/**
   * Creates a Subscription object reading the values from the property.
   *
   * @return Subscription
   */
  private Subscription makeSubscription() {

    Subscription sub = new Subscription();
    sub.setName("SUB-" + System.currentTimeMillis());
    sub.setTermStartDate(ZuoraUtility.getCurrentDate());
    // set ContractEffectiveDate = current date to generate invoice
    // Generates invoice at the time of subscription creation. uncomment for
    // invoice generation
    // sub.setContractEffectiveDate(ZuoraUtility.getCurrentDate());
    sub.setContractAcceptanceDate(ZuoraUtility.getCurrentDate());
    sub.setServiceActivationDate(ZuoraUtility.getCurrentDate());
    // set IsInvoiceSeparate=true //To generate invoice separate for every
    // subscription
    sub.setIsInvoiceSeparate(true);
    sub.setAutoRenew(true);
    sub.setInitialTerm(12); // sets value for next renewal date
    sub.setRenewalTerm(12);
    sub.setNotes("This is a test subscription");
    return sub;
  }
 /**
  * Delete subscribe.
  *
  * @return true, if successful
  * @throws Exception the exception
  */
 public boolean deleteSubscribe() throws Exception {
   ZuoraAPIHelper helper = new ZuoraAPIHelper();
   helper.login();
   stub = helper.getStub();
   header = helper.getHeader();
   boolean isDeleted = false;
   Subscription subscription = querySubscriptionByName("SUB-1336125236281");
   if (subscription != null) {
     isDeleted = helper.delete("Subscription", subscription.getId());
   }
   ZuoraUtility.print("Subscribtion isDeleted :" + isDeleted);
   return isDeleted;
 }
 /**
  * Update subscribe.
  *
  * @return the iD
  * @throws Exception the exception
  */
 public ID updateSubscribe() throws Exception {
   ZuoraAPIHelper helper = new ZuoraAPIHelper();
   helper.login();
   stub = helper.getStub();
   header = helper.getHeader();
   ID id = null;
   Subscription subscription = querySubscriptionByName("SUB-1336383000027");
   if (subscription != null) {
     subscription.setContractEffectiveDate(Calendar.getInstance());
     id = helper.update(subscription);
     ZuoraUtility.print("SubscribeId :" + id);
   }
   return id;
 }
  /**
   * Test subscribe.
   *
   * @return the iD
   * @throws Exception the exception
   */
  public ID createSubscribe() throws Exception {
    ZuoraUtility utility = new ZuoraUtility();
    ZuoraAPIHelper helper = new ZuoraAPIHelper();
    helper.login();
    stub = helper.getStub();
    header = helper.getHeader();

    ProductRatePlanCharge charge =
        getChargeByAccountingCode(utility.getPropertyValue(PROPERTY_ACCOUNTING_CODE));
    AccountSample testData = new AccountSample();
    Account acc = testData.makeAccount();
    Contact con = testData.makeContact();
    PaymentMethod pm = testData.makePaymentMethod();
    Subscription subscription = makeSubscription();

    SubscriptionData sd = new SubscriptionData();
    sd.setSubscription(subscription);

    RatePlanData[] subscriptionRatePlanDataArray = makeRatePlanData(charge);
    sd.setRatePlanData(subscriptionRatePlanDataArray);

    SubscribeRequest subReq = new SubscribeRequest();
    subReq.setAccount(acc);
    subReq.setBillToContact(con);
    subReq.setPaymentMethod(pm);
    subReq.setSubscriptionData(sd);

    SubscribeRequest[] subscribes = new SubscribeRequest[1];
    subscribes[0] = subReq;

    Subscribe subscribe = new Subscribe();
    subscribe.setSubscribes(subscribes);
    SubscribeResponse resp = stub.subscribe(subscribe, this.header);
    SubscribeResult result = resp.getResult()[0];
    if (result.getErrors() == null) {
      ZuoraUtility.print("Subscribe status : Success");

    } else {
      ZuoraUtility.print("Subscribe status: Fail");
      ZuoraUtility.print(ZuoraUtility.createErrorMessage(result));
    }
    return result.getSubscriptionId();
  }
  /**
   * Test subscribe with existing account.
   *
   * @return the iD
   * @throws Exception the exception
   */
  public ID createSubscribeWithExistingAccount() throws Exception {

    ZuoraUtility utility = new ZuoraUtility();
    ZuoraAPIHelper helper = new ZuoraAPIHelper();
    helper.login();
    stub = helper.getStub();
    header = helper.getHeader();

    ProductRatePlanCharge charge =
        getChargeByAccountingCode(utility.getPropertyValue(PROPERTY_ACCOUNTING_CODE));
    Account account = getAccountByName("ACC-1336382492856");
    Subscription subscription = makeSubscription();

    SubscriptionData sd = new SubscriptionData();
    sd.setSubscription(subscription);

    RatePlanData[] subscriptionRatePlanDataArray = makeRatePlanData(charge);
    sd.setRatePlanData(subscriptionRatePlanDataArray);

    SubscribeRequest subRequest = new SubscribeRequest();
    subRequest.setAccount(account);
    subRequest.setSubscriptionData(sd);

    SubscribeRequest[] subscribes = new SubscribeRequest[1];
    subscribes[0] = subRequest;

    Subscribe sr = new Subscribe();
    sr.setSubscribes(subscribes);

    SubscribeResponse resp = stub.subscribe(sr, this.header);
    SubscribeResult result = resp.getResult()[0];
    if (result.getErrors() == null) {
      ZuoraUtility.print("Subscribe status : Success");
    } else {
      ZuoraUtility.print("Subscribe status: Fail");
      ZuoraUtility.print(ZuoraUtility.createErrorMessage(result));
    }
    return result.getSubscriptionId();
  }
Beispiel #6
0
  /**
   * The main method.
   *
   * @param arg the arguments
   */
  public static void main(String[] arg) {

    // Get test operation from command arguments. Default is
    // "account-create"
    // "crud" is used to run the test using ant
    String operation = "account-create";
    if (arg != null && arg.length == 1 && arg[0].equalsIgnoreCase("crud")) {
      operation = "account-create";
    } else if (arg != null && arg.length == 1) {
      operation = arg[0];
    }

    try {
      ZuoraUtility.print("Process start for -: " + operation);

      AccountSample account = new AccountSample();
      SubscribeSample subscribe = new SubscribeSample();
      ProductSample product = new ProductSample();
      AmendmentSample amendment = new AmendmentSample();
      InvoiceSample invoice = new InvoiceSample();

      if (operation.equalsIgnoreCase("account-create")) {
        account.createAccount();
      } else if (operation.equalsIgnoreCase("account-update")) {
        account.updateAccount();
      } else if (operation.equalsIgnoreCase("account-delete")) {
        account.deleteAccount();
      } else if (operation.equalsIgnoreCase("paymentmethod-update")) {
        account.updatePaymentMethod();
      } else if (operation.equalsIgnoreCase("paymentmethod-delete")) {
        account.deletePaymentMethod();
      } else if (operation.equalsIgnoreCase("subscribe-create")) {
        subscribe.createSubscribe();
      } else if (operation.equalsIgnoreCase("subscribe-withaccount")) {
        subscribe.createSubscribeWithExistingAccount();
      } else if (operation.equalsIgnoreCase("subscribe-activate")) {
        subscribe.updateSubscribe(); // Activate subscription
      } else if (operation.equalsIgnoreCase("subscribe-delete")) {
        subscribe.deleteSubscribe();
      } else if (operation.equalsIgnoreCase("product")) {
        product.createProduct();
      } else if (operation.equalsIgnoreCase("product-update")) {
        product.updateProduct();
      } else if (operation.equalsIgnoreCase("product-delete")) {
        product.deleteProduct();
      } else if (operation.equalsIgnoreCase("addRatePlanCharge")) {
        product.addNewRatePlanCharge();
      } else if (operation.equalsIgnoreCase("amendment")) {
        amendment.createAmendment(); // Create Amendment for any type
      } else if (operation.equalsIgnoreCase("amendment-tnc-update")) {
        amendment.updateAmendmentForTnC();
      } else if (operation.equalsIgnoreCase("amendment-newproduct")) {
        amendment.createAmendmentForNewProduct();
      } else if (operation.equalsIgnoreCase("amendment-newproduct-update")) {
        amendment.updateAmendmentForNewProduct();
      } else if (operation.equalsIgnoreCase("amendment-updateproduct")) {
        amendment.createAmendmentForUpdateProduct();
      } else if (operation.equalsIgnoreCase("amendment-updateproduct-update")) {
        amendment.updateAmendmentForUpdateProduct();
      } else if (operation.equalsIgnoreCase("amendment-activate")) {
        amendment.updateAmendment();
      } else if (operation.equalsIgnoreCase("amendment-delete")) {
        amendment.deleteAmendment();
      } else if (operation.equalsIgnoreCase("amend")) {
        amendment.amend();
      } else if (operation.equalsIgnoreCase("amend-updateproduct")) {
        amendment.amendUpdateProduct();
      } else if (operation.equalsIgnoreCase("amend-removeproduct")) {
        amendment.amendRemoveProduct();
      } else if (operation.equalsIgnoreCase("amend-renewproduct")) {
        amendment.amendRenewProduct();
      } else if (operation.equalsIgnoreCase("amend-cancel")) {
        amendment.amendCancel();
      } else if (operation.equalsIgnoreCase("invoice-create")) {
        invoice.createInvoice();
      } else if (operation.equalsIgnoreCase("invoice-update")) {
        invoice.updateInvoice();
      } else if (operation.equalsIgnoreCase("invoice-pdf")) {
        invoice.generateInvoicePDF();
      } else if (operation.equalsIgnoreCase("adjustment-create")) {
        invoice.createAdjustment();
      } else if (operation.equalsIgnoreCase("adjustment-cancel")) {
        invoice.cancelAdjustment();
      } else if (operation.equalsIgnoreCase("adjustment-delete")) {
        invoice.deleteAdjustment();
      } else if (operation.equalsIgnoreCase("itemadjustment-create")) {
        invoice.createItemAdjustment();
      } else if (operation.equalsIgnoreCase("itemadjustment-cancel")) {
        invoice.cancelItemAdjustment();
      } else if (operation.equalsIgnoreCase("itemadjustment-delete")) {
        invoice.deleteItemAdjustment();
      } else if (operation.equalsIgnoreCase("invoicepayment")) {
        invoice.createPayment();
      } else if (operation.equalsIgnoreCase("payment")) {
        invoice.createPayment();
      } else if (operation.equalsIgnoreCase("payment-update")) {
        invoice.updatePayment();
      } else if (operation.equalsIgnoreCase("payment-delete")) {
        invoice.deletePayment();
      } else if (operation.equalsIgnoreCase("refund")) {
        invoice.createRefund();
      } else if (operation.equalsIgnoreCase("refund-update")) {
        invoice.updateRefund();
      } else if (operation.equalsIgnoreCase("usage")) {
        account.createUsage();
      } else if (operation.equalsIgnoreCase("usage-update")) {
        account.updateUsage();
      } else if (operation.equalsIgnoreCase("usage-delete")) {
        account.deleteUsage();
      } else if (operation.equalsIgnoreCase("querymore")) {
        account.queryMore();
      }
    } catch (com.zuora.api.axis2.LoginFault e) {
      ZuoraUtility.print(
          "Login Failure : " + e.getFaultMessage().getLoginFault().getFaultMessage());
    } catch (com.zuora.api.axis2.InvalidTypeFault ie) {
      ZuoraUtility.print(
          "InvalidTypeFault Code : " + ie.getFaultMessage().getInvalidTypeFault().getFaultCode());
      ZuoraUtility.print(
          "Message: " + ie.getFaultMessage().getInvalidTypeFault().getFaultMessage());
    } catch (Exception e) {
      ZuoraUtility.print(e.getMessage());
      e.printStackTrace();
    }
    ZuoraUtility.print("Process Completed.");
  }