/**
  * 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();
  }