Beispiel #1
0
        public static PaymentMethodInfo Get(string paymentMethodToken)
        {
            // Give fake info
            if (IsFakePaymentMethod(paymentMethodToken))
            {
                return(new PaymentMethodInfo
                {
                    ExpirationDate = null,
                    Description = "FakeCard ending in 6789"
                });
            }

            var gateway = NewBraintreeGateway();

            if (String.IsNullOrWhiteSpace(paymentMethodToken))
            {
                return(null);
            }
            try
            {
                var saved = gateway.PaymentMethod.Find(paymentMethodToken);
                var info  = new PaymentMethodInfo();
                if (saved is CreditCard)
                {
                    var card = saved as CreditCard;
                    info.ExpirationDate = DateTimeOffset.Parse(card.ExpirationDate);
                    info.Description    = string.Format("{0} ends in {1}", card.CardType.ToString(), card.LastFour);
                }
                else if (saved is ApplePayCard)
                {
                    var apple = saved as ApplePayCard;
                    info.ExpirationDate = DateTimeOffset.Parse(apple.ExpirationYear + "/" + apple.ExpirationMonth + "/01");
                    info.Description    = string.Format("{0} ends in {1}", apple.CardType, apple.Last4);
                }
                else if (saved is PayPalAccount)
                {
                    var paypal = saved as PayPalAccount;
                    info.ExpirationDate = null;
                    info.Description    = string.Format("Paypal account for {0}", paypal.Email);
                }
                else if (saved is AndroidPayCard)
                {
                    var android = saved as AndroidPayCard;
                    info.ExpirationDate = DateTimeOffset.Parse(android.ExpirationYear + "/" + android.ExpirationMonth + "/01");
                    info.Description    = string.Format("{0} ends in {1}", android.CardType, android.Last4);
                }
                else
                {
                    info.Description = saved.ToString();
                }

                return(info);
            }
            catch (Braintree.Exceptions.NotFoundException)
            {
                return(null);
            }
        }
 private void Create(PaymentMethodInfo paymentMethodInfo, Guid guid, string languageId)
 {
     PaymentMethodDto paymentMethod = new PaymentMethodDto();
     PaymentMethodDto.PaymentMethodRow paymentMethodRow = paymentMethod.PaymentMethod.NewPaymentMethodRow();
     paymentMethodRow[paymentMethod.PaymentMethod.PaymentMethodIdColumn] = guid;
     paymentMethodRow[paymentMethod.PaymentMethod.ApplicationIdColumn] = AppContext.Current.ApplicationId;
     paymentMethodRow[paymentMethod.PaymentMethod.NameColumn] = paymentMethodInfo.Name;
     paymentMethodRow[paymentMethod.PaymentMethod.DescriptionColumn] = paymentMethodInfo.Description;
     paymentMethodRow[paymentMethod.PaymentMethod.LanguageIdColumn] = languageId;
     paymentMethodRow[paymentMethod.PaymentMethod.SystemKeywordColumn] = paymentMethodInfo.SystemKeyword;
     paymentMethodRow[paymentMethod.PaymentMethod.IsActiveColumn] = false;
     paymentMethodRow[paymentMethod.PaymentMethod.IsDefaultColumn] = false;
     paymentMethodRow[paymentMethod.PaymentMethod.ClassNameColumn] = paymentMethodInfo.ClassName;
     paymentMethodRow[paymentMethod.PaymentMethod.PaymentImplementationClassNameColumn] = paymentMethodInfo.PaymentClassName;
     paymentMethodRow[paymentMethod.PaymentMethod.SupportsRecurringColumn] = false;
     paymentMethodRow[paymentMethod.PaymentMethod.OrderingColumn] = paymentMethodInfo.SortOrder;
     paymentMethodRow[paymentMethod.PaymentMethod.CreatedColumn] = FrameworkContext.Current.CurrentDateTime;
     paymentMethodRow[paymentMethod.PaymentMethod.ModifiedColumn] = FrameworkContext.Current.CurrentDateTime;
     paymentMethod.PaymentMethod.Rows.Add(paymentMethodRow);
     PaymentManager.SavePayment(paymentMethod);
 }
        private void Create(PaymentMethodInfo paymentMethodInfo, Guid guid, string languageId)
        {
            PaymentMethodDto paymentMethod = new PaymentMethodDto();

            PaymentMethodDto.PaymentMethodRow paymentMethodRow = paymentMethod.PaymentMethod.NewPaymentMethodRow();
            paymentMethodRow[paymentMethod.PaymentMethod.PaymentMethodIdColumn] = guid;
            paymentMethodRow[paymentMethod.PaymentMethod.ApplicationIdColumn]   = AppContext.Current.ApplicationId;
            paymentMethodRow[paymentMethod.PaymentMethod.NameColumn]            = paymentMethodInfo.Name;
            paymentMethodRow[paymentMethod.PaymentMethod.DescriptionColumn]     = paymentMethodInfo.Description;
            paymentMethodRow[paymentMethod.PaymentMethod.LanguageIdColumn]      = languageId;
            paymentMethodRow[paymentMethod.PaymentMethod.SystemKeywordColumn]   = paymentMethodInfo.SystemKeyword;
            paymentMethodRow[paymentMethod.PaymentMethod.IsActiveColumn]        = false;
            paymentMethodRow[paymentMethod.PaymentMethod.IsDefaultColumn]       = false;
            paymentMethodRow[paymentMethod.PaymentMethod.ClassNameColumn]       = paymentMethodInfo.ClassName;
            paymentMethodRow[paymentMethod.PaymentMethod.PaymentImplementationClassNameColumn] = paymentMethodInfo.PaymentClassName;
            paymentMethodRow[paymentMethod.PaymentMethod.SupportsRecurringColumn] = false;
            paymentMethodRow[paymentMethod.PaymentMethod.OrderingColumn]          = paymentMethodInfo.SortOrder;
            paymentMethodRow[paymentMethod.PaymentMethod.CreatedColumn]           = FrameworkContext.Current.CurrentDateTime;
            paymentMethodRow[paymentMethod.PaymentMethod.ModifiedColumn]          = FrameworkContext.Current.CurrentDateTime;
            paymentMethod.PaymentMethod.Rows.Add(paymentMethodRow);
            PaymentManager.SavePayment(paymentMethod);
        }
Beispiel #4
0
        private PaymentSelection GetPaymentInfo()
        {
            var paymentMethods = PaymentManager.GetPaymentMethods(_currentMarket.GetCurrentMarket().DefaultLanguage.ToString());
            var paymentInfo    = new PaymentSelection();

            foreach (var paymentMethodRow in paymentMethods.PaymentMethod.OrderBy(p => p.Ordering))
            {
                var methodInfo = new PaymentMethodInfo();
                methodInfo.PaymentMethod = paymentMethodRow;

                // Enrich with payment information from page
                var page = _paymentRegistry.GetPaymentContentPageByMethodId(paymentMethodRow.PaymentMethodId);
                methodInfo.Description = page.Description != null?page.Description.ToHtmlString() : string.Empty;

                paymentInfo.PaymentMethods.Add(methodInfo);
            }

            // if there is only 1 choice, select it as default
            if (paymentInfo.PaymentMethods.Count == 1)
            {
                paymentInfo.PaymentMethods.First().PaymentMethod.IsDefault = true;
            }
            return(paymentInfo);
        }
Beispiel #5
0
 public CheckoutIndexViewModel(
     PaymentMethodInfo selectedPaymentMethod,
     AddressViewModel selectedBillingAddress,
     AddressViewModel selectedShippingAddress,
     bool checkoutButtonDisabled,
     bool showOver13Required,
     bool showOkToEmail,
     bool showTermsAndConditions,
     bool displayGiftCardSetup,
     bool showOrderOptions,
     bool showOrderNotes,
     bool showRealTimeShippingInfo,
     bool allowShipToDifferentThanBillTo,
     bool displayShippingSection,
     bool displayBillingSection,
     bool shippingInfoIsRequired,
     bool displayTwoCheckoutText,
     bool displayContinueOffsite,
     bool showPromotions,
     bool showGiftCards,
     bool giftCardCoversTotal,
     bool checkoutIsOffsiteOnly,
     string offsiteCheckoutError,
     string pageTitle,
     string payPalBanner,
     string continueShoppingUrl,
     CheckoutStageDisplayState accountStageState,
     CheckoutStageDisplayState paymentMethodStageState,
     CheckoutStageDisplayState billingAddressStageState,
     CheckoutStageDisplayState shippingAddressStageState,
     CheckoutStageDisplayState shippingMethodStageState,
     CheckoutStageDisplayState giftCardSetupStageState)
 {
     SelectedPaymentMethod          = selectedPaymentMethod;
     SelectedBillingAddress         = selectedBillingAddress;
     SelectedShippingAddress        = selectedShippingAddress;
     CheckoutButtonDisabled         = checkoutButtonDisabled;
     ShowOver13Required             = showOver13Required;
     ShowOkToEmail                  = showOkToEmail;
     ShowTermsAndConditions         = showTermsAndConditions;
     DisplayGiftCardSetup           = displayGiftCardSetup;
     ShowOrderOptions               = showOrderOptions;
     ShowOrderNotes                 = showOrderNotes;
     ShowRealTimeShippingInfo       = showRealTimeShippingInfo;
     AllowShipToDifferentThanBillTo = allowShipToDifferentThanBillTo;
     DisplayBillingSection          = displayBillingSection;
     DisplayShippingSection         = displayShippingSection;
     ShippingInfoIsRequired         = shippingInfoIsRequired;
     DisplayTwoCheckoutText         = displayTwoCheckoutText;
     DisplayContinueOffsite         = displayContinueOffsite;
     ShowPromotions                 = showPromotions;
     ShowGiftCards                  = showGiftCards;
     GiftCardCoversTotal            = giftCardCoversTotal;
     CheckoutIsOffsiteOnly          = checkoutIsOffsiteOnly;
     PageTitle                 = pageTitle;
     PayPalBanner              = payPalBanner;
     ContinueShoppingUrl       = continueShoppingUrl;
     OffsiteCheckoutError      = offsiteCheckoutError;
     AccountStageState         = accountStageState;
     PaymentMethodStageState   = paymentMethodStageState;
     BillingAddressStageState  = billingAddressStageState;
     ShippingAddressStageState = shippingAddressStageState;
     ShippingMethodStageState  = shippingMethodStageState;
     GiftCardSetupStageState   = giftCardSetupStageState;
 }
Beispiel #6
0
        void SaveCustomerContextToDB(PaymentMethodInfo paymentMethod, PersistedCheckoutContext context, Customer customer, Address billingAddress)
        {
            // Take info from the billing address and put it on the customer record if it's missing
            if (string.IsNullOrEmpty(customer.FirstName) || string.IsNullOrEmpty(customer.LastName))
            {
                customer.UpdateCustomer(
                    firstName: billingAddress.FirstName,
                    lastName: billingAddress.LastName);
            }

            if (string.IsNullOrEmpty(customer.Phone))
            {
                customer.UpdateCustomer(phone: billingAddress.Phone);
            }

            //Save the 'over 13' value if needed
            // nal
            //if(AppLogic.AppConfigBool("RequireOver13Checked") && context.Over13Checked)
            if (context.Over13Checked)
            {
                customer.UpdateCustomer(over13Checked: true);
            }

            //payment details for 2Checkout and braintree are not stored on the customer
            var activeGateway    = AppLogic.ActivePaymentGatewayCleaned();
            var gatewayIsOffsite = activeGateway == Gateway.ro_GWBRAINTREE ||
                                   activeGateway == Gateway.ro_GWTWOCHECKOUT;

            if (paymentMethod == null ||
                (gatewayIsOffsite && paymentMethod.Name == AppLogic.ro_PMCreditCard))
            {
                return;
            }

            //Save payment details to the address
            if (paymentMethod.Name == AppLogic.ro_PMCreditCard)
            {
                billingAddress.PaymentMethodLastUsed = AppLogic.ro_PMCreditCard;
                billingAddress.CardName            = context.CreditCard.Name;
                billingAddress.CardType            = context.CreditCard.CardType;
                billingAddress.CardNumber          = context.CreditCard.Number;
                billingAddress.CardExpirationMonth = context.CreditCard.ExpirationDate.Value.Month.ToString();
                billingAddress.CardExpirationYear  = context.CreditCard.ExpirationDate.Value.Year.ToString();

                if (context.CreditCard.StartDate.HasValue)
                {
                    billingAddress.CardStartDate = string.Format("{0:00}{1:0000}",
                                                                 context.CreditCard.StartDate.Value.Month,
                                                                 context.CreditCard.StartDate.Value.Year);
                }

                billingAddress.CardIssueNumber = string.IsNullOrEmpty(context.CreditCard.IssueNumber)
                                        ? string.Empty
                                        : context.CreditCard.IssueNumber;
                billingAddress.UpdateDB();

                //Stick the CVV in customer session so Gateway.MakeOrder can get to it (this is cleared out later)
                AppLogic.StoreCardExtraCodeInSession(customer, context.CreditCard.Cvv);
            }
            else if (paymentMethod.Name == AppLogic.ro_PMPurchaseOrder)
            {
                billingAddress.PONumber = context.PurchaseOrder.Number;
                if (!customer.MasterShouldWeStoreCreditCardInfo)
                {
                    billingAddress.ClearCCInfo();
                }

                billingAddress.UpdateDB();
            }
            else if (paymentMethod.Name == AppLogic.ro_PMAmazonPayments)
            {
                billingAddress.CardNumber = context.AmazonPayments.AmazonOrderReferenceId;
                billingAddress.UpdateDB();
            }
        }
Beispiel #7
0
        ActionResult RenderIndexView(CheckoutStageContext checkoutStageContext, PersistedCheckoutContext persistedCheckoutContext, PaymentMethodInfo selectedPaymentMethod, Customer customer, bool termsAndConditionsAccepted, string returnUrl, bool showCheckoutStageErrors)
        {
            var cart = CachedShoppingCartProvider.Get(customer, CartTypeEnum.ShoppingCart, AppLogic.StoreID());

            // Build a model and render it
            var billingAddressViewModel = customer.PrimaryBillingAddress != null
                                ? AddressViewModelConverter.ConvertToAddressViewModel(customer.PrimaryBillingAddress, customer)
                                : null;

            var shippingAddressViewModel = customer.PrimaryShippingAddress != null
                                ? AddressViewModelConverter.ConvertToAddressViewModel(customer.PrimaryShippingAddress, customer)
                                : null;

            var cartPageAd           = new PayPalAd(PayPalAd.TargetPage.Cart);
            var gatewayIsTwoCheckout = AppLogic.ActivePaymentGatewayCleaned() == Gateway.ro_GWTWOCHECKOUT &&
                                       selectedPaymentMethod != null &&
                                       selectedPaymentMethod.Name == AppLogic.ro_PMCreditCard;

            var shippingEnabled =
                checkoutStageContext.ShippingAddress.Disabled != true ||
                checkoutStageContext.ShippingMethod.Disabled != true;

            var shippingInfoRequired =
                checkoutStageContext.ShippingAddress.Required == true ||
                checkoutStageContext.ShippingMethod.Required == true;

            var displayBillingSection = checkoutStageContext.BillingAddress.Disabled != true;

            // nal
            //var allowShipToDifferentThanBillTo = AppLogic.AppConfigBool("AllowShipToDifferentThanBillTo");
            var allowShipToDifferentThanBillTo = true;

            //  Display the shipping section only if shipping is enabled on the site. If so, than if shipping can be different
            //  than billing, we need to show the form. If shipping and billing can be different or the current payment
            //  option doesn't care about billing, then show just the shipping section and that address will be used for
            //  both shipping and billing.
            var displayShippingSection = shippingEnabled && allowShipToDifferentThanBillTo;

            var checkoutIsOffsiteOnly   = PaymentOptionProvider.CheckoutIsOffsiteOnly(customer, cart);
            var paymentMethodStageState = ConvertStageStatusToDisplayState(checkoutStageContext.PaymentMethod, showCheckoutStageErrors);

            var model = new CheckoutIndexViewModel(
                selectedPaymentMethod: selectedPaymentMethod,
                selectedBillingAddress: billingAddressViewModel,
                selectedShippingAddress: shippingAddressViewModel,
                checkoutButtonDisabled: checkoutStageContext.PlaceOrderButton.Fulfilled != true,
                showOver13Required: Over13Required(customer),
                showOkToEmail: AppLogic.AppConfigBool("Checkout.ShowOkToEmailOnCheckout"),
                showTermsAndConditions: AppLogic.AppConfigBool("RequireTermsAndConditionsAtCheckout"),
                displayGiftCardSetup: checkoutStageContext.GiftCardSetup.Required == true,
                showOrderOptions: cart.AllOrderOptions.Any(),
                // nal
                //showOrderNotes: !AppLogic.AppConfigBool("DisallowOrderNotes"),
                showOrderNotes: true,
                showRealTimeShippingInfo: AppLogic.AppConfigBool("RTShipping.DumpDebugXmlOnCheckout") && (customer.IsAdminUser || customer.IsAdminSuperUser),
                allowShipToDifferentThanBillTo: allowShipToDifferentThanBillTo,
                displayShippingSection: displayShippingSection,
                displayBillingSection: displayBillingSection,
                shippingInfoIsRequired: shippingInfoRequired,
                displayTwoCheckoutText: gatewayIsTwoCheckout,
                displayContinueOffsite: selectedPaymentMethod != null && selectedPaymentMethod.Location == PaymentMethodLocation.Offsite,
                // nal
                //showPromotions: AppLogic.AppConfigBool("Promotions.Enabled"),
                showPromotions: true,
                // nal
                //showGiftCards: AppLogic.AppConfigBool("GiftCards.Enabled"),
                showGiftCards: true,
                giftCardCoversTotal: cart.GiftCardCoversTotal(),
                checkoutIsOffsiteOnly: checkoutIsOffsiteOnly,
                pageTitle: "Secure Checkout",
                payPalBanner: cartPageAd.Show ? cartPageAd.ImageScript : null,
                accountStageState: ConvertStageStatusToDisplayState(checkoutStageContext.Account, showCheckoutStageErrors),
                // nal
                continueShoppingUrl: Url.Content(returnUrl),
                offsiteCheckoutError: checkoutIsOffsiteOnly && paymentMethodStageState == CheckoutStageDisplayState.Failing
                                        ? "Please choose a payment method"
                    : string.Empty,
                paymentMethodStageState: paymentMethodStageState,
                billingAddressStageState: ConvertStageStatusToDisplayState(checkoutStageContext.BillingAddress, showCheckoutStageErrors),
                shippingAddressStageState: ConvertStageStatusToDisplayState(checkoutStageContext.ShippingAddress, showCheckoutStageErrors),
                shippingMethodStageState: ConvertStageStatusToDisplayState(checkoutStageContext.ShippingMethod, showCheckoutStageErrors),
                giftCardSetupStageState: ConvertStageStatusToDisplayState(checkoutStageContext.GiftCardSetup, showCheckoutStageErrors))
            {
                Over13Selected             = persistedCheckoutContext.Over13Checked,
                OkToEmailSelected          = customer.OKToEMail,
                TermsAndConditionsAccepted = termsAndConditionsAccepted
            };

            return(View(model));
        }