Example #1
0
        public override string RecurringBillingAddressUpdate(String RecurringSubscriptionID, int OriginalRecurringOrderNumber, Address UseBillingAddress)
        {
            String result = AppLogic.ro_OK;

            String X_Login             = AppLogic.ro_NotApplicable;
            String X_TranKey           = AppLogic.ro_NotApplicable;
            bool   useLiveTransactions = AppLogic.AppConfigBool("UseLiveTransactions");
            String AuthServer          = "manualgatewaysimulation"; // this short circuits the post/response call, and returns a "sample" approved XmlDoc for all requests, properly formatted.

            // This is the API interface object.
            AuthorizeNetRecurringAPI.ARBUpdateSubscriptionRequest request = new AuthorizeNetRecurringAPI.ARBUpdateSubscriptionRequest();

            // Include authentication information
            request.merchantAuthentication                = new AuthorizeNetRecurringAPI.MerchantAuthentication();
            request.merchantAuthentication.name           = X_Login;
            request.merchantAuthentication.transactionKey = X_TranKey;
            request.refId = OriginalRecurringOrderNumber.ToString();

            // Populate the subscription request with test data
            AuthorizeNetRecurringAPI.ARBSubscription sub        = new AuthorizeNetRecurringAPI.ARBSubscription();
            AuthorizeNetRecurringAPI.CreditCard      creditCard = new AuthorizeNetRecurringAPI.CreditCard();
            request.subscriptionId = RecurringSubscriptionID;

            creditCard.cardNumber     = UseBillingAddress.CardNumber;
            creditCard.expirationDate = UseBillingAddress.CardExpirationYear + "-" + UseBillingAddress.CardExpirationMonth.PadLeft(2, '0');  // required format for API is YYYY-MM
            sub.payment      = new AuthorizeNetRecurringAPI.Payment();
            sub.payment.item = creditCard;

            sub.billTo           = new AuthorizeNetRecurringAPI.NameAndAddress();
            sub.billTo.firstName = UseBillingAddress.FirstName;
            sub.billTo.lastName  = UseBillingAddress.LastName;

            request.subscription = sub;

            // The response type will normally be ARBUpdateSubscriptionResponse.
            // However, in the case of an error such as an XML parsing error, the response type will be ErrorResponse.

            object      response = null;
            XmlDocument xmldoc   = null;

            result = AuthorizeNetRecurringAPI.APIHelper.PostRequest(request, AuthServer, out xmldoc);

            if (result.Equals(AppLogic.ro_OK, StringComparison.InvariantCultureIgnoreCase))
            {
                result = AuthorizeNetRecurringAPI.APIHelper.ProcessXmlResponse(xmldoc, out response);
            }

            if (result.Equals(AppLogic.ro_OK, StringComparison.InvariantCultureIgnoreCase))
            {
                String tmpResultCode = String.Empty;              // not used or needed here
                String tmpRecurringSubscriptionID = String.Empty; // not used or needed here
                result = AuthorizeNetRecurringAPI.APIHelper.ProcessResponse(response, out tmpResultCode, out tmpRecurringSubscriptionID);
            }

            return(result);
        }
Example #2
0
        public override string RecurringBillingCancelSubscription(String RecurringSubscriptionID, int OriginalRecurringOrderNumber, IDictionary <string, string> TransactionContext)
        {
            String result = AppLogic.ro_OK;

            String X_Login             = AppLogic.ro_NotApplicable;
            String X_TranKey           = AppLogic.ro_NotApplicable;
            bool   useLiveTransactions = AppLogic.AppConfigBool("UseLiveTransactions");
            String AuthServer          = "manualgatewaysimulation"; // this short circuits the post/response call, and returns a "sample" approved XmlDoc for all requests, properly formatted.

            // This is the API interface object.
            AuthorizeNetRecurringAPI.ARBCancelSubscriptionRequest request = new AuthorizeNetRecurringAPI.ARBCancelSubscriptionRequest();

            // Include authentication information
            request.merchantAuthentication                = new AuthorizeNetRecurringAPI.MerchantAuthentication();
            request.merchantAuthentication.name           = X_Login;
            request.merchantAuthentication.transactionKey = X_TranKey;
            request.refId = OriginalRecurringOrderNumber.ToString();

            // Populate the subscription request with data
            AuthorizeNetRecurringAPI.ARBSubscription sub        = new AuthorizeNetRecurringAPI.ARBSubscription();
            AuthorizeNetRecurringAPI.CreditCard      creditCard = new AuthorizeNetRecurringAPI.CreditCard();
            request.subscriptionId = RecurringSubscriptionID;

            // The response type will normally be ARBCancelSubscriptionResponse.
            // However, in the case of an error such as an XML parsing error, the response type will be ErrorResponse.

            object      response = null;
            XmlDocument xmldoc   = null;

            result = AuthorizeNetRecurringAPI.APIHelper.PostRequest(request, AuthServer, out xmldoc);

            if (result.Equals(AppLogic.ro_OK, StringComparison.InvariantCultureIgnoreCase))
            {
                result = AuthorizeNetRecurringAPI.APIHelper.ProcessXmlResponse(xmldoc, out response);
            }

            if (result.Equals(AppLogic.ro_OK, StringComparison.InvariantCultureIgnoreCase))
            {
                String tmpResultCode = String.Empty;              // not used or needed here
                String tmpRecurringSubscriptionID = String.Empty; // not used or needed here
                result = AuthorizeNetRecurringAPI.APIHelper.ProcessResponse(response, out tmpResultCode, out tmpRecurringSubscriptionID);
            }

            return(result);
        }
Example #3
0
        // ----------------------------------------------------------------------------------
        // RECURRING BILLING ROUTINES
        // MANUAL GATEWAY ALWAYS APPROVES EVERY CALL!! THESE ARE JUST FOR EMULATION TESTING
        // THEY SIMULATE HOW AUTHORIZE.NET DOES IT'S RECURRING BILLING API
        // ----------------------------------------------------------------------------------

        // returns AppLogic.ro_OK if successful, along with the out RecurringSubscriptionID
        // returns error message if not successful
        // SubscriptionDescription may usually best be passed in as the product description of the first cart item
        public override string RecurringBillingCreateSubscription(String SubscriptionDescription, Customer ThisCustomer, Address UseBillingAddress, Address UseShippingAddress, Decimal RecurringAmount, DateTime StartDate, int RecurringInterval, DateIntervalTypeEnum RecurringIntervalType, int OriginalRecurringOrderNumber, string XID, IDictionary <string, string> TransactionContext, out String RecurringSubscriptionID, out String RecurringSubscriptionCommand, out String RecurringSubscriptionResult)
        {
            String result = AppLogic.ro_OK;

            RecurringSubscriptionID      = String.Empty;
            RecurringSubscriptionCommand = String.Empty;
            RecurringSubscriptionResult  = String.Empty;
            String ResultCode = String.Empty;

            String X_Login             = AppLogic.ro_NotApplicable;
            String X_TranKey           = AppLogic.ro_NotApplicable;
            bool   useLiveTransactions = AppLogic.AppConfigBool("UseLiveTransactions");
            String AuthServer          = "manualgatewaysimulation"; // this short circuits the post/response call, and returns a "sample" approved XmlDoc for all requests, properly formatted.

            // This is the API interface object.
            AuthorizeNetRecurringAPI.ARBCreateSubscriptionRequest request = new AuthorizeNetRecurringAPI.ARBCreateSubscriptionRequest();

            // Include authentication information
            request.merchantAuthentication                = new AuthorizeNetRecurringAPI.MerchantAuthentication();
            request.merchantAuthentication.name           = X_Login;
            request.merchantAuthentication.transactionKey = X_TranKey;
            request.refId = OriginalRecurringOrderNumber.ToString();

            // Populate the subscription request with data
            AuthorizeNetRecurringAPI.ARBSubscription sub        = new AuthorizeNetRecurringAPI.ARBSubscription();
            AuthorizeNetRecurringAPI.CreditCard      creditCard = new AuthorizeNetRecurringAPI.CreditCard();

            sub.name = AppLogic.AppConfig("StoreName") + " - Order " + OriginalRecurringOrderNumber.ToString();

            creditCard.cardNumber     = UseBillingAddress.CardNumber;
            creditCard.expirationDate = UseBillingAddress.CardExpirationYear + "-" + UseBillingAddress.CardExpirationMonth.PadLeft(2, '0');  // required format for API is YYYY-MM

            sub.payment      = new AuthorizeNetRecurringAPI.Payment();
            sub.payment.item = creditCard;

            sub.billTo           = new AuthorizeNetRecurringAPI.NameAndAddress();
            sub.billTo.firstName = UseBillingAddress.FirstName;
            sub.billTo.lastName  = UseBillingAddress.LastName;
            sub.billTo.company   = UseBillingAddress.Company;
            sub.billTo.address   = UseBillingAddress.Address1;
            sub.billTo.city      = UseBillingAddress.City;
            sub.billTo.state     = UseBillingAddress.State;
            sub.billTo.zip       = UseBillingAddress.Zip;
            sub.billTo.country   = UseBillingAddress.Country;

            sub.shipTo           = new AuthorizeNetRecurringAPI.NameAndAddress();
            sub.shipTo.firstName = UseShippingAddress.FirstName;
            sub.shipTo.lastName  = UseShippingAddress.LastName;
            sub.shipTo.company   = UseShippingAddress.Company;
            sub.shipTo.address   = UseShippingAddress.Address1;
            sub.shipTo.city      = UseShippingAddress.City;
            sub.shipTo.state     = UseShippingAddress.State;
            sub.shipTo.zip       = UseShippingAddress.Zip;
            sub.shipTo.country   = UseShippingAddress.Country;

            sub.order = new AuthorizeNetRecurringAPI.Order();
            sub.order.invoiceNumber = OriginalRecurringOrderNumber.ToString();
            sub.order.description   = SubscriptionDescription;
            sub.orderSpecified      = true;

            sub.customer             = new AuthorizeNetRecurringAPI.Customer();
            sub.customer.email       = CommonLogic.IIF(ThisCustomer.EMail.Length != 0, ThisCustomer.EMail, UseBillingAddress.EMail);
            sub.customer.id          = ThisCustomer.CustomerID.ToString();
            sub.customer.phoneNumber = UseBillingAddress.Phone;
            sub.customer.type        = CommonLogic.IIF(UseBillingAddress.ResidenceType == ResidenceTypes.Residential, "individual", "business");
            sub.customerSpecified    = true;

            sub.paymentSchedule           = new AuthorizeNetRecurringAPI.PaymentSchedule();
            sub.paymentSchedule.startDate = StartDate.Year.ToString() + "-" + StartDate.ToString().PadLeft(2, '0') + "-" + StartDate.Day.ToString().PadLeft(2, '0');   // Required format is YYYY-MM-DD

            sub.amount          = RecurringAmount;
            sub.amountSpecified = true;

            // NOTE: since our recurring products have no sunset, set max gateway allowed total occurrences to provide maxmimum
            // length of subscription time
            // MAX interval supported by the gateway is 3 years
            switch (RecurringIntervalType)
            {
            case DateIntervalTypeEnum.Day:
                if (RecurringInterval < 7)
                {
                    result = "The minimum interval for Authorize.Net Recurring Billing is 7 days";
                    return(result);
                }
                sub.paymentSchedule.PaymentScheduleInterval.length = RecurringInterval;
                sub.paymentSchedule.PaymentScheduleInterval.unit   = AuthorizeNetRecurringAPI.SubscriptionUnitType.days;
                sub.paymentSchedule.totalOccurrences          = (int)((365 * 3) / RecurringInterval);
                sub.paymentSchedule.totalOccurrencesSpecified = true;
                break;

            case DateIntervalTypeEnum.Week:
                sub.paymentSchedule.PaymentScheduleInterval.length = RecurringInterval * 7;
                sub.paymentSchedule.PaymentScheduleInterval.unit   = AuthorizeNetRecurringAPI.SubscriptionUnitType.days;
                sub.paymentSchedule.totalOccurrences          = (int)((365 * 3) / (RecurringInterval * 7));
                sub.paymentSchedule.totalOccurrencesSpecified = true;
                break;

            case DateIntervalTypeEnum.Month:
                sub.paymentSchedule.PaymentScheduleInterval.length = RecurringInterval;
                sub.paymentSchedule.PaymentScheduleInterval.unit   = AuthorizeNetRecurringAPI.SubscriptionUnitType.months;
                sub.paymentSchedule.totalOccurrences          = (int)((12 * 3) / RecurringInterval);
                sub.paymentSchedule.totalOccurrencesSpecified = true;
                break;

            case DateIntervalTypeEnum.Year:
                sub.paymentSchedule.PaymentScheduleInterval.length = RecurringInterval * 12;
                sub.paymentSchedule.PaymentScheduleInterval.unit   = AuthorizeNetRecurringAPI.SubscriptionUnitType.months;
                sub.paymentSchedule.totalOccurrences          = (int)((12 * 3) / (RecurringInterval * 12));
                sub.paymentSchedule.totalOccurrencesSpecified = true;
                break;

            case DateIntervalTypeEnum.Weekly:
                RecurringInterval = 1;
                sub.paymentSchedule.PaymentScheduleInterval.length = RecurringInterval * 7;
                sub.paymentSchedule.PaymentScheduleInterval.unit   = AuthorizeNetRecurringAPI.SubscriptionUnitType.days;
                sub.paymentSchedule.totalOccurrences          = (int)((365 * 3) / (RecurringInterval * 7));
                sub.paymentSchedule.totalOccurrencesSpecified = true;
                break;

            case DateIntervalTypeEnum.BiWeekly:
                RecurringInterval = 2;
                sub.paymentSchedule.PaymentScheduleInterval.length = RecurringInterval * 7;
                sub.paymentSchedule.PaymentScheduleInterval.unit   = AuthorizeNetRecurringAPI.SubscriptionUnitType.days;
                sub.paymentSchedule.totalOccurrences          = (int)((365 * 3) / (RecurringInterval * 7));
                sub.paymentSchedule.totalOccurrencesSpecified = true;
                break;

            //case DateIntervalTypeEnum.SemiMonthly:
            //    RecurringInterval = 2;
            //    sub.paymentSchedule.PaymentScheduleInterval.length = RecurringInterval * 7;
            //    sub.paymentSchedule.PaymentScheduleInterval.unit = AuthorizeNetRecurringAPI.SubscriptionUnitType.days;
            //    sub.paymentSchedule.totalOccurrences = (int)((365 * 3) / (RecurringInterval * 7));
            //    sub.paymentSchedule.totalOccurrencesSpecified = true;
            //    break;
            case DateIntervalTypeEnum.EveryFourWeeks:
                RecurringInterval = 4;
                sub.paymentSchedule.PaymentScheduleInterval.length = RecurringInterval * 7;
                sub.paymentSchedule.PaymentScheduleInterval.unit   = AuthorizeNetRecurringAPI.SubscriptionUnitType.days;
                sub.paymentSchedule.totalOccurrences          = (int)((365 * 3) / (RecurringInterval * 7));
                sub.paymentSchedule.totalOccurrencesSpecified = true;
                break;

            case DateIntervalTypeEnum.Monthly:
                RecurringInterval = 1;
                sub.paymentSchedule.PaymentScheduleInterval.length = RecurringInterval;
                sub.paymentSchedule.PaymentScheduleInterval.unit   = AuthorizeNetRecurringAPI.SubscriptionUnitType.months;
                sub.paymentSchedule.totalOccurrences          = (int)((12 * 3) / RecurringInterval);
                sub.paymentSchedule.totalOccurrencesSpecified = true;
                break;

            case DateIntervalTypeEnum.Quarterly:
                RecurringInterval = 3;
                sub.paymentSchedule.PaymentScheduleInterval.length = RecurringInterval;
                sub.paymentSchedule.PaymentScheduleInterval.unit   = AuthorizeNetRecurringAPI.SubscriptionUnitType.months;
                sub.paymentSchedule.totalOccurrences          = (int)((12 * 3) / RecurringInterval);
                sub.paymentSchedule.totalOccurrencesSpecified = true;
                break;

            case DateIntervalTypeEnum.SemiYearly:
                RecurringInterval = 6;
                sub.paymentSchedule.PaymentScheduleInterval.length = RecurringInterval;
                sub.paymentSchedule.PaymentScheduleInterval.unit   = AuthorizeNetRecurringAPI.SubscriptionUnitType.months;
                sub.paymentSchedule.totalOccurrences          = (int)((12 * 3) / RecurringInterval);
                sub.paymentSchedule.totalOccurrencesSpecified = true;
                break;

            case DateIntervalTypeEnum.Yearly:
                RecurringInterval = 12;
                sub.paymentSchedule.PaymentScheduleInterval.length = RecurringInterval;
                sub.paymentSchedule.PaymentScheduleInterval.unit   = AuthorizeNetRecurringAPI.SubscriptionUnitType.months;
                sub.paymentSchedule.totalOccurrences          = (int)((12 * 3) / RecurringInterval);
                sub.paymentSchedule.totalOccurrencesSpecified = true;
                break;

            default:
                RecurringInterval = 1;
                sub.paymentSchedule.PaymentScheduleInterval.length = RecurringInterval;
                sub.paymentSchedule.PaymentScheduleInterval.unit   = AuthorizeNetRecurringAPI.SubscriptionUnitType.months;
                sub.paymentSchedule.totalOccurrences          = (int)((12 * 3) / RecurringInterval);
                sub.paymentSchedule.totalOccurrencesSpecified = true;
                break;
            }
            sub.paymentSchedule.intervalSpecified = true;

            // Any free trial?
            sub.paymentSchedule.trialOccurrences          = 0;
            sub.paymentSchedule.trialOccurrencesSpecified = true;
            sub.trialAmount          = System.Decimal.Zero;
            sub.trialAmountSpecified = false; // we don't support free trials at this time

            request.subscription = sub;

            RecurringSubscriptionCommand = XmlCommon.SerializeObject(request, request.GetType());
            // wipe sensitive data:
            if (RecurringSubscriptionCommand.Length != 0)
            {
                RecurringSubscriptionCommand = RecurringSubscriptionCommand.Replace(UseBillingAddress.CardNumber, AppLogic.SafeDisplayCardNumber(UseBillingAddress.CardNumber, "Orders", 0));
                RecurringSubscriptionCommand = RecurringSubscriptionCommand.Replace(X_TranKey, "*".PadLeft(X_TranKey.Length, '*'));
            }

            // The response type will normally be ARBCreateSubscriptionResponse.
            // However, in the case of an error such as an XML parsing error, the response type will be ErrorResponse.

            object      response = null;
            XmlDocument xmldoc   = null;

            result = AuthorizeNetRecurringAPI.APIHelper.PostRequest(request, AuthServer, out xmldoc);

            if (xmldoc != null)
            {
                RecurringSubscriptionResult = xmldoc.InnerXml;
                // wipe sensitive data:
                if (RecurringSubscriptionResult.Length != 0)
                {
                    RecurringSubscriptionResult = RecurringSubscriptionResult.Replace(UseBillingAddress.CardNumber, AppLogic.SafeDisplayCardNumber(UseBillingAddress.CardNumber, "Orders", 0));
                    RecurringSubscriptionResult = RecurringSubscriptionResult.Replace(X_TranKey, "*".PadLeft(X_TranKey.Length, '*'));
                }
            }

            if (result.Equals(AppLogic.ro_OK, StringComparison.InvariantCultureIgnoreCase))
            {
                result = AuthorizeNetRecurringAPI.APIHelper.ProcessXmlResponse(xmldoc, out response);
            }

            if (result.Equals(AppLogic.ro_OK, StringComparison.InvariantCultureIgnoreCase))
            {
                result = AuthorizeNetRecurringAPI.APIHelper.ProcessResponse(response, out ResultCode, out RecurringSubscriptionID);
            }

            return(result);
        }