Exemple #1
0
 /// <remarks/>
 public void ARBUpdateSubscriptionAsync(MerchantAuthenticationType merchantAuthentication, long subscriptionId, ARBSubscriptionType subscription) {
     this.ARBUpdateSubscriptionAsync(merchantAuthentication, subscriptionId, subscription, null);
 }
Exemple #2
0
 /// <remarks/>
 public void ARBUpdateSubscriptionAsync(MerchantAuthenticationType merchantAuthentication, long subscriptionId, ARBSubscriptionType subscription, object userState) {
     if ((this.ARBUpdateSubscriptionOperationCompleted == null)) {
         this.ARBUpdateSubscriptionOperationCompleted = new System.Threading.SendOrPostCallback(this.OnARBUpdateSubscriptionOperationCompleted);
     }
     this.InvokeAsync("ARBUpdateSubscription", new object[] {
                 merchantAuthentication,
                 subscriptionId,
                 subscription}, this.ARBUpdateSubscriptionOperationCompleted, userState);
 }
Exemple #3
0
 public ARBUpdateSubscriptionResponseType ARBUpdateSubscription(MerchantAuthenticationType merchantAuthentication, long subscriptionId, ARBSubscriptionType subscription) {
     object[] results = this.Invoke("ARBUpdateSubscription", new object[] {
                 merchantAuthentication,
                 subscriptionId,
                 subscription});
     return ((ARBUpdateSubscriptionResponseType)(results[0]));
 }
Exemple #4
0
 /// <remarks/>
 public void ARBCreateSubscriptionAsync(MerchantAuthenticationType merchantAuthentication, ARBSubscriptionType subscription) {
     this.ARBCreateSubscriptionAsync(merchantAuthentication, subscription, null);
 }
        ///<summary>
        ///Create a recurring billing subscription
        ///</summary>
        ///<returns>Returns the generated identification of the subscription</returns>
        public override long CreateSubscription(string subscriptionName, string cardNumber,
                                                string billToFirstName, string billToLastName,
                                                string billToAddress, string billToCity, string billToState,
                                                string billToZip, string billToCountry, 
                                                DateTime? paymentStartDate, string creditCardExpirationDateText,
                                                short? paymentTotalOccurrences, decimal amount,
                                                short? paymentInterval, string paymentPeriodUnit,
                                                short? trialOccurrences, decimal? trialAmount)
        {
            var subscriptionId = 0L;

            var authentication = populateMerchantAuthentication();

            var subscription = new ARBSubscriptionType();
            populateSubscription(subscription, false, subscriptionName, cardNumber, billToFirstName, billToLastName,
                                 billToAddress, billToCity, billToState, billToZip, billToCountry,
                                 paymentStartDate, creditCardExpirationDateText, paymentTotalOccurrences, amount,
                                 paymentInterval, (ARBSubscriptionUnitEnum)Enum.Parse(typeof(ARBSubscriptionUnitEnum), paymentPeriodUnit),
                                 trialOccurrences, trialAmount);

            var response = _webService.ARBCreateSubscription(authentication, subscription);

            if (response.resultCode == MessageTypeEnum.Ok)
                subscriptionId = response.subscriptionId;
            if (subscriptionId <= 0)
            {
                var msg = new StringBuilder();
                foreach (var message in response.messages)
                {
                    msg.AppendLine(string.Format("Error code: '{0}'", message.code));
                    msg.AppendLine(string.Format("Details: '{0}' ", message.text));
                }
                throw new ApplicationException(
                    string.Format("There was a problem with the creation of subscription. Details: {0}", msg));
            }
            Log.Debug(GetType(), string.Format("A subscription with an ID of '{0}' was successfully created.", subscriptionId));
            return subscriptionId;
        }
        private static void populateSubscription(ARBSubscriptionType sub, bool isForUpdate, string accountName,
                                                 string cardNumber, string billToFirstName, string billToLastName,
                                                 string billToAddress, string billToCity, string billToState,
                                                 string billToZip, string billToCountry,
                                                 DateTime? paymentStartDate, string creditCardExpirationDateText,
                                                 short? paymentTotalOcurrences, decimal? amount, short? paymentInterval,
                                                 ARBSubscriptionUnitEnum? paymentPeriodUnit,
                                                 short? trialOccurrences, decimal? trialAmount)
        {
            sub.name = accountName;
            var creditCard = new CreditCardType { cardNumber = cardNumber, expirationDate = creditCardExpirationDateText };
            sub.payment = new PaymentType { Item = creditCard };

            sub.billTo = new NameAndAddressType
                             {
                                 firstName = billToFirstName,
                                 lastName = billToLastName,
                                 address = billToAddress,
                                 city = billToCity,
                                 state = billToState,
                                 zip = billToZip,
                                 country = billToCountry
                             };

            sub.paymentSchedule = new PaymentScheduleType
                                      {
                                          startDateSpecified = paymentStartDate.HasValue,
                                          trialOccurrencesSpecified = trialOccurrences.HasValue
                                      };

            if (paymentStartDate.HasValue)
                sub.paymentSchedule.startDate = paymentStartDate.Value;

            sub.paymentSchedule.totalOccurrencesSpecified = paymentTotalOcurrences.HasValue;
            if (paymentTotalOcurrences.HasValue)
                sub.paymentSchedule.totalOccurrences = paymentTotalOcurrences.Value;

            sub.amountSpecified = amount.HasValue;
            if (amount.HasValue)
                sub.amount = amount.Value;

            if (paymentInterval.HasValue)
            {
                if (isForUpdate)
                    throw new ApplicationException(
                        "Interval of the payment schedule cannot be updated once a subscription is created");
                if (paymentInterval.Value < 1)
                    throw new ApplicationException(
                        "The interval length of the payment schedule must be a positive number greater than zero (0)");
                if (paymentPeriodUnit.Value == ARBSubscriptionUnitEnum.months && paymentInterval.Value > 12)
                    throw new ApplicationException(
                        "If the Interval Unit of the payment schedule is months, it cannot be any number out of the range between one (1) and twelve (12)");
                if (paymentPeriodUnit.Value == ARBSubscriptionUnitEnum.days && paymentInterval.Value > 365)
                    throw new ApplicationException(
                        "If the Interval Unit of the payment schedule is days, it cannot be any number out of the range between one (1) and 365");
                sub.paymentSchedule.interval = new PaymentScheduleTypeInterval
                                                   {
                                                       length = paymentInterval.Value,
                                                       unit = paymentPeriodUnit.Value
                                                   };
            }

            sub.trialAmountSpecified = trialOccurrences.HasValue;
            if (trialOccurrences.HasValue)
            {
                sub.trialAmount = trialAmount.Value;
                sub.paymentSchedule.trialOccurrences = trialOccurrences.Value;
            }
        }
        ///<summary>
        ///Updates the recurring billing subscription
        ///</summary>
        ///<exception cref="ApplicationException">If there was an error on updating, it
        ///throws an exception detailing the problem</exception>
        public override void UpdateSubscription(long subscriptionId, string subscriptionName, string cardNumber,
                                                string billToFirstName, string billToLastName,
                                                string billToAddress, string billToCity, string billToState,
                                                string billToZip, string billToCountry, 
                                                DateTime? paymentStartDate, string expirationDateText,
                                                short? paymentTotalOccurrences, decimal amount,
                                                short? trialOccurrences, decimal? trialAmount)
        {
            var authentication = populateMerchantAuthentication();

            var subscription = new ARBSubscriptionType();
            populateSubscription(subscription, true, subscriptionName, cardNumber, billToFirstName, billToLastName,
                                 billToAddress, billToCity, billToState, billToZip, billToCountry,
                                 paymentStartDate, expirationDateText, paymentTotalOccurrences, amount, null, null,
                                 trialOccurrences, trialAmount);

            var response = _webService.ARBUpdateSubscription(authentication,
                                                             subscriptionId, subscription);

            if (response.resultCode != MessageTypeEnum.Error)
            {
                var msgs = response.messages;
                var messages = new StringBuilder(msgs.Length);
                foreach (var msg in msgs)
                {
                    messages.AppendFormat("Code: {0}", msg.code);
                    messages.AppendLine(msg.text);
                }

                throw new ApplicationException("The subscription throws an error! Error detail:" + messages);
            }
            #if DEBUG
            var responseResult = subscriptionId <= 0
                                     ? response.ToString()
                                     : string.Format("A subscription with an ID of '{0}' was successfully created.",
                                                     subscriptionId);
            Log.Debug(GetType(), responseResult);
            #endif
        }