public void Cleanup(AppliedPaymentMethodCleanupContext context) { // Only finalize the process if this is an Amazon Payments order. if (context.PaymentMethod != AppLogic.ro_PMAmazonPayments) { return; } // Currently, Amazon only needs to clean up the checkout context if there's an error. // Successful orders will trigger the checkout process to clear the context. if (context.Status == AppLogic.ro_OK) { return; } var checkoutContext = PersistedCheckoutContextProvider.LoadCheckoutContext(context.Customer); var updatedCheckoutContext = new PersistedCheckoutContext( creditCard: checkoutContext.CreditCard, payPalExpress: checkoutContext.PayPalExpress, purchaseOrder: checkoutContext.PurchaseOrder, braintree: checkoutContext.Braintree, amazonPayments: null, termsAndConditionsAccepted: checkoutContext.TermsAndConditionsAccepted, over13Checked: checkoutContext.Over13Checked, shippingEstimateDetails: checkoutContext.ShippingEstimateDetails, offsiteRequiresBillingAddressId: null, offsiteRequiresShippingAddressId: null, email: checkoutContext.Email, selectedShippingMethodId: checkoutContext.SelectedShippingMethodId); PersistedCheckoutContextProvider.SaveCheckoutContext(context.Customer, updatedCheckoutContext); context.Customer.UpdateCustomer(requestedPaymentMethod: string.Empty); }
public ActionResult BraintreeThreeDSecureFail() { var customer = HttpContext.GetCustomer(); var context = PersistedCheckoutContextProvider.LoadCheckoutContext(customer); var updatedCheckoutContext = new PersistedCheckoutContext( creditCard: context.CreditCard, payPalExpress: context.PayPalExpress, purchaseOrder: context.PurchaseOrder, braintree: new BraintreeDetails( nonce: context.Braintree.Nonce, token: context.Braintree.Token, paymentMethod: context.Braintree.PaymentMethod, threeDSecureApproved: false), amazonPayments: context.AmazonPayments, termsAndConditionsAccepted: context.TermsAndConditionsAccepted, over13Checked: context.Over13Checked, shippingEstimateDetails: context.ShippingEstimateDetails, offsiteRequiresBillingAddressId: null, offsiteRequiresShippingAddressId: null, email: context.Email, selectedShippingMethodId: context.SelectedShippingMethodId); PersistedCheckoutContextProvider.SaveCheckoutContext(customer, updatedCheckoutContext); NoticeProvider.PushNotice("3dSecure verification failed, this order cannot be accepted.", NoticeType.Failure); return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout)); }
public ActionResult ShippingEstimate(ShippingEstimateViewModel model) { if (!ModelState.IsValid) { return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout)); } // Add the estimate partial address to the checkout context so that we can use that later to display rates if there is no customer address var customer = HttpContext.GetCustomer(); var checkoutContext = PersistedCheckoutContextProvider.LoadCheckoutContext(customer); var shippingEstimateDetails = new ShippingEstimateDetails( country: model.Country, city: model.City, state: model.State, postalCode: model.PostalCode); var updatedCheckoutContext = new PersistedCheckoutContext( creditCard: checkoutContext.CreditCard, payPalExpress: checkoutContext.PayPalExpress, purchaseOrder: checkoutContext.PurchaseOrder, braintree: checkoutContext.Braintree, termsAndConditionsAccepted: checkoutContext.TermsAndConditionsAccepted, over13Checked: checkoutContext.Over13Checked, amazonPayments: checkoutContext.AmazonPayments, shippingEstimateDetails: shippingEstimateDetails, offsiteRequiresBillingAddressId: checkoutContext.OffsiteRequiresBillingAddressId, offsiteRequiresShippingAddressId: checkoutContext.OffsiteRequiresShippingAddressId, email: checkoutContext.Email, selectedShippingMethodId: checkoutContext.SelectedShippingMethodId); PersistedCheckoutContextProvider.SaveCheckoutContext(customer, updatedCheckoutContext); return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout)); }
public ActionResult PurchaseOrder(PurchaseOrderViewModel model) { if (!ModelState.IsValid) { return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout)); } var customer = HttpContext.GetCustomer(); var checkoutContext = PersistedCheckoutContextProvider.LoadCheckoutContext(customer); var updatedCheckoutContext = new PersistedCheckoutContext( creditCard: checkoutContext.CreditCard, payPalExpress: checkoutContext.PayPalExpress, purchaseOrder: new PurchaseOrderDetails(model.PONumber), braintree: checkoutContext.Braintree, amazonPayments: null, termsAndConditionsAccepted: checkoutContext.TermsAndConditionsAccepted, over13Checked: checkoutContext.Over13Checked, shippingEstimateDetails: checkoutContext.ShippingEstimateDetails, offsiteRequiresBillingAddressId: null, offsiteRequiresShippingAddressId: null, email: checkoutContext.Email, selectedShippingMethodId: checkoutContext.SelectedShippingMethodId); PersistedCheckoutContextProvider.SaveCheckoutContext(customer, updatedCheckoutContext); customer.UpdateCustomer(requestedPaymentMethod: AppLogic.ro_PMPurchaseOrder); return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout)); }
public ActionResult SetPaymentMethod(string selectedPaymentMethod = null) { var customer = HttpContext.GetCustomer(); var checkoutContext = PersistedCheckoutContextProvider.LoadCheckoutContext(customer); var updatedCheckoutContext = new PersistedCheckoutContext( creditCard: checkoutContext.CreditCard, payPalExpress: checkoutContext.PayPalExpress, purchaseOrder: checkoutContext.PurchaseOrder, braintree: checkoutContext.Braintree, amazonPayments: checkoutContext.AmazonPayments, termsAndConditionsAccepted: checkoutContext.TermsAndConditionsAccepted, over13Checked: checkoutContext.Over13Checked, shippingEstimateDetails: checkoutContext.ShippingEstimateDetails, offsiteRequiresBillingAddressId: null, offsiteRequiresShippingAddressId: null, email: checkoutContext.Email, selectedShippingMethodId: checkoutContext.SelectedShippingMethodId); PersistedCheckoutContextProvider.SaveCheckoutContext(customer, updatedCheckoutContext); //Update the customer record if (selectedPaymentMethod != null && selectedPaymentMethod != customer.RequestedPaymentMethod) { customer.UpdateCustomer(requestedPaymentMethod: selectedPaymentMethod); } return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout)); }
public ActionResult AmazonPaymentsComplete(AmazonPaymentsViewModel model) { var customer = HttpContext.GetCustomer(); var orderDetails = AmazonPaymentsApiProvider .GetOrderDetails(model.AmazonOrderReferenceId) .GetOrderReferenceDetailsResult .OrderReferenceDetails; var shippingAddress = orderDetails .Destination .PhysicalDestination; var city = shippingAddress.City; var countryCode = shippingAddress.CountryCode; var countryName = AppLogic.GetCountryNameFromTwoLetterISOCode(countryCode); var stateName = shippingAddress.StateOrRegion ?? string.Empty; var stateAbbreviation = AppLogic.GetStateAbbreviation(stateName, countryName); var postalCode = shippingAddress.PostalCode; var amazonAddress = Address.FindOrCreateOffSiteAddress( customerId: customer.CustomerID, city: city, stateAbbreviation: string.IsNullOrEmpty(stateAbbreviation) ? stateName : stateAbbreviation, postalCode: postalCode, countryName: string.IsNullOrEmpty(countryName) ? countryCode : countryName, offSiteSource: AppLogic.ro_PMAmazonPayments); customer.SetPrimaryAddress(amazonAddress.AddressID, AddressTypes.Billing); customer.SetPrimaryAddress(amazonAddress.AddressID, AddressTypes.Shipping); var checkoutContext = PersistedCheckoutContextProvider.LoadCheckoutContext(customer); var updatedCheckoutContext = new PersistedCheckoutContext( creditCard: checkoutContext.CreditCard, payPalExpress: checkoutContext.PayPalExpress, purchaseOrder: checkoutContext.PurchaseOrder, braintree: checkoutContext.Braintree, amazonPayments: new AmazonPaymentsDetails(model.AmazonOrderReferenceId), termsAndConditionsAccepted: checkoutContext.TermsAndConditionsAccepted, over13Checked: checkoutContext.Over13Checked, shippingEstimateDetails: checkoutContext.ShippingEstimateDetails, offsiteRequiresBillingAddressId: amazonAddress.AddressID, offsiteRequiresShippingAddressId: amazonAddress.AddressID, email: checkoutContext.Email, selectedShippingMethodId: checkoutContext.SelectedShippingMethodId); PersistedCheckoutContextProvider.SaveCheckoutContext(customer, updatedCheckoutContext); customer.UpdateCustomer(requestedPaymentMethod: AppLogic.ro_PMAmazonPayments); return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout)); }
public ActionResult BraintreeThreeDSecurePass(string nonce) { var customer = HttpContext.GetCustomer(); var context = PersistedCheckoutContextProvider.LoadCheckoutContext(customer); var cart = CachedShoppingCartProvider.Get(customer, CartTypeEnum.ShoppingCart, AppLogic.StoreID()); var orderNumber = customer.ThisCustomerSession.SessionUSInt("3Dsecure.OrderNumber"); var updatedCheckoutContext = new PersistedCheckoutContext( creditCard: context.CreditCard, payPalExpress: context.PayPalExpress, purchaseOrder: context.PurchaseOrder, braintree: new BraintreeDetails( nonce: nonce, //We got a new nonce after the 3dSecure request token: context.Braintree.Token, paymentMethod: context.Braintree.PaymentMethod, threeDSecureApproved: true), amazonPayments: context.AmazonPayments, termsAndConditionsAccepted: context.TermsAndConditionsAccepted, over13Checked: context.Over13Checked, shippingEstimateDetails: context.ShippingEstimateDetails, offsiteRequiresBillingAddressId: null, offsiteRequiresShippingAddressId: null, email: context.Email, selectedShippingMethodId: context.SelectedShippingMethodId); PersistedCheckoutContextProvider.SaveCheckoutContext(customer, updatedCheckoutContext); customer.ThisCustomerSession[AppLogic.Braintree3dSecureKey] = "true"; customer.ThisCustomerSession[AppLogic.BraintreeNonceKey] = nonce; customer.ThisCustomerSession[AppLogic.BraintreePaymentMethod] = context.Braintree.PaymentMethod; var status = Gateway.MakeOrder(string.Empty, AppLogic.TransactionMode(), cart, orderNumber, string.Empty, string.Empty, string.Empty, string.Empty); ClearThreeDSecureSessionInfo(customer); if (status == AppLogic.ro_OK) { return(RedirectToAction( ActionNames.Confirmation, ControllerNames.CheckoutConfirmation, new { @orderNumber = orderNumber })); } NoticeProvider.PushNotice(string.Format("Unknown Result. Message={0}. Please retry your credit card.", status), NoticeType.Failure); return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout)); }
public ActionResult AmazonPaymentsCallback(string session, string access_token, string token_type, string expires_in, string scope) { // Get an email back from amazon and update the checkout context with it if we don't already have an email on the checkout context. var customer = HttpContext.GetCustomer(); var checkoutContext = PersistedCheckoutContextProvider.LoadCheckoutContext(customer); if (string.IsNullOrEmpty(checkoutContext.Email)) { if (string.IsNullOrEmpty(access_token)) { return(View(ViewNames.AmazonPayments, new { clearSession = true })); } var userProfile = AmazonPaymentsApiProvider.GetUserProfile(access_token); if (userProfile != null && !string.IsNullOrEmpty(userProfile.Email)) { var updatedCheckoutContext = new PersistedCheckoutContext( creditCard: checkoutContext.CreditCard, payPalExpress: checkoutContext.PayPalExpress, purchaseOrder: checkoutContext.PurchaseOrder, braintree: checkoutContext.Braintree, amazonPayments: checkoutContext.AmazonPayments, termsAndConditionsAccepted: checkoutContext.TermsAndConditionsAccepted, over13Checked: checkoutContext.Over13Checked, shippingEstimateDetails: checkoutContext.ShippingEstimateDetails, offsiteRequiresBillingAddressId: checkoutContext.OffsiteRequiresBillingAddressId, offsiteRequiresShippingAddressId: checkoutContext.OffsiteRequiresShippingAddressId, email: userProfile.Email, selectedShippingMethodId: checkoutContext.SelectedShippingMethodId); PersistedCheckoutContextProvider.SaveCheckoutContext(customer, updatedCheckoutContext); } } var model = new AmazonPaymentsViewModel( clientId: AmazonPaymentsApiProvider.Configuration.ClientId, merchantId: AmazonPaymentsApiProvider.Configuration.MerchantId, scriptUrl: AmazonPaymentsApiProvider.Configuration.ScriptUrl); model.CheckoutStep = AmazonPaymentsCheckoutStep.SelectAddress; return(View(ViewNames.AmazonPayments, model)); }
public ActionResult AmazonPayments(bool clearSession = false) { var customer = HttpContext.GetCustomer(); if (!PaymentOptionProvider.PaymentMethodSelectionIsValid(AppLogic.ro_PMAmazonPayments, customer)) { NoticeProvider.PushNotice( message: "Invalid payment method! Please choose another.", type: NoticeType.Failure); return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout)); } var model = new AmazonPaymentsViewModel( clientId: AmazonPaymentsApiProvider.Configuration.ClientId, merchantId: AmazonPaymentsApiProvider.Configuration.MerchantId, scriptUrl: AmazonPaymentsApiProvider.Configuration.ScriptUrl); if (clearSession) { var checkoutContext = PersistedCheckoutContextProvider.LoadCheckoutContext(customer); var updatedCheckoutContext = new PersistedCheckoutContext( creditCard: checkoutContext.CreditCard, payPalExpress: checkoutContext.PayPalExpress, purchaseOrder: checkoutContext.PurchaseOrder, braintree: checkoutContext.Braintree, amazonPayments: null, termsAndConditionsAccepted: checkoutContext.TermsAndConditionsAccepted, over13Checked: checkoutContext.Over13Checked, shippingEstimateDetails: checkoutContext.ShippingEstimateDetails, offsiteRequiresBillingAddressId: null, offsiteRequiresShippingAddressId: null, email: checkoutContext.Email, selectedShippingMethodId: checkoutContext.SelectedShippingMethodId); PersistedCheckoutContextProvider.SaveCheckoutContext(customer, updatedCheckoutContext); customer.UpdateCustomer(requestedPaymentMethod: string.Empty); return(Redirect(Url.Action(ActionNames.Index, ControllerNames.Checkout))); } return(View(model)); }
public void Cleanup(AppliedPaymentMethodCleanupContext context) { // Only finalize the process if this is a PayPal Express order. if (context.PaymentMethod != AppLogic.ro_PMPayPalExpress) { return; } // Currently, PayPal Express only needs to clean up the checkout context if there's an error. // Successful orders will trigger the checkout process to clear the context. if (context.Status == AppLogic.ro_OK) { return; } var checkoutContext = PersistedCheckoutContextProvider.LoadCheckoutContext(context.Customer); var updatedCheckoutContext = new PersistedCheckoutContext( creditCard: checkoutContext.CreditCard, payPalExpress: null, purchaseOrder: checkoutContext.PurchaseOrder, braintree: checkoutContext.Braintree, amazonPayments: checkoutContext.AmazonPayments, termsAndConditionsAccepted: checkoutContext.TermsAndConditionsAccepted, over13Checked: checkoutContext.Over13Checked, shippingEstimateDetails: checkoutContext.ShippingEstimateDetails, offsiteRequiresBillingAddressId: checkoutContext.OffsiteRequiresBillingAddressId, offsiteRequiresShippingAddressId: checkoutContext.OffsiteRequiresShippingAddressId, email: checkoutContext.Email, selectedShippingMethodId: checkoutContext.SelectedShippingMethodId); PersistedCheckoutContextProvider.SaveCheckoutContext(context.Customer, updatedCheckoutContext); DB.ExecuteSQL( sql: "update Customer set RequestedPaymentMethod = null where CustomerId = @customerId", parameters: new System.Data.SqlClient.SqlParameter("@customerId", context.Customer.CustomerID)); }
void UpdateTermsAndConditions(bool?termsAndConditionAccepted, Customer customer) { if (!termsAndConditionAccepted.HasValue) { return; } var checkoutContext = PersistedCheckoutContextProvider.LoadCheckoutContext(customer); var updatedCheckoutContext = new PersistedCheckoutContext( creditCard: checkoutContext.CreditCard, payPalExpress: checkoutContext.PayPalExpress, purchaseOrder: checkoutContext.PurchaseOrder, braintree: checkoutContext.Braintree, amazonPayments: checkoutContext.AmazonPayments, termsAndConditionsAccepted: termsAndConditionAccepted.Value, over13Checked: checkoutContext.Over13Checked, shippingEstimateDetails: checkoutContext.ShippingEstimateDetails, offsiteRequiresBillingAddressId: checkoutContext.OffsiteRequiresBillingAddressId, offsiteRequiresShippingAddressId: checkoutContext.OffsiteRequiresShippingAddressId, email: checkoutContext.Email, selectedShippingMethodId: checkoutContext.SelectedShippingMethodId); PersistedCheckoutContextProvider.SaveCheckoutContext(customer, updatedCheckoutContext); }
public ActionResult BraintreeCreditCard(FormCollection collection) { var customer = HttpContext.GetCustomer(); var checkoutContext = PersistedCheckoutContextProvider.LoadCheckoutContext(customer); var updatedCheckoutContext = new PersistedCheckoutContext( creditCard: new CreditCardDetails( name: customer.Name, number: null, issueNumber: null, cardType: collection["braintreeCardType"], expirationDate: null, startDate: null, cvv: null), payPalExpress: checkoutContext.PayPalExpress, purchaseOrder: checkoutContext.PurchaseOrder, braintree: new BraintreeDetails( nonce: collection["braintreeNonce"], token: collection["braintreeToken"], paymentMethod: Gateway.BraintreeCreditCardKey, //This is the Braintree payment method, not ours threeDSecureApproved: false), amazonPayments: checkoutContext.AmazonPayments, termsAndConditionsAccepted: checkoutContext.TermsAndConditionsAccepted, over13Checked: checkoutContext.Over13Checked, shippingEstimateDetails: checkoutContext.ShippingEstimateDetails, offsiteRequiresBillingAddressId: null, offsiteRequiresShippingAddressId: null, email: checkoutContext.Email, selectedShippingMethodId: checkoutContext.SelectedShippingMethodId); PersistedCheckoutContextProvider.SaveCheckoutContext(customer, updatedCheckoutContext); customer.UpdateCustomer(requestedPaymentMethod: AppLogic.ro_PMCreditCard); return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout)); }
public CheckoutEvaluationResult EvaluateCheckout(CheckoutConfiguration configuration, PersistedCheckoutContext persistedCheckoutContext, CheckoutSelectionContext checkoutSelectionContext, Customer customer, int storeId, CartContext cartContext) { // Build the evaluation context var stateMachineContext = new StateMachineContext( customer: customer, storeId: storeId, shoppingCart: cartContext.Cart, configuration: configuration, selections: checkoutSelectionContext); // Run the state machine var stateEvaluationResult = EvaluateStateMachine(stateMachineContext); // Put together a result var checkoutEvaluationResult = new CheckoutEvaluationResult( state: stateEvaluationResult.State, checkoutStageContext: stateEvaluationResult.CheckoutStageContext, selections: stateEvaluationResult.Selections); return(checkoutEvaluationResult); }
public PersistedCheckoutContextBuilder From(PersistedCheckoutContext source) { Source = source; return(this); }
public ActionResult PayPalExpressReturn(string token) { var customer = HttpContext.GetCustomer(); var expressCheckoutDetails = Gateway.GetExpressCheckoutDetails(token, customer.CustomerID); if (string.IsNullOrEmpty(expressCheckoutDetails)) { // If nothing returned, abort the transaction. return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout)); } if (expressCheckoutDetails.Equals("AVSFAILED", StringComparison.OrdinalIgnoreCase)) { NoticeProvider.PushNotice("PayPal Confirmed Address Required", NoticeType.Failure); return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout)); } if (!customer.IsRegistered && !customer.IsOver13) { // Set the Over13Checked flag since PayPal is permitting the order process, so they don't get rejected. DB.ExecuteSQL( "update Customer set Over13Checked = 1 where CustomerID = @customerId", new SqlParameter("customerId", customer.CustomerID)); } if (customer.PrimaryBillingAddress.PaymentMethodLastUsed == AppLogic.ro_PMPayPalEmbeddedCheckout) { var orderNumber = DB.GetSqlN( "select max(OrderNumber) N from dbo.Orders where CustomerID = @customerId", new SqlParameter("customerId", customer.CustomerID)); return(RedirectToAction( ActionNames.Confirmation, ControllerNames.CheckoutConfirmation, new { orderNumber = orderNumber })); } customer.UpdateCustomer(requestedPaymentMethod: AppLogic.ro_PMPayPalExpress); var checkoutContext = PersistedCheckoutContextProvider.LoadCheckoutContext(customer); // During our call for customer details from paypal above we set the email on the customer record if they are not signed in already. // So let's pull that customer email into the checkout context var email = !string.IsNullOrEmpty(checkoutContext.Email) ? checkoutContext.Email : customer.EMail; var updatedCheckoutContext = new PersistedCheckoutContext( creditCard: checkoutContext.CreditCard, payPalExpress: new PayPalExpressDetails( token: token, payerId: expressCheckoutDetails), purchaseOrder: checkoutContext.PurchaseOrder, braintree: checkoutContext.Braintree, amazonPayments: null, termsAndConditionsAccepted: checkoutContext.TermsAndConditionsAccepted, over13Checked: checkoutContext.Over13Checked, shippingEstimateDetails: checkoutContext.ShippingEstimateDetails, offsiteRequiresBillingAddressId: customer.PrimaryBillingAddressID, //This was set while processing the PayPal return info earlier offsiteRequiresShippingAddressId: customer.PrimaryShippingAddressID, //This was set while processing the PayPal return info earlier email: email, selectedShippingMethodId: checkoutContext.SelectedShippingMethodId); PersistedCheckoutContextProvider.SaveCheckoutContext(customer, updatedCheckoutContext); return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout)); }
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(); } }
public ActionResult CreditCard(CheckoutCreditCardViewModel model) { // Convert model fields into validatable values var customer = HttpContext.GetCustomer(); var checkoutContext = PersistedCheckoutContextProvider.LoadCheckoutContext(customer); var number = !string.IsNullOrEmpty(model.Number) && model.Number.StartsWith("•") && checkoutContext.CreditCard != null ? checkoutContext.CreditCard.Number : model.Number.Replace(" ", ""); var issueNumber = !string.IsNullOrEmpty(model.IssueNumber) && model.IssueNumber.StartsWith("•") && checkoutContext.CreditCard != null ? checkoutContext.CreditCard.IssueNumber : model.IssueNumber; var expirationDate = ParseMonthYearString(model.ExpirationDate); var startDate = ParseMonthYearString(model.StartDate); var cvv = !string.IsNullOrEmpty(model.Cvv) && model.Cvv.StartsWith("•") && checkoutContext.CreditCard != null ? checkoutContext.CreditCard.Cvv : model.Cvv; // Run server-side credit card validation var validationConfiguration = new CreditCardValidationConfiguration( validateCreditCardNumber: AppLogic.AppConfigBool("ValidateCreditCardNumbers"), showCardStartDateFields: AppLogic.AppConfigBool("ShowCardStartDateFields"), cardExtraCodeIsOptional: AppLogic.AppConfigBool("CardExtraCodeIsOptional")); var validationContext = new CreditCardValidationContext( cardType: model.CardType, number: number, issueNumber: issueNumber, expirationDate: expirationDate, startDate: startDate, cvv: cvv); var validationResult = CreditCardValidationProvider.ValidateCreditCard(validationConfiguration, validationContext); // Update the ModelState with any validation issues if (!validationResult.Valid) { foreach (var field in validationResult.FieldErrors) { foreach (var error in field) { // This assumes that the model properties and the credit card validation field enum names match perfectly ModelState.AddModelError(field.Key.ToString(), error); } } } // Use POST redirect GET if there are any issues if (!ModelState.IsValid) { return(RedirectToAction(ActionNames.CreditCard, ControllerNames.CheckoutCreditCard)); } // Save the validated credit card details into the persisted checkout state var updatedCheckoutContext = new PersistedCheckoutContext( creditCard: new CreditCardDetails( name: model.Name, number: number, issueNumber: issueNumber, cardType: model.CardType, expirationDate: expirationDate, startDate: startDate, cvv: cvv), payPalExpress: checkoutContext.PayPalExpress, purchaseOrder: checkoutContext.PurchaseOrder, braintree: checkoutContext.Braintree, amazonPayments: null, termsAndConditionsAccepted: checkoutContext.TermsAndConditionsAccepted, over13Checked: checkoutContext.Over13Checked, shippingEstimateDetails: checkoutContext.ShippingEstimateDetails, offsiteRequiresBillingAddressId: null, offsiteRequiresShippingAddressId: null, email: checkoutContext.Email, selectedShippingMethodId: checkoutContext.SelectedShippingMethodId); PersistedCheckoutContextProvider.SaveCheckoutContext(customer, updatedCheckoutContext); // Save the StoreCCInDB setting if it was shown to the customer & their choice changed var siteIsStoringCCs = AppLogic.AppConfigBool("StoreCCInDB"); if (siteIsStoringCCs && model.SaveCreditCardNumber != customer.StoreCCInDB) { customer.UpdateCustomer(storeCreditCardInDb: siteIsStoringCCs && model.SaveCreditCardNumber); } // Update the customer record if (customer.RequestedPaymentMethod != AppLogic.ro_PMCreditCard) { customer.UpdateCustomer(requestedPaymentMethod: AppLogic.ro_PMCreditCard); } try { if (WalletProvider.WalletsAreEnabled() && model.SaveToWallet) { WalletProvider.CreatePaymentProfile( customer: customer, billingAddress: customer.PrimaryBillingAddress, cardType: model.CardType, number: number, cvv: cvv, expirationDate: expirationDate.Value); } } catch (WalletException walletException) { ModelState.AddModelError("SaveToWallet", walletException.Message); return(RedirectToAction(ActionNames.CreditCard, ControllerNames.CheckoutCreditCard)); } return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout)); }
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)); }