Esempio n. 1
0
        public void ProcessTransaction(IAddressInfo billing, OrderInfo orderInfo, TransactionDetails transaction)
        {
            PayPalSettings settings = new PayPalSettings(_gatewaySettings);

            if (transaction.IsValid())
            {
                CultureInfo ciEnUs = new CultureInfo("en-US");
                _paymentURL = settings.UseSandbox ? SandboxPaymentURL : settings.PaymentURL;
                RemoteForm paypal = new RemoteForm("paypalform", _paymentURL);
                // Main fields
                paypal.Fields.Add("cmd", "_cart");
                paypal.Fields.Add("upload", "1");
                paypal.Fields.Add("business", settings.PayPalID.ToLower());
                paypal.Fields.Add("charset", settings.Charset);
                paypal.Fields.Add("currency_code", settings.Currency);
                paypal.Fields.Add("invoice", orderInfo.OrderID.ToString());
                paypal.Fields.Add("return", transaction.ReturnURL);
                paypal.Fields.Add("cancel_return", transaction.CancelURL);
                paypal.Fields.Add("notify_url", transaction.NotifyURL);
                paypal.Fields.Add("rm", "2");
                paypal.Fields.Add("lc", settings.Lc);
                paypal.Fields.Add("cbt", transaction.Cbt);
                paypal.Fields.Add("custom", orderInfo.CustomerID.ToString());
                paypal.Fields.Add("email", transaction.Email);
                paypal.Fields.Add("first_name", billing.FirstName);
                paypal.Fields.Add("last_name", billing.LastName);
                if (!string.IsNullOrEmpty(billing.Address1))
                {
                    paypal.Fields.Add("address1", billing.Address1);
                }
                if (!string.IsNullOrEmpty(billing.Address2))
                {
                    paypal.Fields.Add("address2", billing.Address2);
                }
                if (!string.IsNullOrEmpty(billing.City))
                {
                    paypal.Fields.Add("city", billing.City);
                }
                if (!string.IsNullOrEmpty(billing.PostalCode))
                {
                    paypal.Fields.Add("zip", billing.PostalCode);
                }
                // Get ISO country code for specified country name
                string country = GetISOCountryCode(billing.CountryCode);
                if (!string.IsNullOrEmpty(country))
                {
                    paypal.Fields.Add("country", country);
                }
                if (!string.IsNullOrEmpty(billing.Phone1))
                {
                    // Remove all chars but numbers from phone number
                    string phonenumber = Regex.Replace(billing.Phone1, "[^\\d]", "", RegexOptions.Compiled);
                    // If the buyer live in the USA
                    if (country == "US")
                    {
                        // Get US postal code for specified region code and add it to the form
                        paypal.Fields.Add("state", GetUSPostalRegionCode(country, billing.RegionCode));
                        // If the phone number is valid
                        int phoneLength = phonenumber.Length;
                        if (phoneLength > 7)
                        {
                            // Extract area code, three digits prefix and four digits phone number
                            paypal.Fields.Add("night_phone_a", phonenumber.Substring(0, phoneLength - 7));
                            paypal.Fields.Add("night_phone_b", phonenumber.Substring(phoneLength - 7, 3));
                            paypal.Fields.Add("night_phone_c", phonenumber.Substring(phoneLength - 4));
                        }
                    }
                    else
                    {
                        // For International buyers, set country code and phone number
                        //paypal.Fields.Add("night_phone_a", country); HERE PHONE country code is required!
                        paypal.Fields.Add("night_phone_b", phonenumber);
                    }
                }
                // Order details
                OrderController        orderController = new OrderController();
                List <OrderDetailInfo> orderDetails    = orderController.GetOrderDetails(orderInfo.OrderID);
                int itemNumber = 1;
                foreach (OrderDetailInfo detail in orderDetails)
                {
                    paypal.Fields.Add("item_number_" + itemNumber, detail.ProductID.ToString());
                    paypal.Fields.Add("item_name_" + itemNumber, detail.ProductTitle);
                    paypal.Fields.Add("quantity_" + itemNumber, detail.Quantity.ToString());
                    paypal.Fields.Add("amount_" + itemNumber, detail.UnitCost.ToString("0.00", ciEnUs));
                    itemNumber++;
                }
                // If a valid coupon exists
                if (orderInfo.CouponID != Null.NullInteger)
                {
                    decimal discount = Math.Abs(orderInfo.Discount);
                    paypal.Fields.Add("discount_amount_cart", discount.ToString("0.00", ciEnUs));
                }
                // Shipping
                if (orderInfo.ShippingCost > 0)
                {
                    paypal.Fields.Add("handling_cart", orderInfo.ShippingCost.ToString("0.00", ciEnUs));
                }
                // Tax
                if (orderInfo.TaxTotal > 0)
                {
                    paypal.Fields.Add("tax_cart", orderInfo.TaxTotal.ToString("0.00", ciEnUs));
                }
                // Post the form to the client browser then submit it to PayPal using JavaScript
                paypal.Post();
            }
        }
Esempio n. 2
0
        protected void btnProcess_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (!Page.IsValid)
            {
                return;
            }

            PortalSecurity security = new PortalSecurity();

            TransactionDetails transaction = new TransactionDetails
            {
                CardNumber       = security.InputFilter(txtNumber.Text, PortalSecurity.FilterFlag.NoMarkup),
                VerificationCode = security.InputFilter(txtVer.Text, PortalSecurity.FilterFlag.NoMarkup),
                ExpirationMonth  = int.Parse(ddlMonth.SelectedValue),
                ExpirationYear   = int.Parse(ddlYear.SelectedValue)
            };

            if (transaction.IsValid())
            {
                IAddressInfo shippingAddress = CheckoutControl.ShippingAddress;
                IAddressInfo billingAddress  = CheckoutControl.BillingAddress;
                //Adds order to db...
                OrderInfo order = CheckoutControl.GetFinalizedOrderInfo();

                GenerateOrderConfirmation();

                //Process transaction
                AuthNetGatewayProvider provider    = new AuthNetGatewayProvider(StoreSettings.GatewaySettings);
                TransactionResult      orderResult = provider.ProcessTransaction(shippingAddress, billingAddress, order, transaction);
                if (!orderResult.Succeeded)
                {
                    string errorMessage    = string.Empty;
                    string localizedReason = string.Empty;
                    // Try to get the corresponding localized reason message
                    localizedReason = Localization.GetString("ReasonCode" + orderResult.ReasonCode, LocalResourceFile);
                    // If a localized message do not exist use the original message
                    if (localizedReason == string.Empty | localizedReason == null)
                    {
                        localizedReason = orderResult.Message.ToString();
                    }
                    switch (orderResult.ResultCode)
                    {
                    case -5:
                        errorMessage = Localization.GetString("ErrorCardInformation", LocalResourceFile);
                        break;

                    case -4:
                        errorMessage = Localization.GetString("ErrorBillingAddress", LocalResourceFile);
                        break;

                    case -3:
                        errorMessage = Localization.GetString("ErrorPaymentOption", LocalResourceFile);
                        break;

                    case -2:
                        errorMessage = Localization.GetString("ErrorConnection", LocalResourceFile);
                        break;

                    case -1:
                        errorMessage = Localization.GetString("ErrorUnexpected", LocalResourceFile);
                        break;

                    case 2:
                        errorMessage          = string.Format(Localization.GetString("ReasonMessage", LocalResourceFile), Localization.GetString("ResponseCode2", LocalResourceFile), orderResult.ReasonCode, "");
                        CheckoutControl.Order = UpdateOrderStatus(order, OrderInfo.OrderStatusList.AwaitingPayment);
                        CheckoutControl.Hide();
                        pnlProceedToAuthorize.Visible = false;
                        InvokePaymentFailed();
                        CurrentCart.DeleteCart(PortalId, StoreSettings.SecureCookie);
                        ClearOrderIdCookie();
                        break;

                    case 3:
                        errorMessage = string.Format(Localization.GetString("ReasonMessage", LocalResourceFile), Localization.GetString("ResponseCode3", LocalResourceFile), orderResult.ReasonCode, localizedReason);
                        break;

                    case 4:
                        errorMessage          = string.Format(Localization.GetString("ReasonMessage", LocalResourceFile), Localization.GetString("ResponseCode4", LocalResourceFile), orderResult.ReasonCode, localizedReason);
                        CheckoutControl.Order = UpdateOrderStatus(order, OrderInfo.OrderStatusList.AwaitingPayment);
                        CheckoutControl.Hide();
                        pnlProceedToAuthorize.Visible = false;
                        InvokePaymentRequiresConfirmation();
                        CurrentCart.DeleteCart(PortalId, StoreSettings.SecureCookie);
                        ClearOrderIdCookie();
                        break;

                    default:
                        errorMessage = string.Format(Localization.GetString("ReasonMessage", LocalResourceFile), Localization.GetString("ErrorUnexpected", LocalResourceFile), orderResult.ReasonCode, localizedReason);
                        break;
                    }
                    lblError.Visible = true;
                    lblError.Text    = errorMessage;
                }
                else
                {
                    int portalId = PortalSettings.PortalId;
                    // Set order status to "Paid"...
                    CheckoutControl.Order = UpdateOrderStatus(order, OrderInfo.OrderStatusList.Paid);
                    // Add User to Product Roles
                    OrderController orderController = new OrderController();
                    orderController.AddUserToRoles(PortalId, order);
                    // Add User to Order Role
                    StoreInfo storeSetting = StoreController.GetStoreInfo(PortalSettings.PortalId);
                    if (storeSetting.OnOrderPaidRoleID != Null.NullInteger)
                    {
                        orderController.AddUserToPaidOrderRole(portalId, order.CustomerID, storeSetting.OnOrderPaidRoleID);
                    }
                    CheckoutControl.Hide();
                    pnlProceedToAuthorize.Visible = false;
                    lblError.Visible = false;
                    InvokePaymentSucceeded();
                    CurrentCart.DeleteCart(PortalId, StoreSettings.SecureCookie);
                    ClearOrderIdCookie();
                }
            }
            else
            {
                lblError.Visible = true;
                lblError.Text    = Localization.GetString("ErrorCardNotValid", LocalResourceFile);
            }
            btnProcess.Enabled = true;
        }
Esempio n. 3
0
        public void ProcessTransaction(IAddressInfo billing, OrderInfo orderInfo, TransactionDetails transaction)
        {
            if (transaction.IsValid())
            {
                SystempaySettings settings  = new SystempaySettings(_gatewaySettings);
                RemoteForm        systempay = new RemoteForm("systempayform", settings.PaymentURL);
                // Main fields
                systempay.Fields.Add("vads_version", "V2");
                systempay.Fields.Add("vads_site_id", settings.SiteID);
                systempay.Fields.Add("vads_ctx_mode", settings.UseTestCertificate ? "TEST" : "PRODUCTION");
                if (!string.IsNullOrEmpty(settings.Contracts))
                {
                    systempay.Fields.Add("vads_contracts", settings.Contracts);
                }
                systempay.Fields.Add("vads_page_action", "PAYMENT");
                systempay.Fields.Add("vads_action_mode", "INTERACTIVE");
                systempay.Fields.Add("vads_payment_config", "SINGLE");
                systempay.Fields.Add("vads_capture_delay", "0");
                //systempay.Fields.Add("vads_validation_mode", "0");
                systempay.Fields.Add("vads_trans_id", GetTransactionID());
                systempay.Fields.Add("vads_trans_date", GetTransactionDate());
                systempay.Fields.Add("vads_currency", settings.Currency);
                systempay.Fields.Add("vads_language", settings.Language);
                systempay.Fields.Add("vads_return_mode", "POST");
                systempay.Fields.Add("vads_url_return", transaction.ReturnURL);
                systempay.Fields.Add("vads_url_refused", transaction.RefusedURL);
                systempay.Fields.Add("vads_url_error", transaction.ErrorURL);
                systempay.Fields.Add("vads_url_cancel", transaction.CancelURL);
                systempay.Fields.Add("vads_url_check", transaction.NotifyURL);
                systempay.Fields.Add("vads_shop_name", transaction.ShopName);
                systempay.Fields.Add("vads_theme_config", transaction.Buttons);

                // Customer fields
                systempay.Fields.Add("vads_cust_id", orderInfo.CustomerID.ToString());
                systempay.Fields.Add("vads_cust_first_name", billing.FirstName);
                systempay.Fields.Add("vads_cust_last_name", billing.LastName);
                string address = (billing.Address1 + " " + billing.Address2).Trim();
                if (!string.IsNullOrEmpty(address))
                {
                    systempay.Fields.Add("vads_cust_address", address);
                }
                if (!string.IsNullOrEmpty(billing.PostalCode))
                {
                    systempay.Fields.Add("vads_cust_zip", billing.PostalCode);
                }
                if (!string.IsNullOrEmpty(billing.City))
                {
                    systempay.Fields.Add("vads_cust_city", billing.City);
                }
                // Get ISO country code for specified country name
                string country = GetISOCountryCode(billing.CountryCode);
                if (!string.IsNullOrEmpty(country))
                {
                    systempay.Fields.Add("vads_cust_country", country);
                }
                if (!string.IsNullOrEmpty(billing.Phone1))
                {
                    systempay.Fields.Add("vads_cust_phone", billing.Phone1);
                }
                if (!string.IsNullOrEmpty(billing.Phone2))
                {
                    systempay.Fields.Add("vads_cust_cell_phone", billing.Phone2);
                }
                systempay.Fields.Add("vads_cust_email", transaction.Email);

                // Order fields
                systempay.Fields.Add("vads_order_id", orderInfo.OrderID.ToString());
                // Order details
                OrderController        orderController = new OrderController();
                List <OrderDetailInfo> orderDetails    = orderController.GetOrderDetails(orderInfo.OrderID);
                int itemNumber = 0;
                foreach (OrderDetailInfo detail in orderDetails)
                {
                    string prodRef = !string.IsNullOrEmpty(detail.ModelNumber) ? detail.ModelNumber : detail.ProductID.ToString();
                    systempay.Fields.Add("vads_product_ref" + itemNumber, prodRef);
                    systempay.Fields.Add("vads_product_label" + itemNumber, detail.ModelName);
                    systempay.Fields.Add("vads_product_qty" + itemNumber, detail.Quantity.ToString());
                    systempay.Fields.Add("vads_product_amount" + itemNumber, FormatAmount(detail.UnitCost));
                    itemNumber++;
                }
                systempay.Fields.Add("vads_nb_products", orderDetails.Count.ToString());
                systempay.Fields.Add("vads_amount", FormatAmount(orderInfo.GrandTotal));

                // Shipping
                if (orderInfo.ShippingCost > 0)
                {
                    systempay.Fields.Add("vads_shipping_amount", FormatAmount(orderInfo.ShippingCost));
                }
                // Tax
                if (orderInfo.TaxTotal > 0)
                {
                    systempay.Fields.Add("vads_tax_amount", FormatAmount(orderInfo.TaxTotal));
                }

                // Add computed signature
                systempay.Fields.Add("signature", GetSignature(systempay.Fields, settings.Certificate));
                // Post the form to the client browser then submit it to Systempay using JavaScript
                systempay.Post(true);
            }
        }
Esempio n. 4
0
        private void ConfirmOrder()
        {
            Page.Validate();
            if (Page.IsValid == false)
            {
                return;
            }

            // Adds order to db...
            OrderInfo    order          = CheckoutControl.GetFinalizedOrderInfo();
            IAddressInfo billingAddress = CheckoutControl.BillingAddress;

            GenerateOrderConfirmation();

            CheckoutControl.Hide();
            pnlProceedToSystempay.Visible = false;

            // Set order status to "Awaiting Payment"...
            CheckoutControl.Order = UpdateOrderStatus(order, OrderInfo.OrderStatusList.AwaitingPayment);

            // Clear basket
            CurrentCart.DeleteCart(PortalId, StoreSettings.SecureCookie);

            // Clear cookies
            ClearOrderIdCookie();

            // Process transaction
            string              urlAuthority = Request.Url.GetLeftPart(UriPartial.Authority);
            TransactionDetails  transaction  = new TransactionDetails();
            SystempayNavigation nav          = new SystempayNavigation(Request.QueryString)
            {
                OrderID = order.OrderID,
                // Return URL
                GatewayExit = "return"
            };

            transaction.ReturnURL = AddAuthority(nav.GetNavigationUrl(), urlAuthority);
            // Refused URL
            nav.GatewayExit        = "refused";
            transaction.RefusedURL = AddAuthority(nav.GetNavigationUrl(), urlAuthority);
            // Error URL
            nav.GatewayExit      = "error";
            transaction.ErrorURL = AddAuthority(nav.GetNavigationUrl(), urlAuthority);
            // Cancel URL
            nav.GatewayExit       = "cancel";
            transaction.CancelURL = AddAuthority(nav.GetNavigationUrl(), urlAuthority);
            // IPN URL
            string language = Request.QueryString["language"];

            if (string.IsNullOrEmpty(language))
            {
                language = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
            }
            transaction.NotifyURL = urlAuthority + TemplateSourceDirectory + "/SystempayIPN.aspx?language=" + language;
            string messages = Localization.GetString("SystempayButtons", LocalResourceFile);

            transaction.Buttons  = string.Format(messages, StoreSettings.Name);
            transaction.ShopName = StoreSettings.Name;
            transaction.Email    = billingAddress.Email;

            SystempayGatewayProvider provider = new SystempayGatewayProvider(StoreSettings.GatewaySettings);

            provider.ProcessTransaction(CheckoutControl.BillingAddress, order, transaction);
        }
Esempio n. 5
0
        public TransactionResult ProcessTransaction(IAddressInfo shipping, IAddressInfo billing, OrderInfo orderInfo, TransactionDetails trans)
        {
            TransactionResult result = new TransactionResult();

            CultureInfo ciEnUs = new CultureInfo("en-US");

            // Check data before performing transaction
            AuthNetSettings settings = new AuthNetSettings(_gatewaySettings);

            if (!settings.IsValid())
            {
                result.Succeeded  = false;
                result.ResultCode = -3;

                return(result);
            }

            if (billing == null)
            {
                result.Succeeded  = false;
                result.ResultCode = -4;

                return(result);
            }

            if (trans == null || !trans.IsValid())
            {
                result.Succeeded  = false;
                result.ResultCode = -5;

                return(result);
            }

            // Gather transaction information
            string url = settings.GatewayURL;
            NameValueCollection NVCol = new NameValueCollection
            {
                // Merchant infos
                { "x_login", settings.Username },    //Req
                { "x_tran_key", settings.Password }, //Req
                { "x_version", settings.Version },   //Req
                { "x_test_request", settings.IsTest.ToString().ToUpper() },
                // Init infos
                { "x_delim_data", "TRUE" },
                { "x_delim_char", "|" },
                { "x_encap_char", "" },
                { "x_relay_response", "FALSE" }, //Req
                                                 //New in Store 3.1.10, added by Authorize in February 2014
                { "x_market_type", "0" },        // 0=eCommerce, 1 MOTO, 2 Retail
                                                 // Billing infos
                { "x_first_name", billing.FirstName },
                { "x_last_name", billing.LastName },
                { "x_company", "" },
                { "x_address", (billing.Address1 + " " + billing.Address2).Trim() },
                { "x_city", billing.City },
                { "x_state", billing.RegionCode },
                { "x_zip", billing.PostalCode },
                { "x_country", billing.CountryCode },
                { "x_phone", billing.Phone1 },
                // Shipping infos
                { "x_ship_to_first_name", shipping.FirstName },
                { "x_ship_to_last_name", shipping.LastName },
                { "x_ship_to_company", "" },
                { "x_ship_to_address", (shipping.Address1 + " " + shipping.Address2).Trim() },
                { "x_ship_to_city", shipping.City },
                { "x_ship_to_state", shipping.RegionCode },
                { "x_ship_to_zip", shipping.PostalCode },
                { "x_ship_to_country", shipping.CountryCode },
                // Customer infos
                { "x_cust_id", billing.UserID.ToString() },
                { "x_customer_ip", HttpContext.Current.Request.UserHostAddress },
                // Order infos
                { "x_invoice_num", orderInfo.OrderID.ToString() },
                { "x_amount", orderInfo.GrandTotal.ToString("0.00", ciEnUs) },//Req
                { "x_tax", orderInfo.TaxTotal.ToString("0.00", ciEnUs) },
                { "x_freight", orderInfo.ShippingCost.ToString("0.00", ciEnUs) },
                // Transaction infos
                { "x_method", "CC" },                      //CC=Credit Card could be also ECHECK
                { "x_type", settings.Capture.ToString() }, //Req
                { "x_recurring_billing", "NO" },
                { "x_card_num", trans.CardNumber },        //Req
                { "x_card_code", trans.VerificationCode },
                { "x_exp_date", trans.ExpirationMonth.ToString("00") + "/" + trans.ExpirationYear }//Req
            };
            // Order details
            string                 fieldSep        = "<|>";
            OrderController        orderController = new OrderController();
            List <OrderDetailInfo> orderDetails    = orderController.GetOrderDetails(orderInfo.OrderID);
            ArrayList              items           = new ArrayList(orderDetails.Count);

            foreach (OrderDetailInfo detail in orderDetails)
            {
                string modelNumber = detail.ModelNumber;
                if (modelNumber.Length > 31)
                {
                    modelNumber = modelNumber.Substring(0, 31);
                }

                string modelName = detail.ModelName;
                if (modelName.Length > 31)
                {
                    modelName = modelName.Substring(0, 31);
                }

                items.Add(modelNumber + fieldSep + modelName + fieldSep + fieldSep + detail.Quantity +
                          fieldSep + detail.UnitCost.ToString("0.00", ciEnUs) + fieldSep + "Y");
            }
            // Perform transaction
            try
            {
                Encoding     enc = Encoding.GetEncoding(1252);
                StreamReader loResponseStream = new StreamReader(PostEx(url, NVCol, items).GetResponseStream(), enc);

                string lcHtml = loResponseStream.ReadToEnd();
                loResponseStream.Close();

                string[] resultArray = lcHtml.Split('|');

                result.Succeeded  = (resultArray[0] == "1");
                result.ResultCode = int.Parse(resultArray[0]);
                result.ReasonCode = int.Parse(resultArray[2]);
                result.Message    = resultArray[3];
            }
            catch (Exception ex)
            {
                result.Succeeded  = false;
                result.ResultCode = -2;
                result.Message    = ex.Message;
            }

            return(result);
        }