/// <summary>
        /// Process recurring payment
        /// </summary>
        /// <param name="paymentInfo">Payment info required for an betting processing</param>
        /// <param name="bettingGuid">Unique order identifier</param>
        /// <param name="processPaymentResult">Process payment result</param>
        public void ProcessRecurringPayment(TransactionPayment transactionPayment, Guid bettingGuid, ref ProcessPaymentResult processPaymentResult)
        {
            InitSettings();
            MerchantAuthenticationType authentication = PopulateMerchantAuthentication();
            if (!transactionPayment.IsRecurringPayment)
            {
                ARBSubscriptionType subscription = new ARBSubscriptionType();
                AuthorizeNet.net.authorize.api.CreditCardType creditCard = new AuthorizeNet.net.authorize.api.CreditCardType();

                subscription.name = bettingGuid.ToString();
                creditCard.cardNumber = transactionPayment.PaymentMenthod.CreditCardNumber;
                creditCard.expirationDate = transactionPayment.PaymentMenthod.CardExpirationYear + "-" + transactionPayment.PaymentMenthod.CardExpirationMonth; // required format for API is YYYY-MM
                creditCard.cardCode = transactionPayment.PaymentMenthod.CardCvv2;

                subscription.payment = new PaymentType();
                subscription.payment.Item = creditCard;
                subscription.billTo = new NameAndAddressType();
                subscription.billTo.firstName = transactionPayment.Customer.FirstName;
                subscription.billTo.lastName = transactionPayment.Customer.LastName;
                subscription.billTo.address = transactionPayment.Customer.Address;
                subscription.billTo.city = transactionPayment.Customer.City;
                subscription.billTo.zip = transactionPayment.Customer.PostalCode;
                subscription.customer = new CustomerType();
                subscription.customer.email = transactionPayment.Customer.Email1;
                subscription.customer.phoneNumber = transactionPayment.Customer.Telephone;
                subscription.order = new OrderType();
                subscription.order.description =Constant.Payment.STORENAME+" "+ "Recurring payment";

                // Create a subscription that is leng of specified occurrences and interval is amount of days ad runs

                subscription.paymentSchedule = new PaymentScheduleType();
                DateTime dtNow = DateTime.UtcNow;
                subscription.paymentSchedule.startDate = new DateTime(dtNow.Year, dtNow.Month, dtNow.Day);
                subscription.paymentSchedule.startDateSpecified = true;

                subscription.paymentSchedule.totalOccurrences = Convert.ToInt16(transactionPayment.RecurringTotalCycles);
                subscription.paymentSchedule.totalOccurrencesSpecified = true;

                subscription.amount = transactionPayment.TransactionPaymentTotal;
                subscription.amountSpecified = true;

                // Interval can't be updated once a subscription is created.
                subscription.paymentSchedule.interval = new PaymentScheduleTypeInterval();
                switch (transactionPayment.RecurringCyclePeriod)
                {
                    case (int)RecurringProductCyclePeriodEnum.Days:
                        subscription.paymentSchedule.interval.length = Convert.ToInt16(transactionPayment.RecurringCycleLength);
                        subscription.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.days;
                        break;
                    case (int)RecurringProductCyclePeriodEnum.Weeks:
                        subscription.paymentSchedule.interval.length = Convert.ToInt16(transactionPayment.RecurringCycleLength * 7);
                        subscription.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.days;
                        break;
                    case (int)RecurringProductCyclePeriodEnum.Months:
                        subscription.paymentSchedule.interval.length = Convert.ToInt16(transactionPayment.RecurringCycleLength);
                        subscription.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.months;
                        break;
                    case (int)RecurringProductCyclePeriodEnum.Years:
                        subscription.paymentSchedule.interval.length = Convert.ToInt16(transactionPayment.RecurringCycleLength * 12);
                        subscription.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.months;
                        break;
                    default:
                        throw new Exception("Not supported cycle period");
                }

                ARBCreateSubscriptionResponseType response = webService.ARBCreateSubscription(authentication, subscription);

                if (response.resultCode == MessageTypeEnum.Ok)
                {
                    processPaymentResult.SubscriptionTransactionId = response.subscriptionId.ToString();
                    processPaymentResult.AuthorizationTransactionCode = response.resultCode.ToString();
                    processPaymentResult.AuthorizationTransactionResult = string.Format("Approved ({0}: {1})", response.resultCode.ToString(), response.subscriptionId.ToString());
                }
                else
                {
                    processPaymentResult.Error = string.Format("Error processing recurring payment. {0}", GetErrors(response));
                    processPaymentResult.FullError = string.Format("Error processing recurring payment. {0}", GetErrors(response));
                }
            }
        }
Example #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);
 }
Example #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]));
 }
Example #4
0
 /// <remarks/>
 public void ARBUpdateSubscriptionAsync(MerchantAuthenticationType merchantAuthentication, long subscriptionId, ARBSubscriptionType subscription) {
     this.ARBUpdateSubscriptionAsync(merchantAuthentication, subscriptionId, subscription, null);
 }
Example #5
0
 /// <remarks/>
 public void ARBCreateSubscriptionAsync(MerchantAuthenticationType merchantAuthentication, ARBSubscriptionType subscription) {
     this.ARBCreateSubscriptionAsync(merchantAuthentication, subscription, null);
 }