コード例 #1
0
        protected void SaveCardButton_Click(object sender, EventArgs e)
        {
            int   profileId             = AlwaysConvert.ToInt(HiddenProfileId.Value);
            Label ProfileSuccessMessage = (Label)PageHelper.RecursiveFindControl(Page, "ProfileSuccessMessage");
            Label ProfileErrorMessage   = (Label)PageHelper.RecursiveFindControl(Page, "ProfileErrorMessage");

            if (profileId > 0)
            {
                var profile = GatewayPaymentProfileDataSource.Load(profileId);
                if (profile != null)
                {
                    int            gatewayId = PaymentGatewayDataSource.GetPaymentGatewayIdByClassId(profile.GatewayIdentifier);
                    PaymentGateway gateway   = PaymentGatewayDataSource.Load(gatewayId);

                    if (gateway != null)
                    {
                        var provider = gateway.GetInstance();
                        try
                        {
                            AccountDataDictionary cardDetails = new AccountDataDictionary();
                            cardDetails["AccountNumber"]   = "XXX" + profile.ReferenceNumber.Replace("x", "X");
                            cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                            cardDetails["ExpirationYear"]  = ExpirationYear.SelectedItem.Value;
                            cardDetails["SecurityCode"]    = SecurityCode.Text.Trim();
                            PaymentMethod         method = PaymentMethodDataSource.Load(profile.InstrumentTypeId);
                            PaymentInstrumentData instr  = PaymentInstrumentData.CreateInstance(cardDetails, method.PaymentInstrumentType, null);
                            var rsp = provider.DoUpdatePaymentProfile(new CommerceBuilder.Payments.Providers.UpdatePaymentProfileRequest(AbleContext.Current.User, instr, profile.CustomerProfileId, profile.PaymentProfileId));
                            if (rsp.Successful || rsp.ResponseCode == "E00040")
                            {
                                int id = profile.Id;
                                profile.Expiry = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedItem.Value), AlwaysConvert.ToInt(ExpirationMonth.SelectedItem.Value), 1));
                                profile.Save();
                                if (ProfileSuccessMessage != null)
                                {
                                    ProfileSuccessMessage.Text    = string.Format("Profile '{0} ending in {1}' updated successfully!", profile.InstrumentType, profile.ReferenceNumber);
                                    ProfileSuccessMessage.Visible = true;
                                    ProfileErrorMessage.Visible   = false;
                                }
                            }
                            else
                            {
                                if (ProfileErrorMessage != null)
                                {
                                    ProfileErrorMessage.Text      = string.Format("Somthing went wrong! Unable to update profile '{0} ending in {1}'", profile.InstrumentType, profile.ReferenceNumber);
                                    ProfileSuccessMessage.Visible = false;
                                    ProfileErrorMessage.Visible   = true;
                                }

                                Logger.Error(rsp.ResponseMessage);
                            }
                        }
                        catch (Exception exp)
                        {
                            Logger.Error(exp.Message);
                        }
                    }
                }
            }
            EditCardInfoPopUp.Hide();
        }
コード例 #2
0
        private CreditCardRequest InitializeRefundRequest(Payment payment, Transaction captureTransaction, LSDecimal amount)
        {
            VerifyPaymentInstrument(payment);
            CreditCardRequest request = new CreditCardRequest();

            request.setChargeType(CreditCardRequest.CREDIT);
            request.setReferenceId(captureTransaction.ProviderTransactionId);
            request.setOrderId(payment.Order.OrderId.ToString());

            LSDecimal minAmount = 0.01M;

            if (amount > captureTransaction.Amount || amount < minAmount)
            {
                throw new InvalidOperationException("Refund Amount must be from 0.01 to the previously captured amount");
            }

            request.setChargeTotal((double)amount);

            AccountDataDictionary accountData = new AccountDataDictionary(payment.AccountData);

            SetCreditCardData(request, payment, accountData);

            if (!string.IsNullOrEmpty(payment.CurrencyCode))
            {
                request.setCurrency(payment.CurrencyCode);
            }

            return(request);
        }
コード例 #3
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid && CustomValidation())
            {
                PaymentMethod method = GetSelectedMethod();
                if (method != null)
                {
                    Payment payment = new Payment();
                    payment.Order           = _Order;
                    payment.PaymentMethodId = method.Id;
                    AccountDataDictionary paymentInstrumentBuilder = new AccountDataDictionary();
                    switch (method.PaymentInstrumentType)
                    {
                    case PaymentInstrumentType.AmericanExpress:
                    case PaymentInstrumentType.Discover:
                    case PaymentInstrumentType.JCB:
                    case PaymentInstrumentType.MasterCard:
                    case PaymentInstrumentType.Visa:
                    case PaymentInstrumentType.DinersClub:
                    case PaymentInstrumentType.Maestro:
                    case PaymentInstrumentType.SwitchSolo:
                    case PaymentInstrumentType.VisaDebit:
                        paymentInstrumentBuilder["AccountName"]     = CardName.Text;
                        paymentInstrumentBuilder["AccountNumber"]   = CardNumber.Text;
                        paymentInstrumentBuilder["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                        paymentInstrumentBuilder["ExpirationYear"]  = ExpirationYear.SelectedItem.Value;
                        paymentInstrumentBuilder["SecurityCode"]    = SecurityCode.Text;
                        if (IssueNumber.Text.Length > 0)
                        {
                            paymentInstrumentBuilder["IssueNumber"] = IssueNumber.Text;
                        }
                        if ((StartDateMonth.SelectedIndex > 0) && (StartDateYear.SelectedIndex > 0))
                        {
                            paymentInstrumentBuilder["StartDateMonth"] = StartDateMonth.SelectedItem.Value;
                            paymentInstrumentBuilder["StartDateYear"]  = StartDateYear.SelectedItem.Value;
                        }
                        payment.ReferenceNumber = StringHelper.MakeReferenceNumber(CardNumber.Text);
                        payment.Amount          = AlwaysConvert.ToDecimal(CreditCardPaymentAmount.Text);
                        break;

                    case PaymentInstrumentType.Check:
                        paymentInstrumentBuilder["RoutingNumber"] = RoutingNumber.Text;
                        paymentInstrumentBuilder["BankName"]      = BankName.Text;
                        paymentInstrumentBuilder["AccountHolder"] = AccountHolder.Text;
                        paymentInstrumentBuilder["AccountNumber"] = BankAccountNumber.Text;
                        payment.ReferenceNumber = StringHelper.MakeReferenceNumber(BankAccountNumber.Text);
                        payment.Amount          = AlwaysConvert.ToDecimal(CheckPaymentAmount.Text);
                        break;
                    }
                    if (payment.Amount > 0)
                    {
                        //ADD IN PAYMENT INSTRUMENT DATA FOR PROCESSING
                        payment.AccountData = paymentInstrumentBuilder.ToString();
                        payment.Authorize(false);
                        //REDIRECT TO PAYMENT PAGE
                        Response.Redirect("Default.aspx?OrderNumber=" + _Order.OrderNumber.ToString());
                    }
                }
            }
        }
コード例 #4
0
        private Payment GetPayment()
        {
            Payment payment = new Payment();

            payment.PaymentMethodId = AlwaysConvert.ToInt(CardType.SelectedValue);
            payment.Amount          = GetPaymentAmount();
            AccountDataDictionary instrumentBuilder = new AccountDataDictionary();

            instrumentBuilder["AccountName"]     = CardName.Text;
            instrumentBuilder["AccountNumber"]   = CardNumber.Text;
            instrumentBuilder["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
            instrumentBuilder["ExpirationYear"]  = ExpirationYear.SelectedItem.Value;
            instrumentBuilder["SecurityCode"]    = SecurityCode.Text;
            if (payment.PaymentMethod.IsIntlDebitCard())
            {
                if (IssueNumber.Text.Length > 0)
                {
                    instrumentBuilder["IssueNumber"] = IssueNumber.Text;
                }
                if ((StartDateMonth.SelectedIndex > 0) && (StartDateYear.SelectedIndex > 0))
                {
                    instrumentBuilder["StartDateMonth"] = StartDateMonth.SelectedItem.Value;
                    instrumentBuilder["StartDateYear"]  = StartDateYear.SelectedItem.Value;
                }
            }
            payment.ReferenceNumber = Payment.GenerateReferenceNumber(CardNumber.Text);
            payment.AccountData     = instrumentBuilder.ToString();
            return(payment);
        }
コード例 #5
0
        private void SetCreditCardData(CreditCardRequest request, Payment payment, AccountDataDictionary accountData)
        {
            //set credit card data
            string accountNumber   = accountData.GetValue("AccountNumber");
            string expirationMonth = accountData.GetValue("ExpirationMonth");

            if (expirationMonth.Length == 1)
            {
                expirationMonth.Insert(0, "0");
            }
            string expirationYear = accountData.GetValue("ExpirationYear");

            if (string.IsNullOrEmpty(accountNumber))
            {
                //credit card data missing. can't do much
                return;
            }
            request.setCreditCardNumber(accountNumber);
            request.setExpireMonth(expirationMonth);
            request.setExpireYear(expirationYear);

            string securityCode = accountData.GetValue("SecurityCode");

            if (!string.IsNullOrEmpty(securityCode))
            {
                request.setCreditCardVerificationNumber(securityCode);
            }
        }
コード例 #6
0
        private void SetupCreditCardData(XmlDocument xmlRequest, Payment payment, AccountDataDictionary accountData, Dictionary <string, string> sensitiveData)
        {
            //set credit card data
            string accountNumber   = accountData.GetValue("AccountNumber");
            string expirationMonth = accountData.GetValue("ExpirationMonth");

            if (expirationMonth.Length == 1)
            {
                expirationMonth.Insert(0, "0");
            }
            string expirationYear = accountData.GetValue("ExpirationYear");

            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxCard_Number", accountNumber);
            if (this.UseDebugMode)
            {
                sensitiveData[accountNumber] = MakeReferenceNumber(accountNumber);
            }
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxCCMonth", expirationMonth);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxCCYear", expirationYear);

            string securityCode = accountData.GetValue("SecurityCode");

            if (!string.IsNullOrEmpty(securityCode))
            {
                XmlUtility.SetElementValue(xmlRequest.DocumentElement, "CVV2Indicator", "0");
                XmlUtility.SetElementValue(xmlRequest.DocumentElement, "CVV2", securityCode);
                if (this.UseDebugMode)
                {
                    sensitiveData["CVV2%3E" + securityCode] = "CVV2%3E" + (new string('x', securityCode.Length));
                    sensitiveData["CVV2%3e" + securityCode] = "CVV2%3e" + (new string('x', securityCode.Length));
                }
            }
        }
コード例 #7
0
        protected void Page_Init(object sender, EventArgs e)
        {
            _PaymentId = AlwaysConvert.ToInt(Request.QueryString["PaymentId"]);
            _Payment   = PaymentDataSource.Load(_PaymentId);
            if (_Payment == null)
            {
                Response.Redirect("../Default.aspx");
            }
            _OrderId              = _Payment.OrderId;
            _Order                = _Payment.Order;
            Caption.Text          = string.Format(Caption.Text, (_Order.Payments.IndexOf(_PaymentId) + 1), _Payment.ReferenceNumber);
            PaymentReference.Text = _Payment.PaymentMethodName + " - " + _Payment.ReferenceNumber;
            PaymentAmount.Text    = _Payment.Amount.LSCurrencyFormat("lc");
            if (!Page.IsPostBack)
            {
                RefundAmount.Text = string.Format("{0:F2}", _Payment.Amount);
            }

            _PaymentProvider = GetPaymentProvider(_Payment);
            if (_PaymentProvider != null &&
                (_PaymentProvider.RefundRequiresAccountData || (_PaymentProvider.Name == "Authorize.NET CIM" && _Payment.PaymentProfile == null)))
            {
                // INITIALIZE FIELDS FOR COLLECTING REFUND ACCOUNT DATA
                _AccountData = new AccountDataDictionary(_Payment.AccountData);
                bool isCheckPayment = (_Payment.PaymentMethod != null && _Payment.PaymentMethod.PaymentInstrumentType == PaymentInstrumentType.Check);
                if (isCheckPayment)
                {
                    CheckFields.Visible      = true;
                    CreditCardFields.Visible = false;
                    DebitCardFields.Visible  = false;
                    InitializeCheckFields();
                }
                else
                {
                    CheckFields.Visible      = false;
                    CreditCardFields.Visible = true;
                    bool isAuthNet = (_PaymentProvider.Name == "Authorize.Net");
                    if (isAuthNet)
                    {
                        trCreditCardExpiration.Visible = false;
                        CreditCardNumberLiteral.Text   = " (last 4 digits or whole number)";
                        CreditCardNumberValidator.ValidationExpression = "^(\\d{4}|\\d{13,19})$";
                        CreditCardNumberValidator.ErrorMessage         = "Enter the last 4 digits or the whole number between 13 and 19 digits long.";
                    }
                    DebitCardFields.Visible = _Payment.PaymentMethod != null && _Payment.PaymentMethod.IsIntlDebitCard();
                    InitializeCreditCardFields();
                }
            }
            else
            {
                CheckFields.Visible      = false;
                CreditCardFields.Visible = false;
                DebitCardFields.Visible  = false;
            }
        }
コード例 #8
0
        private Payment GetPayment()
        {
            Payment payment = new Payment();
            IPaymentMethodProvider payMethProvider = AbleContext.Resolve <IPaymentMethodProvider>();

            payment.PaymentMethod = payMethProvider.GetGiftCertificatePaymentMethod();
            payment.Amount        = this.PaymentAmount > 0 ? this.PaymentAmount : AbleContext.Current.User.Basket.Items.TotalPrice();
            AccountDataDictionary instrumentBuilder = new AccountDataDictionary();

            instrumentBuilder["SerialNumber"] = StringHelper.StripHtml(GiftCertificateNumber.Text);
            payment.AccountData     = instrumentBuilder.ToString();
            payment.ReferenceNumber = Payment.GenerateReferenceNumber(GiftCertificateNumber.Text);
            return(payment);
        }
コード例 #9
0
        private Payment GetPayment()
        {
            Payment payment = new Payment();

            payment.PaymentMethodId = _PaymentMethodId;
            payment.Amount          = GetPaymentAmount();
            AccountDataDictionary instrumentBuilder = new AccountDataDictionary();

            instrumentBuilder["AccountHolder"] = StringHelper.StripHtml(AccountHolder.Text);
            instrumentBuilder["BankName"]      = StringHelper.StripHtml(BankName.Text);
            instrumentBuilder["RoutingNumber"] = RoutingNumber.Text;
            instrumentBuilder["AccountNumber"] = AccountNumber.Text;
            payment.ReferenceNumber            = Payment.GenerateReferenceNumber(AccountNumber.Text);
            payment.AccountData = instrumentBuilder.ToString();
            return(payment);
        }
コード例 #10
0
        private Payment GetPayment()
        {
            Payment payment = new Payment();

            payment.PaymentMethod = PaymentMethodDataSource.Load(this.PaymentMethodId);
            if (this.PaymentAmount > 0)
            {
                payment.Amount = this.PaymentAmount;
            }
            else
            {
                payment.Amount = AbleContext.Current.User.Basket.Items.TotalPrice();
            }
            AccountDataDictionary instrumentBuilder = new AccountDataDictionary();

            PurchaseOrderNumber.Text = StringHelper.StripHtml(PurchaseOrderNumber.Text);
            instrumentBuilder["PurchaseOrderNumber"] = PurchaseOrderNumber.Text;
            payment.ReferenceNumber = PurchaseOrderNumber.Text;
            payment.AccountData     = instrumentBuilder.ToString();
            return(payment);
        }
コード例 #11
0
        private Payment GetPayment()
        {
            Payment payment = new Payment();

            payment.Amount = GetPaymentAmount(true);

            if (ProfilesPH.Visible)
            {
                var profile = GatewayPaymentProfileDataSource.Load(AlwaysConvert.ToInt(ProfilesList.SelectedValue));
                payment.PaymentProfile    = profile;
                payment.ReferenceNumber   = profile.ReferenceNumber;
                payment.PaymentMethodName = profile.PaymentMethodName;
            }
            else
            {
                payment.PaymentMethod = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue));
                AccountDataDictionary instrumentBuilder = new AccountDataDictionary();
                instrumentBuilder["AccountName"]     = CardName.Text;
                instrumentBuilder["AccountNumber"]   = CardNumber.Text;
                instrumentBuilder["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                instrumentBuilder["ExpirationYear"]  = ExpirationYear.SelectedItem.Value;
                instrumentBuilder["SecurityCode"]    = SecurityCode.Text;
                if (payment.PaymentMethod.IsIntlDebitCard())
                {
                    if (IssueNumber.Text.Length > 0)
                    {
                        instrumentBuilder["IssueNumber"] = IssueNumber.Text;
                    }
                    if ((StartDateMonth.SelectedIndex > 0) && (StartDateYear.SelectedIndex > 0))
                    {
                        instrumentBuilder["StartDateMonth"] = StartDateMonth.SelectedItem.Value;
                        instrumentBuilder["StartDateYear"]  = StartDateYear.SelectedItem.Value;
                    }
                }
                payment.ReferenceNumber = Payment.GenerateReferenceNumber(CardNumber.Text);
                payment.AccountData     = instrumentBuilder.ToString();
            }

            return(payment);
        }
コード例 #12
0
        private CreditCardRequest InitializeVoidRequest(Payment payment, Transaction authorizeTransaction)
        {
            VerifyPaymentInstrument(payment);
            CreditCardRequest request = new CreditCardRequest();

            request.setChargeType(CreditCardRequest.VOID);
            request.setReferenceId(authorizeTransaction.ProviderTransactionId);
            request.setOrderId(payment.Order.OrderId.ToString());

            request.setChargeTotal((double)authorizeTransaction.Amount);

            AccountDataDictionary accountData = new AccountDataDictionary(payment.AccountData);

            SetCreditCardData(request, payment, accountData);

            if (!string.IsNullOrEmpty(payment.CurrencyCode))
            {
                request.setCurrency(payment.CurrencyCode);
            }

            return(request);
        }
コード例 #13
0
 protected void UpdateButton_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         int            gatewayId = PaymentGatewayDataSource.GetPaymentGatewayIdByClassId(_profile.GatewayIdentifier);
         PaymentGateway gateway   = PaymentGatewayDataSource.Load(gatewayId);
         if (gateway != null)
         {
             var provider = gateway.GetInstance();
             try
             {
                 AccountDataDictionary cardDetails = new AccountDataDictionary();
                 cardDetails["AccountNumber"]   = _profile.ReferenceNumber.PadLeft(8, 'x').ToUpper();
                 cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedValue;
                 cardDetails["ExpirationYear"]  = ExpirationYear.SelectedValue;
                 cardDetails["SecurityCode"]    = SecurityCode.Text;
                 PaymentInstrumentData instr = PaymentInstrumentData.CreateInstance(cardDetails, _profile.InstrumentType, null);
                 var rsp = provider.DoUpdatePaymentProfile(new CommerceBuilder.Payments.Providers.UpdatePaymentProfileRequest(AbleContext.Current.User, instr, _profile.CustomerProfileId, _profile.PaymentProfileId));
                 if (rsp.Successful || rsp.ResponseCode == "E00040")
                 {
                     _profile.Expiry = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedValue), AlwaysConvert.ToInt(ExpirationMonth.SelectedValue), 1));
                     _profile.Save();
                     SuccessMessage.Text    = string.Format(SuccessMessage.Text, LocaleHelper.LocalNow);
                     SuccessMessage.Visible = true;
                 }
                 else
                 {
                     ErrorMessage.Visible = true;
                     Logger.Error(rsp.ResponseMessage);
                 }
             }
             catch (Exception exp)
             {
                 Logger.Error(exp.Message);
             }
         }
     }
 }
コード例 #14
0
        private string InitializeRefundRequest(Payment payment, RefundTransactionRequest refundRequest, Transaction authorizeTransaction, LSDecimal dAmount, Dictionary <string, string> sensitiveData)
        {
            Order order = payment.Order;
            AccountDataDictionary accountData = new AccountDataDictionary(payment.AccountData);
            string accountNumber   = refundRequest.CardNumber;
            string expirationMonth = refundRequest.ExpirationMonth.ToString();
            string expirationYear  = refundRequest.ExpirationYear.ToString();

            if (expirationMonth.Length == 1)
            {
                expirationMonth = "0" + expirationMonth;
            }
            if (expirationYear.Length > 2)
            {
                expirationYear = expirationYear.Substring(expirationYear.Length - 2);
            }
            string expireDate   = expirationMonth + expirationYear;
            string amount       = String.Format("{0:F2}", dAmount);
            string securityCode = accountData.GetValue("SecurityCode");

            string fullName;

            if (accountData.ContainsKey("AccountName") && !string.IsNullOrEmpty(accountData["AccountName"]))
            {
                fullName = accountData["AccountName"];
            }
            else
            {
                fullName = order.BillToFirstName + " " + order.BillToLastName;
            }

            string data = "dc_logon=" + HttpUtility.UrlEncode(this.LoginName, System.Text.Encoding.UTF8);

            data += Encode("dc_password", this.Password);
            if (this.UseDebugMode)
            {
                sensitiveData[this.Password] = "xxxxxxxx";
            }
            data += Encode("dc_transaction_type", "CREDIT");
            data += Encode("dc_version", "1.2");
            data += Encode("dc_transaction_id", authorizeTransaction.ProviderTransactionId);
            data += Encode("dc_address", order.BillToAddress1 + " " + order.BillToAddress2);
            data += Encode("dc_city", order.BillToCity);
            data += Encode("dc_zip", order.BillToPostalCode);
            data += Encode("dc_transaction_amount", amount);
            data += Encode("dc_name", fullName);
            data += Encode("dc_number", accountNumber);
            if (this.UseDebugMode)
            {
                sensitiveData[accountNumber] = MakeReferenceNumber(accountNumber);
            }
            data += Encode("dc_expiration_month", expirationMonth);
            data += Encode("dc_expiration_year", expirationYear);
            if (!string.IsNullOrEmpty(securityCode))
            {
                data += Encode("dc_verification_number", securityCode);
                if (this.UseDebugMode)
                {
                    sensitiveData["dc_verification_number=" + securityCode] = "dc_verification_number=" + (new string('x', securityCode.Length));
                }
            }

            return(data);
        }
コード例 #15
0
        protected void SaveCardButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid && CustomValidation())
            {
                AccountDataDictionary cardDetails = new AccountDataDictionary();
                cardDetails["AccountName"] = CardName.Text.Trim();
                cardDetails["AccountNumber"] = CardNumber.Text.Trim();
                cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                cardDetails["ExpirationYear"] = ExpirationYear.SelectedItem.Value;
                cardDetails["SecurityCode"] = SecurityCode.Text.Trim();
                PaymentMethod method = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue));
                PaymentInstrumentData instr = PaymentInstrumentData.CreateInstance(cardDetails, method.PaymentInstrumentType, null);
                PaymentGateway gateway = method.PaymentGateway;
                if (gateway != null)
                {
                    var provider = gateway.GetInstance();
                    string customerProfileId = string.Empty;
                    var profileResult = _user.PaymentProfiles.Where(p => p.GatewayIdentifier == gateway.ClassId)
                        .GroupBy(p => p.CustomerProfileId)
                        .Take(1)
                        .Select(g => new { CustomerProfileId = g.Key })
                        .SingleOrDefault();

                    if (profileResult != null && !string.IsNullOrEmpty(profileResult.CustomerProfileId))
                        customerProfileId = profileResult.CustomerProfileId;

                    if (string.IsNullOrEmpty(customerProfileId))
                    {
                        try 
                        {
                            var rsp = provider.DoCreateCustomerProfile(new CommerceBuilder.Payments.Providers.CreateCustomerProfileRequest(_user));
                            if (rsp.Successful)
                                customerProfileId = rsp.CustomerProfileId;
                            else if (rsp.ResponseCode == "E00039")
                            {
                                var match = Regex.Match(rsp.ResponseMessage, @"\d+", RegexOptions.IgnoreCase);
                                if(match.Success)
                                    customerProfileId = match.Value;
                                else
                                    ErrorMessage.Text = rsp.ResponseMessage;
                            }
                            else
                                ErrorMessage.Text = rsp.ResponseMessage;
                        }
                        catch(Exception exp)
                        {
                            ErrorMessage.Text = exp.Message;
                        }

                        if (string.IsNullOrEmpty(customerProfileId)) return;
                    }

                    try
                    {
                        var rsp = provider.DoCreatePaymentProfile(new CommerceBuilder.Payments.Providers.CreatePaymentProfileRequest(_user, instr, customerProfileId) { ValidateProfile = true });
                        if (rsp.Successful)
                        {
                            GatewayPaymentProfile gwprofile = new GatewayPaymentProfile();
                            gwprofile.NameOnCard = CardName.Text.Trim(); ;
                            gwprofile.Expiry = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedItem.Value), AlwaysConvert.ToInt(ExpirationMonth.SelectedItem.Value), 1));
                            gwprofile.CustomerProfileId = customerProfileId;
                            gwprofile.PaymentProfileId = rsp.PaymentProfileId;
                            gwprofile.ReferenceNumber = StringHelper.MakeReferenceNumber(cardDetails["AccountNumber"]);
                            gwprofile.User = _user;
                            gwprofile.InstrumentType = instr.InstrumentType;
                            gwprofile.PaymentMethodName = method.Name;
                            gwprofile.GatewayIdentifier = gateway.ClassId;
                            gwprofile.Save();
                            if (_user.PaymentProfiles.Count == 0)
                            {
                                _user.Settings.DefaultPaymentProfileId = gwprofile.Id;
                                _user.Settings.Save();
                            }
                            CardName.Text = string.Empty;
                            CardNumber.Text = string.Empty;
                            ExpirationMonth.SelectedIndex = 0;
                            ExpirationYear.SelectedIndex = 0;
                            BindCards();
                        }
                        else
                        {
                            ErrorMessage.Text = rsp.ResponseMessage;
                            Logger.Error(rsp.ResponseMessage);
                        }
                    }
                    catch (Exception exp)
                    {
                        ErrorMessage.Text = exp.Message;
                    }
                }
            }
        }
コード例 #16
0
        private string InitializeAuthRecurringRequest(AuthorizeRecurringTransactionRequest authRequest, Dictionary <string, string> sensitiveData)
        {
            Payment payment = authRequest.Payment;
            User    user    = payment.Order.User;
            Order   order   = payment.Order;

            VerifyPaymentInstrument(payment);
            AccountDataDictionary accountData = new AccountDataDictionary(payment.AccountData);
            string accountNumber   = accountData.GetValue("AccountNumber");
            string expirationMonth = accountData.GetValue("ExpirationMonth");
            string expirationYear  = accountData.GetValue("ExpirationYear");

            if (expirationMonth.Length == 1)
            {
                expirationMonth = "0" + expirationMonth;
            }
            if (expirationYear.Length > 2)
            {
                expirationYear = expirationYear.Substring(expirationYear.Length - 2);
            }
            string expireDate   = expirationMonth + expirationYear;
            string amount       = String.Format("{0:F2}", authRequest.RecurringChargeSpecified? authRequest.RecurringCharge : authRequest.Amount);
            string securityCode = accountData.GetValue("SecurityCode");

            //authentication data
            string data = "dc_logon=" + HttpUtility.UrlEncode(this.LoginName, System.Text.Encoding.UTF8);

            data += Encode("dc_password", this.Password);
            if (this.UseDebugMode)
            {
                sensitiveData[this.Password] = "xxxxxxxx";
            }

            //address data
            data += Encode("dc_address", order.BillToAddress1 + " " + order.BillToAddress2);
            data += Encode("dc_city", order.BillToCity);
            data += Encode("dc_zip", order.BillToPostalCode);
            data += Encode("dc_country", order.BillToCountryCode);

            //transaction data
            data += Encode("dc_transaction_type", "AUTHORIZATION_CAPTURE");
            data += Encode("dc_transaction_amount", amount);
            data += Encode("dc_version", "1.2");

            //cc data
            string fullName;

            if (accountData.ContainsKey("AccountName") && !string.IsNullOrEmpty(accountData["AccountName"]))
            {
                fullName = accountData["AccountName"];
            }
            else
            {
                fullName = order.BillToFirstName + " " + order.BillToLastName;
            }
            data += Encode("dc_name", fullName);
            data += Encode("dc_number", accountNumber);
            if (this.UseDebugMode)
            {
                sensitiveData[accountNumber] = MakeReferenceNumber(accountNumber);
            }
            data += Encode("dc_expiration_month", expirationMonth);
            data += Encode("dc_expiration_year", expirationYear);

            if (!string.IsNullOrEmpty(securityCode))
            {
                data += Encode("dc_verification_number", securityCode);
                if (this.UseDebugMode)
                {
                    sensitiveData["dc_verification_number=" + securityCode] = "dc_verification_number=" + (new string('x', securityCode.Length));
                }
            }

            //schedule data
            data += Encode("dc_schedule_create", "true");
            int remainingPayments = authRequest.NumberOfPayments;

            if (authRequest.RecurringChargeSpecified)
            {
                remainingPayments -= 1;
            }
            data += Encode("dc_schedule_limit", remainingPayments.ToString());
            if (authRequest.PaymentFrequencyUnit == CommerceBuilder.Products.PaymentFrequencyUnit.Day)
            {
                data += Encode("dc_schedule_periodic_type", "day");
            }
            else
            {
                data += Encode("dc_schedule_periodic_type", "month");
            }
            data += Encode("dc_schedule_periodic_number", authRequest.PaymentFrequency.ToString());

            DateTime startDt = GetNextPaymentDate(authRequest);

            data += Encode("dc_schedule_start", startDt.ToString("yyyy-MM-dd"));

            return(data);
        }
コード例 #17
0
 private static bool HasValue(AccountDataDictionary data, string varName)
 {
     return(data.ContainsKey(varName) && !string.IsNullOrEmpty(data[varName]));
 }
コード例 #18
0
        protected GatewayPaymentProfile CreateProfile(AccountDataDictionary cardDetails)
        {
            PaymentMethod         method  = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue));
            PaymentGateway        gateway = method.PaymentGateway;
            PaymentInstrumentData instr   = PaymentInstrumentData.CreateInstance(cardDetails, method.PaymentInstrumentType, null);
            GatewayPaymentProfile profile = null;

            if (gateway != null)
            {
                var    provider          = gateway.GetInstance();
                string customerProfileId = string.Empty;
                var    profileResult     = _user.PaymentProfiles.Where(p => p.GatewayIdentifier == gateway.ClassId)
                                           .GroupBy(p => p.CustomerProfileId)
                                           .Take(1)
                                           .Select(g => new { CustomerProfileId = g.Key })
                                           .SingleOrDefault();

                if (profileResult != null && !string.IsNullOrEmpty(profileResult.CustomerProfileId))
                {
                    customerProfileId = profileResult.CustomerProfileId;
                }

                if (string.IsNullOrEmpty(customerProfileId))
                {
                    try
                    {
                        var rsp = provider.DoCreateCustomerProfile(new CommerceBuilder.Payments.Providers.CreateCustomerProfileRequest(_user));
                        if (rsp.Successful)
                        {
                            customerProfileId = rsp.CustomerProfileId;
                        }
                        else if (rsp.ResponseCode == "E00039")
                        {
                            var match = Regex.Match(rsp.ResponseMessage, @"\d+", RegexOptions.CultureInvariant);
                            if (match.Success)
                            {
                                customerProfileId = match.Value;
                            }
                            else
                            {
                                Logger.Error(rsp.ResponseMessage);
                            }
                        }
                        else
                        {
                            Logger.Error(rsp.ResponseMessage);
                        }
                    }
                    catch (Exception exp)
                    {
                        Logger.Error(exp.Message);
                    }
                }

                try
                {
                    var rsp = provider.DoCreatePaymentProfile(new CommerceBuilder.Payments.Providers.CreatePaymentProfileRequest(_user, instr, customerProfileId)
                    {
                        ValidateProfile = true
                    });
                    if (rsp.Successful)
                    {
                        GatewayPaymentProfile gwprofile = new GatewayPaymentProfile();
                        gwprofile.NameOnCard        = CardName.Text.Trim();;
                        gwprofile.Expiry            = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedItem.Value), AlwaysConvert.ToInt(ExpirationMonth.SelectedItem.Value), 1));
                        gwprofile.CustomerProfileId = customerProfileId;
                        gwprofile.PaymentProfileId  = rsp.PaymentProfileId;
                        gwprofile.ReferenceNumber   = StringHelper.MakeReferenceNumber(cardDetails["AccountNumber"]);
                        gwprofile.User              = _user;
                        gwprofile.InstrumentType    = instr.InstrumentType;
                        gwprofile.PaymentMethodName = method.Name;
                        gwprofile.GatewayIdentifier = gateway.ClassId;
                        gwprofile.Save();
                        CardName.Text   = string.Empty;
                        CardNumber.Text = string.Empty;
                        ExpirationMonth.SelectedIndex = 0;
                        ExpirationYear.SelectedIndex  = 0;
                        profile = gwprofile;
                    }
                }
                catch (Exception exp)
                {
                    Logger.Error(exp.Message);
                }
            }

            return(profile);
        }
コード例 #19
0
        private string InitializeAuthRequest(Payment payment, Order order, User user, Dictionary <string, string> sensitiveData, bool capture)
        {
            VerifyPaymentInstrument(payment);
            //Address address = user.PrimaryAddress;
            AccountDataDictionary accountData = new AccountDataDictionary(payment.AccountData);
            string accountNumber   = accountData.GetValue("AccountNumber");
            string expirationMonth = accountData.GetValue("ExpirationMonth");
            string expirationYear  = accountData.GetValue("ExpirationYear");

            if (expirationMonth.Length == 1)
            {
                expirationMonth = "0" + expirationMonth;
            }
            if (expirationYear.Length > 2)
            {
                expirationYear = expirationYear.Substring(expirationYear.Length - 2);
            }
            string expireDate   = expirationMonth + expirationYear;
            string amount       = String.Format("{0:F2}", payment.Amount);
            string securityCode = accountData.GetValue("SecurityCode");

            string data = "dc_logon=" + HttpUtility.UrlEncode(this.LoginName, System.Text.Encoding.UTF8);

            data += Encode("dc_password", this.Password);
            if (this.UseDebugMode)
            {
                sensitiveData[this.Password] = "xxxxxxxx";
            }
            if (capture)
            {
                data += Encode("dc_transaction_type", "AUTHORIZATION_CAPTURE");
            }
            else
            {
                data += Encode("dc_transaction_type", "AUTHORIZATION");
            }

            string fullName;

            if (accountData.ContainsKey("AccountName") && !string.IsNullOrEmpty(accountData["AccountName"]))
            {
                fullName = accountData["AccountName"];
            }
            else
            {
                fullName = order.BillToFirstName + " " + order.BillToLastName;
            }

            data += Encode("dc_version", "1.2");
            data += Encode("dc_address", order.BillToAddress1 + " " + order.BillToAddress2);
            data += Encode("dc_city", order.BillToCity);
            data += Encode("dc_zip", order.BillToPostalCode);
            data += Encode("dc_country", order.BillToCountryCode);
            data += Encode("dc_transaction_amount", amount);
            data += Encode("dc_name", fullName);
            data += Encode("dc_number", accountNumber);
            if (this.UseDebugMode)
            {
                sensitiveData[accountNumber] = MakeReferenceNumber(accountNumber);
            }
            data += Encode("dc_expiration_month", expirationMonth);
            data += Encode("dc_expiration_year", expirationYear);

            if (!string.IsNullOrEmpty(securityCode))
            {
                data += Encode("dc_verification_number", securityCode);
                if (this.UseDebugMode)
                {
                    sensitiveData["dc_verification_number=" + securityCode] = "dc_verification_number=" + (new string('x', securityCode.Length));
                }
            }

            return(data);
        }
コード例 #20
0
        private CreditCardRequest InitializeAuthRequest(AuthorizeTransactionRequest authorizeRequest)
        {
            Payment payment = authorizeRequest.Payment;
            Order   order   = payment.Order;
            User    user    = order.User;

            VerifyPaymentInstrument(payment);
            CreditCardRequest request = new CreditCardRequest();

            AccountDataDictionary accountData = new AccountDataDictionary(payment.AccountData);

            //set user info
            if (accountData.ContainsKey("AccountName") && !string.IsNullOrEmpty(accountData["AccountName"]))
            {
                string[] names = accountData["AccountName"].Split(" ".ToCharArray());
                request.setBillFirstName(names[0]);
                if (names.Length > 1)
                {
                    request.setBillLastName(string.Join(" ", names, 1, names.Length - 1));
                }
                else
                {
                    //no last name. what to do? send empty string? TODO : check the API
                    request.setBillLastName(string.Empty);
                }
            }
            else
            {
                request.setBillFirstName(order.BillToFirstName);
                request.setBillLastName(order.BillToLastName);
            }

            request.setBillEmail(order.BillToEmail);
            request.setBillCompany(order.BillToCompany);
            request.setBillAddressOne(order.BillToAddress1);
            request.setBillAddressTwo(order.BillToAddress2);
            request.setBillCity(order.BillToCity);
            request.setBillStateOrProvince(order.BillToProvince);
            request.setBillPostalCode(order.BillToPostalCode);
            request.setBillCountryCode(order.BillToCountryCode);
            request.setBillPhone(order.BillToPhone);
            request.setBillFax(order.BillToFax);
            request.setOrderUserId(user.UserId.ToString());

            SetCreditCardData(request, payment, accountData);

            // set charge details
            if (this.UseAuthCapture)
            {
                request.setChargeType(CreditCardRequest.SALE);
            }
            else
            {
                request.setChargeType(CreditCardRequest.AUTH);
            }
            request.setChargeTotal((double)authorizeRequest.Amount);
            //TODO set tax and shipping
            //request.setTaxAmount();
            //request.setShippingCharge();
            if (!string.IsNullOrEmpty(payment.CurrencyCode))
            {
                request.setCurrency(payment.CurrencyCode);
            }

            request.setOrderId(order.OrderId.ToString());
            request.setInvoiceNumber(order.OrderNumber.ToString());
            //TODO add description if present
            //if(!string.IsNullOrEmpty(order.Notes)) {
            //    request.setOrderDescription(order.Notes);
            //}

            HttpContext context = HttpContext.Current;

            if (context != null)
            {
                request.setCustomerIpAddress(context.Request.ServerVariables["REMOTE_HOST"]);
            }

            return(request);
        }
コード例 #21
0
        protected void CreditCardButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid && CustomValidation())
            {
                // CREATE THE PAYMENT OBJECT
                Payment payment = GetPayment();

                // PROCESS CHECKING OUT EVENT
                bool checkOut = true;
                if (CheckingOut != null)
                {
                    CheckingOutEventArgs c = new CheckingOutEventArgs(payment);
                    CheckingOut(this, c);
                    checkOut = !c.Cancel;
                }

                if (checkOut)
                {
                    // CONTINUE TO PROCESS THE CHECKOUT
                    Basket           basket           = AbleContext.Current.User.Basket;
                    ICheckoutService checkoutService  = AbleContext.Resolve <ICheckoutService>();
                    CheckoutRequest  checkoutRequest  = new CheckoutRequest(basket, payment);
                    CheckoutResponse checkoutResponse = checkoutService.ExecuteCheckout(checkoutRequest);
                    if (checkoutResponse.Success)
                    {
                        if (trSaveCard.Visible && SaveCard.Checked)
                        {
                            AccountDataDictionary cardDetails = new AccountDataDictionary();
                            cardDetails["AccountName"]     = CardName.Text.Trim();
                            cardDetails["AccountNumber"]   = CardNumber.Text.Trim();
                            cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                            cardDetails["ExpirationYear"]  = ExpirationYear.SelectedItem.Value;
                            cardDetails["SecurityCode"]    = SecurityCode.Text.Trim();
                            PaymentMethod         method  = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue));
                            PaymentGateway        gateway = method.PaymentGateway;
                            PaymentInstrumentData instr   = PaymentInstrumentData.CreateInstance(cardDetails, method.PaymentInstrumentType, null);
                            if (gateway != null)
                            {
                                var    provider          = gateway.GetInstance();
                                string customerProfileId = string.Empty;
                                var    profileResult     = _user.PaymentProfiles.Where(p => p.GatewayIdentifier == gateway.ClassId)
                                                           .GroupBy(p => p.CustomerProfileId)
                                                           .Take(1)
                                                           .Select(g => new { CustomerProfileId = g.Key })
                                                           .SingleOrDefault();

                                if (profileResult != null && !string.IsNullOrEmpty(profileResult.CustomerProfileId))
                                {
                                    customerProfileId = profileResult.CustomerProfileId;
                                }

                                if (string.IsNullOrEmpty(customerProfileId))
                                {
                                    try
                                    {
                                        var rsp = provider.DoCreateCustomerProfile(new CommerceBuilder.Payments.Providers.CreateCustomerProfileRequest(_user));
                                        if (rsp.Successful)
                                        {
                                            customerProfileId = rsp.CustomerProfileId;
                                        }
                                        else if (rsp.ResponseCode == "E00039")
                                        {
                                            var match = Regex.Match(rsp.ResponseMessage, @"\d+", RegexOptions.CultureInvariant);
                                            if (match.Success)
                                            {
                                                customerProfileId = match.Value;
                                            }
                                            else
                                            {
                                                Logger.Error(rsp.ResponseMessage);
                                            }
                                        }
                                        else
                                        {
                                            Logger.Error(rsp.ResponseMessage);
                                        }
                                    }
                                    catch (Exception exp)
                                    {
                                        Logger.Error(exp.Message);
                                    }
                                }

                                try
                                {
                                    var rsp = provider.DoCreatePaymentProfile(new CommerceBuilder.Payments.Providers.CreatePaymentProfileRequest(_user, instr, customerProfileId)
                                    {
                                        ValidateProfile = true
                                    });
                                    if (rsp.Successful)
                                    {
                                        GatewayPaymentProfile gwprofile = new GatewayPaymentProfile();
                                        gwprofile.NameOnCard        = CardName.Text.Trim();;
                                        gwprofile.Expiry            = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedItem.Value), AlwaysConvert.ToInt(ExpirationMonth.SelectedItem.Value), 1));
                                        gwprofile.CustomerProfileId = customerProfileId;
                                        gwprofile.PaymentProfileId  = rsp.PaymentProfileId;
                                        gwprofile.ReferenceNumber   = StringHelper.MakeReferenceNumber(cardDetails["AccountNumber"]);
                                        gwprofile.User              = _user;
                                        gwprofile.InstrumentType    = instr.InstrumentType;
                                        gwprofile.PaymentMethodName = method.Name;
                                        gwprofile.GatewayIdentifier = gateway.ClassId;
                                        gwprofile.Save();
                                        CardName.Text   = string.Empty;
                                        CardNumber.Text = string.Empty;
                                        ExpirationMonth.SelectedIndex = 0;
                                        ExpirationYear.SelectedIndex  = 0;
                                    }
                                }
                                catch (Exception exp)
                                {
                                    Logger.Error(exp.Message);
                                }
                            }
                        }

                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                        Response.Redirect(AbleCommerce.Code.NavigationHelper.GetReceiptUrl(checkoutResponse.Order.OrderNumber));
                    }
                    else
                    {
                        IList <string> warningMessages = checkoutResponse.WarningMessages;
                        if (warningMessages.Count == 0)
                        {
                            warningMessages.Add("The order could not be submitted at this time.  Please try again later or contact us for assistance.");
                        }
                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                    }
                }
            }
        }
コード例 #22
0
        private string InitializeAuthRecurringRequest(AuthorizeRecurringTransactionRequest authRequest, string payPeriod, Dictionary <string, string> sensitiveData)
        {
            Payment payment = authRequest.Payment;
            Order   order   = payment.Order;
            User    user    = order.User;

            XmlDocument xmlRequest = new XmlDocument();

            xmlRequest.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TranxRequest />");

            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "MerchantNumber", MerchantNumber);

            AccountDataDictionary accountData = new AccountDataDictionary(payment.AccountData);

            /*string sCurrencyCode = payment.CurrencyCode;
             * if (!("USD".Equals(sCurrencyCode)))
             * {
             *  sCurrencyCode = "CAD";
             * }*/
            string sCurrencyCode = "CAD";

            if (IsUSD)
            {
                sCurrencyCode = "USD";
            }

            string    recurrFlag    = "{RB ";
            LSDecimal recurAmount   = authRequest.RecurringChargeSpecified ? authRequest.RecurringCharge : authRequest.Amount;
            string    startDtString = GetNextPaymentDateStr(authRequest);
            string    duration      = ((int)(authRequest.NumberOfPayments - 1)).ToString();

            recurrFlag += recurAmount.ToString("F2") + " " + startDtString + " " + payPeriod + " " + duration + " email=2}";

            string ccFlag   = "{" + sCurrencyCode + "}";
            string testFlag = (UseTestMode ? "{TEST}" : "");

            string sFlags       = ccFlag + testFlag + recurrFlag;
            string sDescription = authRequest.SubscriptionName; //order.Notes;
            string sAmount      = String.Format("{0:F2}", authRequest.Amount);

            string pline;

            System.Collections.Generic.List <string> arrProducts = new System.Collections.Generic.List <string>();
            if (IncludeOrderItems)
            {
                OrderItemCollection orderItems = order.Items;
                if (orderItems != null && orderItems.Count > 0)
                {
                    foreach (OrderItem orderItem in orderItems)
                    {
                        if (orderItem.OrderItemType == OrderItemType.Product)
                        {
                            pline = "0.00::" + orderItem.Quantity + "::" + MakeSafe(orderItem.Sku, 30) + "::" + MakeSafe(orderItem.Name, 150) + "::" + sFlags;
                            arrProducts.Add(pline);
                        }
                    }
                }
            }

            pline = sAmount + "::1::" + order.OrderNumber + "::" + sDescription + "::" + sFlags;
            arrProducts.Add(pline);

            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "Products", string.Join("|", (string[])arrProducts.ToArray()));
            if (accountData.ContainsKey("AccountName") && !string.IsNullOrEmpty(accountData["AccountName"]))
            {
                XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxName", accountData["AccountName"]);
            }
            else
            {
                XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxName", order.BillToFirstName + " " + order.BillToLastName);
            }

            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxCompany", order.BillToCompany);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxAddress", order.BillToAddress1);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxCity", order.BillToCity);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxProvince", order.BillToProvince);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxPostal", order.BillToPostalCode);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxCountry", order.BillToCountryCode);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxPhone", order.BillToPhone);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxEmail", order.BillToEmail);


            SetupCreditCardData(xmlRequest, payment, accountData, sensitiveData);

            StringBuilder formData = new StringBuilder();

            formData.Append("xxxRequestMode=X&xxxRequestData=" + HttpUtility.UrlEncode(XmlToString(xmlRequest)));

            return(formData.ToString());
        }
コード例 #23
0
        protected void SaveCardButton_Click(Object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                GatewayPaymentProfile profile = _Subscription.PaymentProfile;
                if (profile != null)
                {
                    AccountDataDictionary cardDetails = new AccountDataDictionary();
                    cardDetails["AccountName"]     = CardName.Text.Trim();
                    cardDetails["AccountNumber"]   = CardNumber.Text.Trim();
                    cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                    cardDetails["ExpirationYear"]  = ExpirationYear.SelectedItem.Value;
                    cardDetails["SecurityCode"]    = SecurityCode.Text.Trim();
                    PaymentMethod         method = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue));
                    PaymentInstrumentData instr  = PaymentInstrumentData.CreateInstance(cardDetails, method.PaymentInstrumentType, null);
                    int            gatewayId     = PaymentGatewayDataSource.GetPaymentGatewayIdByClassId(_Subscription.PaymentProfile.GatewayIdentifier);
                    PaymentGateway gateway       = PaymentGatewayDataSource.Load(gatewayId);
                    if (gateway != null)
                    {
                        var provider = gateway.GetInstance();
                        try
                        {
                            var rsp = provider.DoCreatePaymentProfile(new CommerceBuilder.Payments.Providers.CreatePaymentProfileRequest(_Subscription.User, instr, profile.CustomerProfileId)
                            {
                                ValidateProfile = true
                            });
                            if (rsp.Successful)
                            {
                                GatewayPaymentProfile gwprofile = new GatewayPaymentProfile();
                                gwprofile.NameOnCard        = CardName.Text.Trim();;
                                gwprofile.Expiry            = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedItem.Value), AlwaysConvert.ToInt(ExpirationMonth.SelectedItem.Value), 1));
                                gwprofile.CustomerProfileId = profile.CustomerProfileId;
                                gwprofile.PaymentProfileId  = rsp.PaymentProfileId;
                                gwprofile.ReferenceNumber   = StringHelper.MakeReferenceNumber(cardDetails["AccountNumber"]);
                                gwprofile.User              = _Subscription.User;
                                gwprofile.InstrumentType    = instr.InstrumentType;
                                gwprofile.GatewayIdentifier = profile.GatewayIdentifier;
                                gwprofile.Save();
                                BindPayments(gwprofile.Id);
                                CardName.Text   = string.Empty;
                                CardNumber.Text = string.Empty;
                                ExpirationMonth.SelectedIndex = 0;
                                ExpirationYear.SelectedIndex  = 0;
                                AddCardPopup.Hide();
                            }
                            else
                            {
                                ErrorMessage.Text = rsp.ResponseMessage;
                                AddCardPopup.Show();
                            }
                        }
                        catch (Exception exp)
                        {
                            Logger.Error(exp.Message);
                            ErrorMessage.Text = exp.Message;
                            AddCardPopup.Show();
                        }
                    }

                    BindPayments(profile.Id);
                }
            }
            else
            {
                AddCardPopup.Show();
            }
        }
コード例 #24
0
        protected void CreditCardButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid && CustomValidation())
            {
                // CREATE THE PAYMENT OBJECT
                Payment payment = GetPayment();

                // PROCESS CHECKING OUT EVENT
                bool checkOut = true;
                if (CheckingOut != null)
                {
                    CheckingOutEventArgs c = new CheckingOutEventArgs(payment);
                    CheckingOut(this, c);
                    checkOut = !c.Cancel;
                }

                if (checkOut)
                {
                    // CONTINUE TO PROCESS THE CHECKOUT
                    Basket           basket           = AbleContext.Current.User.Basket;
                    ICheckoutService checkoutService  = AbleContext.Resolve <ICheckoutService>();
                    CheckoutRequest  checkoutRequest  = new CheckoutRequest(basket, payment);
                    CheckoutResponse checkoutResponse = checkoutService.ExecuteCheckout(checkoutRequest);
                    if (checkoutResponse.Success)
                    {
                        GatewayPaymentProfile profile = null;
                        if (trSaveCard.Visible && SaveCard.Checked)
                        {
                            AccountDataDictionary cardDetails = new AccountDataDictionary();
                            cardDetails["AccountName"]     = CardName.Text.Trim();
                            cardDetails["AccountNumber"]   = CardNumber.Text.Trim();
                            cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                            cardDetails["ExpirationYear"]  = ExpirationYear.SelectedItem.Value;
                            cardDetails["SecurityCode"]    = SecurityCode.Text.Trim();
                            profile = CreateProfile(cardDetails);
                        }

                        if (AbleContext.Current.Store.Settings.ROCreateNewOrdersEnabled && OrderHelper.HasRecurringSubscriptions(checkoutResponse.Order))
                        {
                            IList <Subscription> subscriptions = SubscriptionDataSource.LoadForOrder(checkoutResponse.Order.Id);
                            foreach (Subscription subscription in subscriptions)
                            {
                                OrderItem oi = subscription.OrderItem;
                                if (oi != null && oi.Price == 0 && OrderHelper.HasRecurringSubscriptions(oi) && subscription.PaymentProfile == null)
                                {
                                    if (profile == null)
                                    {
                                        if (ProfilesPH.Visible)
                                        {
                                            profile = GatewayPaymentProfileDataSource.Load(AlwaysConvert.ToInt(ProfilesList.SelectedValue));
                                        }

                                        if (CardPH.Visible)
                                        {
                                            AccountDataDictionary cardDetails = new AccountDataDictionary();
                                            cardDetails["AccountName"]     = CardName.Text.Trim();
                                            cardDetails["AccountNumber"]   = CardNumber.Text.Trim();
                                            cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                                            cardDetails["ExpirationYear"]  = ExpirationYear.SelectedItem.Value;
                                            cardDetails["SecurityCode"]    = SecurityCode.Text.Trim();
                                            profile = CreateProfile(cardDetails);
                                        }
                                    }

                                    subscription.PaymentProfile        = profile;
                                    subscription.PaymentProcessingType = PaymentProcessingType.ArbProfileManaged;
                                    subscription.Save();
                                }
                            }
                        }

                        if (profile != null && payment.PaymentProfile == null)
                        {
                            payment.PaymentProfile = profile;
                            payment.Save();
                        }

                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                        Response.Redirect(AbleCommerce.Code.NavigationHelper.GetReceiptUrl(checkoutResponse.Order.OrderNumber));
                    }
                    else
                    {
                        IList <string> warningMessages = checkoutResponse.WarningMessages;
                        if (warningMessages.Count == 0)
                        {
                            warningMessages.Add("The order could not be submitted at this time.  Please try again later or contact us for assistance.");
                        }
                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                    }
                }
            }
        }
コード例 #25
0
        private RecurringRequest InitializeAuthRecurringRequest(AuthorizeRecurringTransactionRequest authRequest, int payPeriod)
        {
            VerifyPaymentInstrument(authRequest.Payment);
            RecurringRequest request = new RecurringRequest();

            Payment payment = authRequest.Payment;
            Order   order   = payment.Order;
            User    user    = payment.Order.User;
            //Address address = user.PrimaryAddress;

            //credit card data
            AccountDataDictionary accountData = new AccountDataDictionary(payment.AccountData);
            string accountNumber   = accountData.GetValue("AccountNumber");
            string expirationMonth = accountData.GetValue("ExpirationMonth");

            if (expirationMonth.Length == 1)
            {
                expirationMonth.Insert(0, "0");
            }
            string expirationYear = accountData.GetValue("ExpirationYear");

            request.setCommand(RecurringRequest.COMMAND_ADD_CUSTOMER_ACCOUNT_AND_RECURRENCE);
            request.setAccountType(RecurringRequest.ACCOUNT_TYPE_CREDIT_CARD);
            request.setCreditCardNumber(accountNumber);
            request.setExpireMonth(expirationMonth);
            request.setExpireYear(expirationYear);

            request.setBillingAddress(order.BillToAddress1 + ", " + order.BillToAddress2 + "," + order.BillToCity);
            request.setZipOrPostalCode(order.BillToPostalCode);
            request.setCountryCode(order.BillToCountryCode);

            LSDecimal amount = authRequest.RecurringChargeSpecified ? authRequest.RecurringCharge : authRequest.Amount;

            request.setChargeTotal((double)amount);

            request.setCustomerId(user.UserId.ToString());
            if (accountData.ContainsKey("AccountName") && !string.IsNullOrEmpty(accountData["AccountName"]))
            {
                request.setCustomerName(accountData["AccountName"]);
            }
            else
            {
                request.setCustomerName(order.BillToFirstName + " " + order.BillToLastName);
            }
            request.setDescription(authRequest.SubscriptionName);

            string strEmail = string.IsNullOrEmpty(order.BillToEmail) ? user.Email : order.BillToEmail;

            request.setEmailAddress(user.Email);

            request.setNotifyCustomer(true);
            request.setNumberOfRetries(3);
            request.setRecurrenceId(authRequest.Payment.OrderId.ToString());
            request.setPeriod(payPeriod);

            DateTime startDt = LocaleHelper.LocalNow;

            if (authRequest.RecurringChargeSpecified)
            {
                startDt = GetNextPaymentDate(payPeriod);
            }
            request.setStartDay(startDt.Day);
            request.setStartMonth(startDt.Month);
            request.setStartYear(startDt.Year);

            DateTime endDt = GetEndDate(startDt, payPeriod, authRequest.NumberOfPayments);

            request.setEndDay(endDt.Day);
            request.setEndMonth(endDt.Month);
            request.setEndYear(endDt.Year);

            return(request);
        }
コード例 #26
0
        protected void CompleteButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                bool checkOut = true;
                if (CheckingOut != null)
                {
                    CheckingOutEventArgs c = new CheckingOutEventArgs();
                    CheckingOut(this, c);
                    checkOut = !c.Cancel;
                }
                if (checkOut)
                {
                    Basket basket = AbleContext.Current.User.Basket;
                    //PROCESS THE CHECKOUT
                    ICheckoutService checkoutService  = AbleContext.Resolve <ICheckoutService>();
                    CheckoutRequest  checkoutRequest  = new CheckoutRequest(basket);
                    CheckoutResponse checkoutResponse = checkoutService.ExecuteCheckout(checkoutRequest);
                    if (checkoutResponse.Success)
                    {
                        GatewayPaymentProfile profile = null;
                        this.Visible = true;

                        if (ProfilesPH.Visible)
                        {
                            profile = GatewayPaymentProfileDataSource.Load(AlwaysConvert.ToInt(ProfilesList.SelectedValue));
                        }

                        if (CardPH.Visible)
                        {
                            AccountDataDictionary cardDetails = new AccountDataDictionary();
                            cardDetails["AccountName"]     = CardName.Text.Trim();
                            cardDetails["AccountNumber"]   = CardNumber.Text.Trim();
                            cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                            cardDetails["ExpirationYear"]  = ExpirationYear.SelectedItem.Value;
                            cardDetails["SecurityCode"]    = SecurityCode.Text.Trim();
                            profile = CreateProfile(cardDetails);
                        }

                        if (profile != null)
                        {
                            IList <Subscription> subscriptions = SubscriptionDataSource.LoadForOrder(checkoutResponse.Order.Id);
                            foreach (Subscription subscription in subscriptions)
                            {
                                if (subscription.PaymentFrequency.HasValue && subscription.PaymentFrequencyUnit.HasValue)
                                {
                                    subscription.PaymentProfile        = profile;
                                    subscription.PaymentProcessingType = PaymentProcessingType.ArbProfileManaged;
                                    subscription.Save();
                                }
                            }
                        }

                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                        Response.Redirect(AbleCommerce.Code.NavigationHelper.GetReceiptUrl(checkoutResponse.Order.OrderNumber));
                    }
                    else
                    {
                        IList <string> warningMessages = checkoutResponse.WarningMessages;
                        if (warningMessages.Count == 0)
                        {
                            warningMessages.Add("The order could not be submitted at this time.  Please try again later or contact us for assistance.");
                        }
                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                    }
                }
            }
        }
コード例 #27
0
        protected void PaymentRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName.StartsWith("Do_"))
            {
                int paymentId = AlwaysConvert.ToInt(e.CommandArgument);
                int index     = _Order.Payments.IndexOf(paymentId);
                if (index > -1)
                {
                    Payment payment = _Order.Payments[index];

                    string whichCommand = e.CommandName.Substring(3);

                    //TAKE ACTION BASED ON COMMAND
                    if (!string.IsNullOrEmpty(whichCommand))
                    {
                        whichCommand = whichCommand.ToUpperInvariant();
                        switch (whichCommand)
                        {
                        case "RETRY":
                            //IF THIS WAS A FAILED CAPTURE, RESET PAYMENT STATUS TO AUTHORIZED AND REDIRECT TO CAPTURE PAGE
                            if (payment.PaymentStatus == PaymentStatus.CaptureFailed)
                            {
                                payment.UpdateStatus(PaymentStatus.Authorized);
                                Response.Redirect("CapturePayment.aspx?PaymentId=" + payment.Id.ToString());
                            }
                            //THIS WAS A FAILED AUTHORIZATION, SHOW THE RETRY PANEL
                            Panel retryPanel = (Panel)AbleCommerce.Code.PageHelper.RecursiveFindControl(e.Item, "RetryPanel");
                            retryPanel.Visible = true;
                            break;

                        case "SUBMITRETRY":
                            TextBox securityCode = (TextBox)AbleCommerce.Code.PageHelper.RecursiveFindControl(e.Item, "RetrySecurityCode");
                            if (!string.IsNullOrEmpty(securityCode.Text))
                            {
                                AccountDataDictionary accountData = new AccountDataDictionary(payment.AccountData);
                                accountData["SecurityCode"] = securityCode.Text;
                                payment.AccountData         = accountData.ToString();
                            }
                            payment.PaymentStatus = CommerceBuilder.Payments.PaymentStatus.Unprocessed;
                            payment.Authorize(false);
                            BindPayments();
                            break;

                        case "CANCELRETRY":
                            //NO ACTION REQUIRED, THE REBIND STEP WILL HIDE THE RETRY PANEL
                            BindPayments();
                            break;

                        case "EDIT":
                            Response.Redirect("EditPayment.aspx?PaymentId=" + payment.Id.ToString());
                            break;

                        case "CAPTURE":
                            //REDIRECT TO CAPTURE FORM
                            Response.Redirect("CapturePayment.aspx?PaymentId=" + payment.Id.ToString());
                            break;

                        case "DELETE":
                            string deleteNote = string.Format("A payment of type {0} and amount {1:c} is deleted.", payment.PaymentMethodName, payment.Amount);
                            _Order.Payments.DeleteAt(index);
                            _Order.Notes.Add(new OrderNote(_Order.Id, AbleContext.Current.UserId, LocaleHelper.LocalNow, deleteNote, NoteType.SystemPrivate));
                            _Order.Notes.Save();
                            BindPayments();
                            break;

                        case "AUTHORIZE":
                            payment.Authorize();
                            BindPayments();
                            break;

                        case "RECEIVED":
                            AbleContext.Current.Database.BeginTransaction();
                            payment.PaymentStatus = PaymentStatus.Completed;
                            payment.Save(true);
                            AbleContext.Current.Database.CommitTransaction();
                            BindPayments();
                            break;

                        case "REFUND":
                            Response.Redirect("RefundPayment.aspx?PaymentId=" + payment.Id.ToString() + "&OrderNumber=" + _Order.OrderNumber);
                            break;

                        case "VOID":
                            Response.Redirect("VoidPayment.aspx?PaymentId=" + payment.Id.ToString() + "&OrderNumber=" + _Order.OrderNumber);
                            break;

                        default:
                            throw new ArgumentException("Unrecognized command: " + whichCommand);
                        }
                    }
                }
            }
        }