예제 #1
0
파일: USAePay.cs 프로젝트: giagiigi/WE
        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 = String.Empty;             //explicitly set this to AppLogic.ro_OK when things are ok

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

            if (String.IsNullOrEmpty(GetUSAePaySchedule(RecurringIntervalType)))
            {
                //order has product with invalid recurring interval - bail
                return(result = string.Format(CultureInfo.CurrentCulture, "USAePay - Not supported: Product set to invalid Recurring interval type: {0} or Recurring interval: {1}", RecurringIntervalType, RecurringInterval.ToString(CultureInfo.InvariantCulture)));
            }

            //set service configuration
            GatewayUSAePay.USAePaySOAP.ueSoapServerPortType client = GetServiceClient(UseSandBox);
            var    token    = GetSecurityToken();
            var    customer = MakeRecurringUSAePayCustomer(UseBillingAddress, ThisCustomer, RecurringIntervalType, StartDate, RecurringAmount, OriginalRecurringOrderNumber);
            String response = String.Empty;

            try
            {
                response = client.addCustomer(token, customer);
                RecurringSubscriptionID     = response;
                RecurringSubscriptionResult = "USAePay Customer Subscription added. USAePay CustNum = " + response;
                result = AppLogic.ro_OK;
                return(result);
            }

            catch (Exception err)
            {
                //TODO Card can process ok but if usaepay doesn't like the customer info,
                //order still goes through but does not create subscription.
                //This is a known issue with recurring - (Gateway.cs::1722 ::1760 and ::1793.)
                result = err.Message;
                RecurringSubscriptionResult = "USAePay Subscription FAILED - " + err.Message;
                return(result);
            }
        }
예제 #2
0
        public virtual 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)
        {
            RecurringSubscriptionID      = string.Empty;
            RecurringSubscriptionCommand = string.Empty;
            RecurringSubscriptionResult  = string.Empty;

            return(string.Empty);
        }
예제 #3
0
파일: USAePay.cs 프로젝트: giagiigi/WE
        private string GetUSAePaySchedule(DateIntervalTypeEnum RecurringIntervalType)
        {
            String schedule = String.Empty;

            switch (RecurringIntervalType)
            {
            case DateIntervalTypeEnum.Weekly:
                schedule = "weekly";
                break;

            case DateIntervalTypeEnum.BiWeekly:
                schedule = "biweekly";
                break;

            case DateIntervalTypeEnum.Monthly:
                schedule = "monthly";
                break;

            case DateIntervalTypeEnum.Quarterly:
                schedule = "quarterly";
                break;

            case DateIntervalTypeEnum.SemiYearly:
                schedule = "biannually";
                break;

            case DateIntervalTypeEnum.Yearly:
                schedule = "annually";
                break;

            default:
                //something is wrong, if intervaltype is incorrect it shouldn't run through recurring charge
                schedule = String.Empty;
                break;
            }
            return(schedule);
        }
예제 #4
0
        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 = string.Empty;

            try
            {
                //Re-Use the Internal Gateway Recurring Billing logic for calculating how much of the order is recurring
                ShoppingCart recurringCart = new ShoppingCart(ThisCustomer.SkinID, ThisCustomer, CartTypeEnum.RecurringCart, OriginalRecurringOrderNumber, false);

                CreditCardDetailsType creditCard = new CreditCardDetailsType();

                if (UseBillingAddress.CardNumber != null && UseBillingAddress.CardNumber.Length > 0)
                {
                    creditCard.CreditCardNumber  = UseBillingAddress.CardNumber;
                    creditCard.ExpMonth          = Localization.ParseUSInt(UseBillingAddress.CardExpirationMonth);
                    creditCard.ExpYear           = Localization.ParseUSInt(UseBillingAddress.CardExpirationYear);
                    creditCard.ExpMonthSpecified = true;
                    creditCard.ExpYearSpecified  = true;
                    creditCard.CVV2 = XID;

                    if (UseBillingAddress.CardType == "AmericanExpress")
                    {
                        creditCard.CreditCardType = (CreditCardTypeType)Enum.Parse(typeof(CreditCardTypeType), "Amex", true);
                    }
                    else
                    {
                        creditCard.CreditCardType = (CreditCardTypeType)Enum.Parse(typeof(CreditCardTypeType), UseBillingAddress.CardType, true);
                    }
                    creditCard.CreditCardTypeSpecified = true;
                }
                else
                {
                    creditCard.CreditCardTypeSpecified = false;
                }

                BasicAmountType recurringAmount = new BasicAmountType();
                recurringAmount.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), AppLogic.AppConfig("Localization.StoreCurrency"), true);
                recurringAmount.Value      = RecurringAmount.ToString();

                DateIntervalTypeEnum recurringIntervalType = recurringCart.CartItems[0].RecurringIntervalType;                 //We currently only support 1 interval per recurring order, so grabbing the first as a default should be safe
                int recurringInterval = recurringCart.CartItems[0].RecurringInterval;

                BillingPeriodDetailsType billingPeriodDetails = PayPalController.GetECRecurringPeriodDetails(recurringIntervalType, recurringInterval);
                billingPeriodDetails.Amount = recurringAmount;
                billingPeriodDetails.TotalBillingCyclesSpecified = false;

                ScheduleDetailsType scheduleDetails = new ScheduleDetailsType();
                scheduleDetails.Description                        = string.Format("Recurring order created on {0} from {1}", System.DateTime.Now.ToShortDateString(), AppLogic.AppConfig("StoreName"));
                scheduleDetails.MaxFailedPayments                  = 0;
                scheduleDetails.MaxFailedPaymentsSpecified         = true;
                scheduleDetails.AutoBillOutstandingAmount          = AutoBillType.NoAutoBill;
                scheduleDetails.AutoBillOutstandingAmountSpecified = true;
                scheduleDetails.PaymentPeriod                      = billingPeriodDetails;

                RecurringPaymentsProfileDetailsType profileDetails = new RecurringPaymentsProfileDetailsType();
                profileDetails.SubscriberName   = ThisCustomer.FirstName + " " + ThisCustomer.LastName;
                profileDetails.BillingStartDate = StartDate;

                CreateRecurringPaymentsProfileRequestDetailsType profileRequestDetails = new CreateRecurringPaymentsProfileRequestDetailsType();
                profileRequestDetails.ScheduleDetails = scheduleDetails;
                profileRequestDetails.RecurringPaymentsProfileDetails = profileDetails;
                profileRequestDetails.CreditCard = creditCard;

                if (!(UseBillingAddress.CardNumber != null && UseBillingAddress.CardNumber.Length > 0))
                {
                    profileRequestDetails.Token = XID;
                }

                if (recurringCart.IsAllDownloadComponents())
                {
                    PaymentDetailsItemType paymentDetailsItem = new PaymentDetailsItemType();
                    paymentDetailsItem.ItemCategory          = ItemCategoryType.Digital;
                    paymentDetailsItem.ItemCategorySpecified = true;

                    List <PaymentDetailsItemType> paymentDetailsList = new List <PaymentDetailsItemType>();
                    paymentDetailsList.Add(paymentDetailsItem);

                    profileRequestDetails.PaymentDetailsItem = paymentDetailsList.ToArray();
                }

                CreateRecurringPaymentsProfileRequestType profileRequest = new CreateRecurringPaymentsProfileRequestType();
                profileRequest.Version = API_VER;
                profileRequest.CreateRecurringPaymentsProfileRequestDetails = profileRequestDetails;

                CreateRecurringPaymentsProfileReq request = new CreateRecurringPaymentsProfileReq();
                request.CreateRecurringPaymentsProfileRequest = profileRequest;

                CreateRecurringPaymentsProfileResponseType profileResponse = new CreateRecurringPaymentsProfileResponseType();
                profileResponse = IPayPal.CreateRecurringPaymentsProfile(request);

                if (profileResponse != null && profileResponse.Ack.ToString().StartsWith("success", StringComparison.InvariantCultureIgnoreCase))
                {
                    result = AppLogic.ro_OK;
                }
                else
                {
                    if (profileResponse.Errors != null)
                    {
                        bool first = true;
                        for (int ix = 0; ix < profileResponse.Errors.Length; ix++)
                        {
                            if (!first)
                            {
                                result += ", ";
                            }
                            result += profileResponse.Errors[ix].LongMessage;
                            first   = false;
                        }
                    }
                }

                RecurringSubscriptionID      = (profileResponse.CreateRecurringPaymentsProfileResponseDetails.ProfileID == null ? "No ProfileID provided" : profileResponse.CreateRecurringPaymentsProfileResponseDetails.ProfileID);
                RecurringSubscriptionCommand = string.Empty;
                RecurringSubscriptionResult  = (profileResponse.CreateRecurringPaymentsProfileResponseDetails.DCCProcessorResponse == null ? "No response provided" : profileResponse.CreateRecurringPaymentsProfileResponseDetails.DCCProcessorResponse);

                //Log the transaction
                OrderTransactionCollection ecRecurringOrderTransaction = new OrderTransactionCollection(OriginalRecurringOrderNumber);
                ecRecurringOrderTransaction.AddTransaction("PayPal Express Checkout Recurring Profile Creation",
                                                           request.ToString(),
                                                           result,
                                                           string.Empty,
                                                           (profileResponse.CreateRecurringPaymentsProfileResponseDetails.ProfileID == null ? "No ProfileID provided" : profileResponse.CreateRecurringPaymentsProfileResponseDetails.ProfileID),
                                                           AppLogic.ro_PMPayPalExpress,
                                                           null,
                                                           RecurringAmount);
            }
            catch
            {
                result = "Recurring Profile Creation Failed.";
                RecurringSubscriptionID      = string.Empty;
                RecurringSubscriptionCommand = string.Empty;
                RecurringSubscriptionResult  = result;
            }
            return(result);
        }
예제 #5
0
파일: USAePay.cs 프로젝트: giagiigi/WE
        private GatewayUSAePay.USAePaySOAP.CustomerObject MakeRecurringUSAePayCustomer(Address UseBillingAddress, Customer ThisCustomer, DateIntervalTypeEnum RecurringIntervalType, DateTime StartDate, decimal RecurringAmount, int OriginalRecurringOrderNumber)
        {
            var addressBilling = GetUSAePayBillingAddress(UseBillingAddress);
            var customer       = new GatewayUSAePay.USAePaySOAP.CustomerObject();

            customer.BillingAddress = addressBilling;
            customer.CustomerID     = ThisCustomer.CustomerID.ToString(CultureInfo.InvariantCulture);//ADNSF CustomerId, not USAePay CustNum (SubscriptionId)
            //customer recurring setup http://wiki.usaepay.com/developer/soap-1.6/objects/customerobject
            customer.Schedule = GetUSAePaySchedule(RecurringIntervalType);

            customer.Enabled     = true; //enable recurring
            customer.NumLeft     = "-1"; //unlimited transactions
            customer.Next        = StartDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) ?? String.Empty;
            customer.Amount      = Convert.ToDouble(RecurringAmount);
            customer.OrderID     = OriginalRecurringOrderNumber.ToString(CultureInfo.InvariantCulture) ?? String.Empty;
            customer.SendReceipt = false; //USAePay gateway sending email receipts

            var payMethod = GetUSAePayCCPaymentMethod(UseBillingAddress);

            customer.PaymentMethods = payMethod;
            return(customer);
        }
예제 #6
0
 public IntervalRegExValidator(string regEx, string regExErrorMessage, DateIntervalTypeEnum intervalType)
     : base(intervalType)
 {
     RegEx             = new Regex(regEx);
     RegExErrorMessage = regExErrorMessage;
 }
예제 #7
0
 public IntervalValidator(DateIntervalTypeEnum intervalType)
 {
     IntervalType = intervalType;
 }
예제 #8
0
 public virtual IntervalValidator GetIntervalValidator(DateIntervalTypeEnum intervalType)
 {
     return(new IntervalRegExValidator(@"^(\d+)$", "Please enter an integer.", intervalType));
 }
예제 #9
0
파일: Manual.cs 프로젝트: lulzzz/BrandStore
        // ----------------------------------------------------------------------------------
        // 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);
        }
예제 #10
0
        public static BillingPeriodDetailsType GetECRecurringPeriodDetails(DateIntervalTypeEnum ecRecurringIntervalType, int ecRecurringInterval)
        {
            BillingPeriodDetailsType ecBillingPeriod = new BillingPeriodDetailsType();

            switch (ecRecurringIntervalType)
            {
            case DateIntervalTypeEnum.Day:
                ecBillingPeriod.BillingFrequency = ecRecurringInterval;
                ecBillingPeriod.BillingPeriod    = BillingPeriodType.Day;
                break;

            case DateIntervalTypeEnum.Week:
                ecBillingPeriod.BillingFrequency = ecRecurringInterval;
                ecBillingPeriod.BillingPeriod    = BillingPeriodType.Week;
                break;

            case DateIntervalTypeEnum.Month:
                ecBillingPeriod.BillingFrequency = ecRecurringInterval;
                ecBillingPeriod.BillingPeriod    = BillingPeriodType.Month;
                break;

            case DateIntervalTypeEnum.Year:
                ecBillingPeriod.BillingFrequency = ecRecurringInterval;
                ecBillingPeriod.BillingPeriod    = BillingPeriodType.Year;
                break;

            case DateIntervalTypeEnum.Weekly:
                ecBillingPeriod.BillingFrequency = 1;
                ecBillingPeriod.BillingPeriod    = BillingPeriodType.Week;
                break;

            case DateIntervalTypeEnum.BiWeekly:
                ecBillingPeriod.BillingFrequency = 1;
                ecBillingPeriod.BillingPeriod    = BillingPeriodType.SemiMonth;
                break;

            case DateIntervalTypeEnum.EveryFourWeeks:
                ecBillingPeriod.BillingFrequency = 4;
                ecBillingPeriod.BillingPeriod    = BillingPeriodType.Week;
                break;

            case DateIntervalTypeEnum.Monthly:
                ecBillingPeriod.BillingFrequency = 1;
                ecBillingPeriod.BillingPeriod    = BillingPeriodType.Month;
                break;

            case DateIntervalTypeEnum.Quarterly:
                ecBillingPeriod.BillingFrequency = 3;
                ecBillingPeriod.BillingPeriod    = BillingPeriodType.Month;
                break;

            case DateIntervalTypeEnum.SemiYearly:
                ecBillingPeriod.BillingFrequency = 6;
                ecBillingPeriod.BillingPeriod    = BillingPeriodType.Month;
                break;

            case DateIntervalTypeEnum.Yearly:
                ecBillingPeriod.BillingFrequency = 1;
                ecBillingPeriod.BillingPeriod    = BillingPeriodType.Year;
                break;

            default:                        //Default to monthly like we do elsewhere
                ecBillingPeriod.BillingFrequency = ecRecurringInterval;
                ecBillingPeriod.BillingPeriod    = BillingPeriodType.Month;
                break;
            }

            return(ecBillingPeriod);
        }
예제 #11
0
        public static String MakeECRecurringProfile(ShoppingCart cart, int orderNumber, String payPalToken, String payerID, DateTime nextRecurringShipDate)
        {
            PayPalAPISoapBinding   IPayPalRefund;
            PayPalAPIAASoapBinding IPayPal;

            PayPalController.GetPaypalRequirements(out IPayPalRefund, out IPayPal);
            String result = String.Empty;

            CreateRecurringPaymentsProfileReq                ECRecurringRequest  = new CreateRecurringPaymentsProfileReq();
            CreateRecurringPaymentsProfileRequestType        varECRequest        = new CreateRecurringPaymentsProfileRequestType();
            CreateRecurringPaymentsProfileRequestDetailsType varECRequestDetails = new CreateRecurringPaymentsProfileRequestDetailsType();
            CreateRecurringPaymentsProfileResponseType       ECRecurringResponse = new CreateRecurringPaymentsProfileResponseType();

            //Re-Use the Internal Gateway Recurring Billing logic for calculating how much of the order is recurring
            ShoppingCart cartRecur       = new ShoppingCart(cart.ThisCustomer.SkinID, cart.ThisCustomer, CartTypeEnum.RecurringCart, orderNumber, false);
            Decimal      CartTotalRecur  = Decimal.Round(cartRecur.Total(true), 2, MidpointRounding.AwayFromZero);
            Decimal      RecurringAmount = CartTotalRecur - CommonLogic.IIF(cartRecur.Coupon.CouponType == CouponTypeEnum.GiftCard, CommonLogic.IIF(CartTotalRecur < cartRecur.Coupon.DiscountAmount, CartTotalRecur, cartRecur.Coupon.DiscountAmount), 0);

            DateIntervalTypeEnum ecRecurringIntervalType = cartRecur.CartItems[0].RecurringIntervalType;                //We currently only support 1 interval per recurring order, so grabbing the first as a default should be safe
            int ecRecurringInterval = cartRecur.CartItems[0].RecurringInterval;

            BasicAmountType ecRecurringAmount = new BasicAmountType();

            ecRecurringAmount.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), AppLogic.AppConfig("Localization.StoreCurrency"), true);
            ecRecurringAmount.Value      = RecurringAmount.ToString();

            BillingPeriodDetailsType varECSchedulePaymentDetails = GetECRecurringPeriodDetails(ecRecurringIntervalType, ecRecurringInterval);

            varECSchedulePaymentDetails.Amount = ecRecurringAmount;
            varECSchedulePaymentDetails.TotalBillingCyclesSpecified = false;

            ScheduleDetailsType varECSchedule = new ScheduleDetailsType();

            //Need a better description, but it must match the one sent in StartEC
            varECSchedule.Description                        = "Recurring order created on " + System.DateTime.Now.ToShortDateString() + " from " + AppLogic.AppConfig("StoreName");
            varECSchedule.MaxFailedPayments                  = 0; //Cancel the order if a recurrence fails
            varECSchedule.MaxFailedPaymentsSpecified         = true;
            varECSchedule.AutoBillOutstandingAmount          = AutoBillType.NoAutoBill;
            varECSchedule.AutoBillOutstandingAmountSpecified = true;
            varECSchedule.PaymentPeriod                      = varECSchedulePaymentDetails;

            RecurringPaymentsProfileDetailsType varECProfileDetails = new RecurringPaymentsProfileDetailsType();

            varECProfileDetails.SubscriberName   = cart.ThisCustomer.FirstName + " " + cart.ThisCustomer.LastName;
            varECProfileDetails.BillingStartDate = nextRecurringShipDate;

            varECRequestDetails.ScheduleDetails = varECSchedule;
            varECRequestDetails.Token           = payPalToken;
            varECRequestDetails.RecurringPaymentsProfileDetails = varECProfileDetails;

            if (cart.IsAllDownloadComponents())
            {
                PaymentDetailsItemType varECPaymentDetails = new PaymentDetailsItemType();
                varECPaymentDetails.ItemCategory          = ItemCategoryType.Digital;
                varECPaymentDetails.ItemCategorySpecified = true;

                List <PaymentDetailsItemType> ECPaymentDetailsList = new List <PaymentDetailsItemType>();

                ECPaymentDetailsList.Add(varECPaymentDetails);

                varECRequestDetails.PaymentDetailsItem = ECPaymentDetailsList.ToArray();
            }

            varECRequest.Version = API_VER;
            varECRequest.CreateRecurringPaymentsProfileRequestDetails = varECRequestDetails;

            ECRecurringRequest.CreateRecurringPaymentsProfileRequest = varECRequest;

            ECRecurringResponse = IPayPal.CreateRecurringPaymentsProfile(ECRecurringRequest);

            if (ECRecurringResponse.Ack.ToString().StartsWith("success", StringComparison.InvariantCultureIgnoreCase))
            {
                result = AppLogic.ro_OK;
            }
            else
            {
                if (ECRecurringResponse.Errors != null)
                {
                    bool first = true;
                    for (int ix = 0; ix < ECRecurringResponse.Errors.Length; ix++)
                    {
                        if (!first)
                        {
                            result += ", ";
                        }
                        result += ECRecurringResponse.Errors[ix].LongMessage;
                        first   = false;
                    }
                }
            }

            //Log the transaction
            OrderTransactionCollection ecRecurringOrderTransaction = new OrderTransactionCollection(orderNumber);

            ecRecurringOrderTransaction.AddTransaction("PayPal Express Checkout Recurring Profile Creation",
                                                       ECRecurringRequest.ToString(),
                                                       result,
                                                       payerID,                                                                                                                                                                                       //PNREF = payerID
                                                       (ECRecurringResponse.CreateRecurringPaymentsProfileResponseDetails.ProfileID == null ? "No ProfileID provided" : ECRecurringResponse.CreateRecurringPaymentsProfileResponseDetails.ProfileID), //Code = ProfileID
                                                       AppLogic.ro_PMPayPalExpress,
                                                       null,
                                                       RecurringAmount);

            return(result);
        }
예제 #12
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            Response.CacheControl = "private";
            Response.Expires      = 0;
            Response.AddHeader("pragma", "no-cache");


            TargetCustomer = new Customer(CommonLogic.QueryStringUSInt("CustomerID"), true);
            if (TargetCustomer.CustomerID == 0)
            {
                AppLogic.AdminLinkUrl("Customers.aspx");
            }
            if (TargetCustomer.IsAdminSuperUser && !ThisCustomer.IsAdminSuperUser)
            {
                throw new ArgumentException(AppLogic.GetString("admin.common.SecurityException", SkinID, LocaleSetting));
            }
            if (CommonLogic.QueryStringUSInt("DeleteID") != 0)
            {
                DB.ExecuteSQL("delete from ShoppingCart where CustomerID=" + TargetCustomer.CustomerID.ToString() + " and ShoppingCartRecID=" + CommonLogic.QueryStringUSInt("DeleteID").ToString());
                DB.ExecuteSQL("delete from kitcart where CustomerID=" + TargetCustomer.CustomerID.ToString() + " and ShoppingCartRecID=" + CommonLogic.QueryStringUSInt("DeleteID").ToString());
            }

            if (CommonLogic.FormUSInt("OriginalRecurringOrderNumber") != 0)
            {
                int OriginalRecurringOrderNumber = CommonLogic.FormUSInt("OriginalRecurringOrderNumber");
                int NewRecurringInterval         = CommonLogic.FormUSInt("RecurringInterval");
                DateIntervalTypeEnum NewRecurringIntervalType = (DateIntervalTypeEnum)CommonLogic.FormUSInt("RecurringIntervalType");

                DateTime SetNextShipDate = System.DateTime.MinValue;
                if (CommonLogic.FormCanBeDangerousContent("NextRecurringShipDate").Length != 0)
                {
                    try
                    {
                        SetNextShipDate = CommonLogic.FormNativeDateTime("NextRecurringShipDate");
                    }
                    catch { }
                    if (SetNextShipDate != System.DateTime.MinValue && OriginalRecurringOrderNumber != 0)
                    {
                        DB.ExecuteSQL(String.Format("update shoppingcart set NextRecurringShipDate={0} where customerid={1} and originalrecurringordernumber={2}", DB.DateQuote(Localization.ToDBShortDateString(SetNextShipDate)), TargetCustomer.CustomerID.ToString(), OriginalRecurringOrderNumber.ToString()));
                    }
                }

                if (CommonLogic.FormUSInt("RecurringInterval") != 0)
                {
                    DateTime             CreatedOnDate                = System.DateTime.MinValue;
                    DateTime             LastRecurringShipDate        = System.DateTime.MinValue;
                    int                  RecurringIndex               = 1;
                    int                  CurrentRecurringInterval     = 0;
                    DateIntervalTypeEnum CurrentRecurringIntervalType = DateIntervalTypeEnum.Monthly;

                    using (SqlConnection dbconn = DB.dbConn())
                    {
                        dbconn.Open();
                        using (IDataReader rs2 = DB.GetRS("select CreatedOn, NextRecurringShipDate,RecurringIndex,RecurringInterval,RecurringIntervalType from ShoppingCart   with (NOLOCK)  where CustomerID=" + TargetCustomer.CustomerID.ToString() + " and CartType=" + ((int)CartTypeEnum.RecurringCart).ToString() + " and OriginalRecurringOrderNumber=" + OriginalRecurringOrderNumber.ToString(), dbconn))
                        {
                            if (rs2.Read())
                            {
                                CurrentRecurringInterval     = DB.RSFieldInt(rs2, "RecurringInterval");
                                CurrentRecurringIntervalType = (DateIntervalTypeEnum)DB.RSFieldInt(rs2, "RecurringIntervalType");
                                RecurringIndex        = DB.RSFieldInt(rs2, "RecurringIndex");
                                CreatedOnDate         = DB.RSFieldDateTime(rs2, "CreatedOn");
                                LastRecurringShipDate = DB.RSFieldDateTime(rs2, "NextRecurringShipDate"); // this must be "fixed" up below...we need the PRIOR ship date, not the date of next schedule ship
                            }
                        }
                    }

                    LastRecurringShipDate = System.DateTime.Now;

                    DateTime NewShipDate = System.DateTime.MinValue;
                    if (LastRecurringShipDate != System.DateTime.MinValue)
                    {
                        switch (CurrentRecurringIntervalType)
                        {
                        case DateIntervalTypeEnum.Day:
                            NewShipDate = LastRecurringShipDate.AddDays(NewRecurringInterval);
                            break;

                        case DateIntervalTypeEnum.Week:
                            NewShipDate = LastRecurringShipDate.AddDays(7 * NewRecurringInterval);
                            break;

                        case DateIntervalTypeEnum.Month:
                            NewShipDate = LastRecurringShipDate.AddMonths(NewRecurringInterval);
                            break;

                        case DateIntervalTypeEnum.Year:
                            NewShipDate = LastRecurringShipDate.AddYears(NewRecurringInterval);
                            break;

                        case DateIntervalTypeEnum.Weekly:
                            NewShipDate = LastRecurringShipDate.AddDays(7);
                            break;

                        case DateIntervalTypeEnum.BiWeekly:
                            NewShipDate = LastRecurringShipDate.AddDays(14);
                            break;

                        case DateIntervalTypeEnum.EveryFourWeeks:
                            NewShipDate = LastRecurringShipDate.AddDays(28);
                            break;

                        case DateIntervalTypeEnum.Monthly:
                            NewShipDate = LastRecurringShipDate.AddMonths(1);
                            break;

                        case DateIntervalTypeEnum.Quarterly:
                            NewShipDate = LastRecurringShipDate.AddMonths(3);
                            break;

                        case DateIntervalTypeEnum.SemiYearly:
                            NewShipDate = LastRecurringShipDate.AddMonths(6);
                            break;

                        case DateIntervalTypeEnum.Yearly:
                            NewShipDate = LastRecurringShipDate.AddYears(1);
                            break;

                        default:
                            NewShipDate = LastRecurringShipDate.AddMonths(NewRecurringInterval);
                            break;
                        }
                        DB.ExecuteSQL("update ShoppingCart set RecurringInterval=" + NewRecurringInterval.ToString() + ", RecurringIntervalType=" + ((int)NewRecurringIntervalType).ToString() + ", NextRecurringShipDate=" + DB.DateQuote(Localization.ToDBDateTimeString(NewShipDate)) + " where CustomerID=" + TargetCustomer.CustomerID.ToString() + " and CartType=" + ((int)CartTypeEnum.RecurringCart).ToString() + " and OriginalRecurringOrderNumber=" + OriginalRecurringOrderNumber.ToString());
                    }
                }
            }

            SectionTitle = "<a href=\"" + AppLogic.AdminLinkUrl("Customers.aspx") + "?searchfor=" + TargetCustomer.CustomerID.ToString() + "\">" + AppLogic.GetString("admin.menu.Customers", SkinID, LocaleSetting) + "</a> - <a href=\"" + AppLogic.AdminLinkUrl("cst_history.aspx") + "?customerid=" + TargetCustomer.CustomerID.ToString() + "\">" + AppLogic.GetString("admin.cst_recurring.OrderHistory", SkinID, LocaleSetting) + "</a> - " + AppLogic.GetString("admin.cst_recurring.RecurringShipmentsFor", SkinID, LocaleSetting) + " " + TargetCustomer.FullName() + " (" + TargetCustomer.EMail + ")";
            RenderMarkup();
        }