Exemplo n.º 1
0
            public KlarnaPaymentArgs CreatePaymentArgs(OrderCarrier order, string paymentAccountId)
            {
                var tlsUsage = _routeRequestLookupInfoAccessor.RouteRequestLookupInfo.IsSecureConnection;

                if (!tlsUsage)
                {
                    this.Log().Trace("Klarna Checkout Validation is disabled. To enable the validate you need to use https on the checkout page.");
                }

                var checkoutFlowInfo = Cart.CheckoutFlowInfo;

                checkoutFlowInfo.ExecutePaymentMode     = ExecutePaymentMode.Reserve;
                checkoutFlowInfo.RequireConsumerConfirm = false;

                var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);

                var checkoutPage             = _requestModelAccessor.RequestModel.WebsiteModel.Fields.GetValue <PointerPageItem>(AcceleratorWebsiteFieldNameConstants.CheckouPage);
                var checkoutPageUrl          = GetAbsolutePageUrl(checkoutPage);
                var checkoutPageEntity       = checkoutPage.EntitySystemId.MapTo <PageModel>();
                var termsAndConditionPage    = checkoutPageEntity.GetValue <PointerPageItem>(CheckoutPageFieldNameConstants.TermsAndConditionsPage);
                var termsAndConditionPageUrl = GetAbsolutePageUrl(termsAndConditionPage);

                var channelUri = new Uri(_urlService.GetUrl(_requestModelAccessor.RequestModel.ChannelModel.Channel, new ChannelUrlArgs()
                {
                    AbsoluteUrl = true
                }));
                var channelUrl      = channelUri.AbsoluteUri;
                var confirmationUrl = new Uri(channelUri, urlHelper
                                              .Action("Confirmation", "KlarnaPayment", new { AccountId = paymentAccountId, TransactionNumber = "{checkout.order.id}" }, Uri.UriSchemeHttps))?
                                      .AbsoluteUri
                                      .Replace("%7B", "{").Replace("%7D", "}");
                var validateUrl = new Uri(channelUri, urlHelper
                                          .Action("Validate", "KlarnaPayment", new { AccountId = paymentAccountId, TransactionNumber = "{checkout.order.id}" }, Uri.UriSchemeHttps))?
                                  .AbsoluteUri
                                  .Replace("%7B", "{").Replace("%7D", "}");
                var pushUrl = new Uri(channelUri, urlHelper
                                      .Action("PushNotification", "KlarnaPayment", new { TransactionNumber = "{checkout.order.id}" }, Uri.UriSchemeHttps))?
                              .AbsoluteUri
                              .Replace("%7B", "{").Replace("%7D", "}");

                var args = new KlarnaPaymentArgs
                {
                    CustomerPersonalNumber = string.Empty, //no ssn.
                    KlarnaCampaignCode     = -1,
                    ExecuteScript          = null,         //not used
                    TermsUrl              = termsAndConditionPageUrl,
                    ConfirmationUrl       = confirmationUrl,
                    PushNotificationUrl   = pushUrl,
                    CheckoutUrl           = checkoutPageUrl, //if cancelled, go back to checkout page.
                    ClientLanguage        = CultureInfo.CurrentUICulture.Name,
                    BackToStoreUrl        = channelUrl,
                    ValidationUrl         = tlsUsage ? validateUrl : null,
                    UserHostAddress       = StudioKlarnaApi.GetClientIP(),
                    PaymentMode           = ExecutePaymentMode.Reserve,
                    KlarnaCheckoutOptions = _paymentConfig.GetCheckoutOptions(order)
                };

                return(args);
            }
Exemplo n.º 2
0
#pragma warning disable IDE0060 // Remove unused parameter
        public void UpdateDataSentToKlarna(UrlHelper urlHelper, OrderCarrier orderCarrier, KlarnaPaymentArgs paymentArgs, CheckoutOrder klarnaCheckoutOrder)
#pragma warning restore IDE0060 // Remove unused parameter
        {
            //if the project has specific data to be sent to Klarna, outside the order carrier,
            //or has them as additional order info, and is not handled by the Klarna addOn, modify the klarnaCheckoutOrder parameter.
            //it is the klarnaCheckoutOrder object that will be sent to Klarna checkout api at Klarna.
            //the format of klarnaCheckoutOrder parameter is described in Klarna API documentation https://developers.klarna.com.

            //Set the checkout options here.
            klarnaCheckoutOrder.CheckoutOptions = new CheckoutOptions
            {
                AllowSeparateShippingAddress = true,
                ColorButton          = "#ff69b4",
                DateOfBirthMandatory = true
            };

            //External payment methods should be configured for each Merchant account by Klarna before they are used.
            AddCashOnDeliveryExternalPaymentMethod(urlHelper, orderCarrier, klarnaCheckoutOrder);
        }