public void Initialize()
    {
        //btnContCheckout.Visible = false;
        string returnUrl = string.Format("{0}fp-paypalembeddedcheckoutok.aspx", AppLogic.GetStoreHTTPLocation(true));
        string errorUrl = string.Format("{0}fp-paypalembeddedcheckoutok.aspx", AppLogic.GetStoreHTTPLocation(true));
        string cancelUrl = string.Format("{0}fp-shoppingcart.aspx", AppLogic.GetStoreHTTPLocation(true));
        string notifyUrl = string.Format("{0}paypalnotification.aspx", AppLogic.GetStoreHTTPLocation(true));
        string silentPostURL = string.Format("{0}paypalembeddedcheckoutok.aspx", AppLogic.GetStoreHTTPLocation(true));
        PayPalEmbeddedCheckoutSecureTokenResponse response = PayFlowProController.GetFramedHostedCheckout(returnUrl, errorUrl, cancelUrl, notifyUrl, silentPostURL);

        if (response.Result != 0)
            throw new Exception("PayPal Embedded Checkout is not configured properly.");

        Session["PayPalEmbeddedCheckoutSecureToken"] = response.SecureToken;
        Session["PayPalEmbeddedCheckoutSecureTokenId"] = response.SecureTokenID;

        if (CommonLogic.QueryStringNativeInt("ErrorMsg") > 0)
        {
            ErrorMessage e = new ErrorMessage(CommonLogic.QueryStringNativeInt("ErrorMsg"));
            ShowError(e.Message);
        }

        string frameSrc = response.GetFrameSrc(0, 400);
        litPayPalEmbeddedCheckoutFrame.Text = frameSrc;
    }
コード例 #2
0
    public override void Initialize()
    {
        string returnUrl     = string.Format("{0}fp-paypalembeddedcheckoutok.aspx", AppLogic.GetStoreHTTPLocation(true));
        string errorUrl      = string.Format("{0}fp-paypalembeddedcheckoutok.aspx", AppLogic.GetStoreHTTPLocation(true));
        string cancelUrl     = string.Format("{0}fp-shoppingcart.aspx", AppLogic.GetStoreHTTPLocation(true));
        string notifyUrl     = string.Format("{0}paypalnotification.aspx", AppLogic.GetStoreHTTPLocation(true));
        string silentPostURL = string.Format("{0}paypalembeddedcheckoutok.aspx", AppLogic.GetStoreHTTPLocation(true));
        PayPalEmbeddedCheckoutSecureTokenResponse response = PayFlowProController.GetFramedHostedCheckout(returnUrl, errorUrl, cancelUrl, notifyUrl, silentPostURL);

        if (response.Result != 0)
        {
            throw new Exception(AppLogic.GetString("paypalpaymentsadvanced.configerror", ((AspDotNetStorefrontPrincipal)Context.User).ThisCustomer.LocaleSetting));
        }

        Session["PayPalEmbeddedCheckoutSecureToken"]   = response.SecureToken;
        Session["PayPalEmbeddedCheckoutSecureTokenId"] = response.SecureTokenID;

        if (CommonLogic.QueryStringNativeInt("ErrorMsg") > 0)
        {
            ErrorMessage e = new ErrorMessage(CommonLogic.QueryStringNativeInt("ErrorMsg"));
            ShowError(e.Message);
        }

        string frameSrc = response.GetFrameSrc(0, 400);

        litPayPalEmbeddedCheckoutFrame.Text = frameSrc;
    }
コード例 #3
0
        public ActionResult PlaceOrder(CheckoutIndexPostModel model)
        {
            // Get the current checkout state
            var customer = HttpContext.GetCustomer();
            var storeId  = AppLogic.StoreID();

            var checkoutConfiguration = CheckoutConfigurationProvider.GetCheckoutConfiguration();

            var selectedPaymentMethod = PaymentMethodInfoProvider
                                        .GetPaymentMethodInfo(
                paymentMethod: customer.RequestedPaymentMethod,
                gateway: AppLogic.ActivePaymentGatewayCleaned());

            // update checkboxes
            UpdateOver13(model.Over13Selected, customer);
            UpdateOkToEmail(model.OkToEmailSelected, customer);
            UpdateTermsAndConditions(model.TermsAndConditionsAccepted, customer);

            var persistedCheckoutContext = PersistedCheckoutContextProvider
                                           .LoadCheckoutContext(customer);

            UpdateCustomerEmail(persistedCheckoutContext.Email, customer);

            var cartContext = CartContextProvider
                              .LoadCartContext(
                customer: customer,
                configuration: checkoutConfiguration,
                persistedCheckoutContext: persistedCheckoutContext,
                selectedPaymentMethod: selectedPaymentMethod);

            var checkoutSelectionContext = CheckoutSelectionProvider
                                           .GetCheckoutSelection(
                customer: customer,
                persistedCheckoutContext: persistedCheckoutContext,
                selectedPaymentMethod: selectedPaymentMethod);

            var result = CheckoutEngine
                         .EvaluateCheckout(
                customer: customer,
                configuration: checkoutConfiguration,
                persistedCheckoutContext: persistedCheckoutContext,
                checkoutSelectionContext: checkoutSelectionContext,
                storeId: storeId,
                cartContext: cartContext);

            var action = GetActionForState(result.State);

            var checkoutEngineUpdates = CheckoutSelectionProvider.ApplyCheckoutSelections(customer, result.Selections);

            customer = checkoutEngineUpdates.Customer;
            persistedCheckoutContext = checkoutEngineUpdates.PersistedCheckoutContext;
            selectedPaymentMethod    = checkoutEngineUpdates.SelectedPaymentMethod;

            if (action != CheckoutAction.Complete)
            {
                NoticeProvider.PushNotice("Please complete the required areas below before you place your order", NoticeType.Failure);
            }

            // Only place the order if checkout is complete.
            if (action != CheckoutAction.Complete)
            {
                return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout, new RouteValueDictionary {
                    { RouteDataKeys.ShowErrors, true }
                }));
            }

            var billingAddress = new Address();

            billingAddress.LoadByCustomer(customer.CustomerID, customer.PrimaryBillingAddressID, AddressTypes.Billing);

            //Save customer context to the 'permanent' places it needs to go
            SaveCustomerContextToDB(selectedPaymentMethod, persistedCheckoutContext, customer, billingAddress);

            //Reload the customer so it's got the new CustomerSession values
            customer = new Customer(customer.CustomerID);
            var cart = CachedShoppingCartProvider.Get(customer, CartTypeEnum.ShoppingCart, AppLogic.StoreID());

            var orderNumber   = 0;
            var gatewayToUse  = AppLogic.ActivePaymentGatewayCleaned();
            var paymentMethod = selectedPaymentMethod == null
                                ? null
                                : selectedPaymentMethod.Name;
            var giftCardOrder = cart.GiftCardCoversTotal();

            if (selectedPaymentMethod == null)
            {
                orderNumber = AppLogic.GetNextOrderNumber();
                var status = Gateway.MakeOrder(string.Empty, AppLogic.TransactionMode(), cart, orderNumber, string.Empty, string.Empty, string.Empty, string.Empty);

                if (status != AppLogic.ro_OK)
                {
                    NoticeProvider.PushNotice(status, NoticeType.Failure);
                    return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
                }
            }
            else if (paymentMethod == AppLogic.ro_PMCreditCard)
            {
                //2checkout has own 3dsecure
                if (gatewayToUse == Gateway.ro_GWTWOCHECKOUT)
                {
                    return(RedirectToAction(ActionNames.TwoCheckout, ControllerNames.TwoCheckout));
                }

                //Set up some special info for Braintree
                if (gatewayToUse == Gateway.ro_GWBRAINTREE && !giftCardOrder)
                {
                    customer.ThisCustomerSession[AppLogic.Braintree3dSecureKey]   = persistedCheckoutContext.Braintree.ThreeDSecureApproved.ToString();
                    customer.ThisCustomerSession[AppLogic.BraintreeNonceKey]      = persistedCheckoutContext.Braintree.Nonce.ToString();
                    customer.ThisCustomerSession[AppLogic.BraintreePaymentMethod] = persistedCheckoutContext.Braintree.PaymentMethod;
                }

                var status = string.Empty;
                orderNumber = AppLogic.GetNextOrderNumber();

                if (Cardinal.EnabledForCheckout(cart.Total(true), billingAddress.CardType) &&
                    gatewayToUse != Gateway.ro_GWBRAINTREE)                         //Braintree has its own native 3dSecure support
                {
                    if (Cardinal.PreChargeLookupAndStoreSession(
                            customer,
                            orderNumber,
                            cart.Total(true),
                            billingAddress.CardNumber,
                            billingAddress.CardExpirationMonth,
                            billingAddress.CardExpirationYear) &&
                        gatewayToUse != Gateway.ro_GWBRAINTREE)
                    {
                        return(RedirectToAction(ActionNames.ThreeDSecure, ControllerNames.ThreeDSecure));
                    }
                    else
                    {
                        // user not enrolled or cardinal gateway returned error, so process card normally, using already created order #:
                        var eciFlag = Cardinal.GetECIFlag(billingAddress.CardType);
                        status = Gateway.MakeOrder(string.Empty, AppLogic.TransactionMode(), cart, orderNumber, string.Empty, eciFlag, string.Empty, string.Empty);

                        CleanupPaymentMethod(new AppliedPaymentMethodCleanupContext(
                                                 customer: customer,
                                                 orderNumber: orderNumber,
                                                 status: status,
                                                 paymentMethod: paymentMethod));

                        if (status != AppLogic.ro_OK)
                        {
                            NoticeProvider.PushNotice(status, NoticeType.Failure);
                            return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
                        }
                        DB.ExecuteSQL("update orders set CardinalLookupResult=" + DB.SQuote(customer.ThisCustomerSession["Cardinal.LookupResult"]) + " where OrderNumber=" + orderNumber.ToString());
                    }
                }
                else
                {
                    status = Gateway.MakeOrder(string.Empty, AppLogic.TransactionMode(), cart, orderNumber, string.Empty, string.Empty, string.Empty, string.Empty);

                    CleanupPaymentMethod(new AppliedPaymentMethodCleanupContext(
                                             customer: customer,
                                             orderNumber: orderNumber,
                                             status: status,
                                             paymentMethod: paymentMethod,
                                             gateway: gatewayToUse));

                    if (status == AppLogic.ro_3DSecure)
                    {                     // If credit card is enrolled in a 3D Secure service (Verified by Visa, etc.)
                        return(RedirectToAction(ActionNames.ThreeDSecure, ControllerNames.ThreeDSecure));
                    }
                    if (status != AppLogic.ro_OK)
                    {
                        NoticeProvider.PushNotice(status, NoticeType.Failure);
                        return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
                    }
                }
            }
            else if (paymentMethod == AppLogic.ro_PMPayPalExpress ||
                     paymentMethod == AppLogic.ro_PMPayPalExpressMark)
            {
                if (persistedCheckoutContext.PayPalExpress == null || string.IsNullOrEmpty(persistedCheckoutContext.PayPalExpress.Token))
                {
                    NoticeProvider.PushNotice("The PaypalExpress checkout token has expired, please re-login to your PayPal account or checkout using a different method of payment.", NoticeType.Failure);
                    return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
                }

                orderNumber = AppLogic.GetNextOrderNumber();

                var effectiveBillingAddress = new Address();
                effectiveBillingAddress.LoadByCustomer(customer.CustomerID, customer.PrimaryBillingAddressID, AddressTypes.Billing);
                effectiveBillingAddress.PaymentMethodLastUsed = paymentMethod;
                effectiveBillingAddress.CardNumber            = string.Empty;
                effectiveBillingAddress.CardType            = string.Empty;
                effectiveBillingAddress.CardExpirationMonth = string.Empty;
                effectiveBillingAddress.CardExpirationYear  = string.Empty;
                effectiveBillingAddress.CardName            = string.Empty;
                effectiveBillingAddress.CardStartDate       = string.Empty;
                effectiveBillingAddress.CardIssueNumber     = string.Empty;
                effectiveBillingAddress.UpdateDB();

                var transactionContext = new Dictionary <string, string>
                {
                    { "TENDER", "P" }
                };

                gatewayToUse = PayPalController.GetAppropriateExpressType() == ExpressAPIType.PayFlowPro
                                        ? Gateway.ro_GWPAYFLOWPRO
                                        : string.Empty;

                var status = Gateway.MakeOrder(
                    gatewayToUse,
                    AppLogic.TransactionMode(),
                    cart,
                    orderNumber,
                    persistedCheckoutContext.PayPalExpress.Token,
                    persistedCheckoutContext.PayPalExpress.PayerId,
                    persistedCheckoutContext.PayPalExpress.Token,
                    string.Empty,
                    transactionContext);

                CleanupPaymentMethod(new AppliedPaymentMethodCleanupContext(
                                         customer: customer,
                                         orderNumber: orderNumber,
                                         status: status,
                                         paymentMethod: selectedPaymentMethod.Name,
                                         gateway: gatewayToUse));

                if (status != AppLogic.ro_OK)
                {
                    NoticeProvider.PushNotice(status, NoticeType.Failure);
                    return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
                }
            }
            else if (paymentMethod == AppLogic.ro_PMPayPalEmbeddedCheckout)
            {
                var returnUrl = Url.Action(
                    actionName: ActionNames.Ok,
                    controllerName: ControllerNames.PayPalPaymentsAdvanced,
                    routeValues: null,
                    protocol: Uri.UriSchemeHttps);

                var errorUrl = Url.Action(
                    actionName: ActionNames.Error,
                    controllerName: ControllerNames.PayPalPaymentsAdvanced,
                    routeValues: null,
                    protocol: Uri.UriSchemeHttps);

                var cancelUrl = Url.Action(
                    actionName: ActionNames.Index,
                    controllerName: ControllerNames.Checkout,
                    routeValues: null,
                    protocol: Uri.UriSchemeHttps);

                var notifyUrl = Url.Action(
                    actionName: ActionNames.Index,
                    controllerName: ControllerNames.PayPalNotifications,
                    routeValues: null,
                    protocol: Uri.UriSchemeHttps);

                var silentPostUrl = Url.Action(
                    actionName: ActionNames.Ok,
                    controllerName: ControllerNames.PayPalPaymentsAdvanced,
                    routeValues: null,
                    protocol: Uri.UriSchemeHttps);

                var shippingAddress = customer.PrimaryShippingAddress ?? new Address();

                var response = PayFlowProController.GetFramedHostedCheckout(
                    cart: cart,
                    ShippingAddress: shippingAddress,
                    returnUrl: returnUrl,
                    errorUrl: errorUrl,
                    cancelUrl: cancelUrl,
                    notifyUrl: notifyUrl,
                    silentPostUrl: silentPostUrl);

                if (response.Result != 0)
                {
                    throw new Exception("PayPal Payments Advanced is not configured properly.");
                }

                Session["PayPalEmbeddedCheckoutSecureToken"]   = response.SecureToken;
                Session["PayPalEmbeddedCheckoutSecureTokenId"] = response.SecureTokenID;

                var redirectUrl = response.GetRedirectUrl();
                return(Redirect(redirectUrl));
            }
            else if (paymentMethod == AppLogic.ro_PMAmazonPayments ||
                     paymentMethod == AppLogic.ro_PMPurchaseOrder ||
                     paymentMethod == AppLogic.ro_PMRequestQuote ||
                     paymentMethod == AppLogic.ro_PMCheckByMail ||
                     paymentMethod == AppLogic.ro_PMCOD ||
                     paymentMethod == AppLogic.ro_PMMicropay)
            {
                orderNumber = AppLogic.GetNextOrderNumber();
                var status = Gateway.MakeOrder(string.Empty, AppLogic.TransactionMode(), cart, orderNumber, string.Empty, string.Empty, string.Empty, string.Empty);

                CleanupPaymentMethod(new AppliedPaymentMethodCleanupContext(
                                         customer: customer,
                                         orderNumber: orderNumber,
                                         status: status,
                                         paymentMethod: selectedPaymentMethod.Name));

                if (status != AppLogic.ro_OK)
                {
                    NoticeProvider.PushNotice(status, NoticeType.Failure);
                    return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
                }
            }

            return(RedirectToAction(
                       ActionNames.Confirmation,
                       ControllerNames.CheckoutConfirmation,
                       new
            {
                orderNumber = orderNumber,
                paymentMethod = paymentMethod
            }));
        }