private AuthorizeResponse AuthorizePayment(
            AmazonPaySettings settings,
            AmazonPayCheckoutState state,
            Store store,
            ProcessPaymentRequest request,
            Client client,
            bool synchronously,
            out AuthorizeRequest authRequest)
        {
            authRequest = new AuthorizeRequest()
                          .WithMerchantId(settings.SellerId)
                          .WithAmazonOrderReferenceId(state.OrderReferenceId)
                          .WithAuthorizationReferenceId(GetRandomId("Authorize"))
                          .WithCaptureNow(settings.TransactionType == AmazonPayTransactionType.AuthorizeAndCapture)
                          .WithCurrencyCode(ConvertCurrency(store.PrimaryStoreCurrency.CurrencyCode))
                          .WithAmount(request.OrderTotal);

            if (synchronously)
            {
                authRequest = authRequest.WithTransactionTimeout(0);
            }

            // See https://pay.amazon.com/de/developer/documentation/lpwa/201956480
            //{"SandboxSimulation": {"State":"Declined", "ReasonCode":"InvalidPaymentMethod", "PaymentMethodUpdateTimeInMins":5}}
            //{"SandboxSimulation": {"State":"Declined", "ReasonCode":"AmazonRejected"}}
            //if (settings.UseSandbox)
            //{
            //	var authNote = _services.Settings.GetSettingByKey<string>("SmartStore.AmazonPay.SellerAuthorizationNote");
            //  authRequest = authRequest.WithSellerAuthorizationNote(authNote);
            //}

            var authResponse = client.Authorize(authRequest);

            return(authResponse);
        }
        internal static string GetWidgetUrl(AmazonPaySettings settings)
        {
            switch (settings.Marketplace.EmptyNull().ToLower())
            {
            case "us":
                return(settings.UseSandbox
                                                ? "https://static-na.payments-amazon.com/OffAmazonPayments/us/sandbox/js/Widgets.js"
                                                : "https://static-na.payments-amazon.com/OffAmazonPayments/us/js/Widgets.js");

            case "uk":
                return(settings.UseSandbox
                                                ? "https://static-eu.payments-amazon.com/OffAmazonPayments/gbp/sandbox/lpa/js/Widgets.js"
                                                : "https://static-eu.payments-amazon.com/OffAmazonPayments/gbp/lpa/js/Widgets.js");

            case "jp":
                return(settings.UseSandbox
                                                ? "https://static-fe.payments-amazon.com/OffAmazonPayments/jp/sandbox/lpa/js/Widgets.js"
                                                : "https://static-fe.payments-amazon.com/OffAmazonPayments/jp/lpa/js/Widgets.js");

            default:
                return(settings.UseSandbox
                                                ? "https://static-eu.payments-amazon.com/OffAmazonPayments/eur/sandbox/lpa/js/Widgets.js"
                                                : "https://static-eu.payments-amazon.com/OffAmazonPayments/eur/lpa/js/Widgets.js");
            }
        }
Example #3
0
        public ActionResult Configure(AmazonPaySettings settings)
        {
            var model = new ConfigurationModel();

            MiniMapper.Map(settings, model);
            _apiService.SetupConfiguration(model);

            return(View(model));
        }
        public void Copy(AmazonPaySettings settings, bool fromSettings)
        {
            if (fromSettings)
            {
                UseSandbox = settings.UseSandbox;
                SellerId   = settings.SellerId;
                AccessKey  = settings.AccessKey;
                SecretKey  = settings.SecretKey;
                ClientId   = settings.ClientId;
                //ClientSecret = settings.ClientSecret;
                Marketplace = settings.Marketplace;

                DataFetching = settings.DataFetching;
                PollingMaxOrderCreationDays  = settings.PollingMaxOrderCreationDays;
                TransactionType              = settings.TransactionType;
                SaveEmailAndPhone            = settings.SaveEmailAndPhone;
                ShowButtonInMiniShoppingCart = settings.ShowButtonInMiniShoppingCart;
                AdditionalFee             = settings.AdditionalFee;
                AdditionalFeePercentage   = settings.AdditionalFeePercentage;
                AddOrderNotes             = settings.AddOrderNotes;
                InformCustomerAboutErrors = settings.InformCustomerAboutErrors;
                InformCustomerAddErrors   = settings.InformCustomerAddErrors;

                PayButtonColor  = settings.PayButtonColor;
                PayButtonSize   = settings.PayButtonSize;
                AuthButtonType  = settings.AuthButtonType;
                AuthButtonColor = settings.AuthButtonColor;
                AuthButtonSize  = settings.AuthButtonSize;
            }
            else
            {
                settings.UseSandbox = UseSandbox;
                settings.SellerId   = SellerId;
                settings.AccessKey  = AccessKey;
                settings.SecretKey  = SecretKey;
                settings.ClientId   = ClientId;
                //settings.ClientSecret = ClientSecret;
                settings.Marketplace = Marketplace;

                settings.DataFetching = DataFetching;
                settings.PollingMaxOrderCreationDays  = PollingMaxOrderCreationDays;
                settings.TransactionType              = TransactionType;
                settings.SaveEmailAndPhone            = SaveEmailAndPhone;
                settings.ShowButtonInMiniShoppingCart = ShowButtonInMiniShoppingCart;
                settings.AdditionalFee             = AdditionalFee;
                settings.AdditionalFeePercentage   = AdditionalFeePercentage;
                settings.AddOrderNotes             = AddOrderNotes;
                settings.InformCustomerAboutErrors = InformCustomerAboutErrors;
                settings.InformCustomerAddErrors   = InformCustomerAddErrors;

                settings.PayButtonColor  = PayButtonColor;
                settings.PayButtonSize   = PayButtonSize;
                settings.AuthButtonType  = AuthButtonType;
                settings.AuthButtonColor = AuthButtonColor;
                settings.AuthButtonSize  = AuthButtonSize;
            }
        }
Example #5
0
        public AmazonPayClient(AmazonPaySettings settings)
        {
            var config = new OffAmazonPaymentsServiceConfig()
            {
                ServiceURL = (settings.UseSandbox ? AmazonPayCore.UrlApiEuSandbox : AmazonPayCore.UrlApiEuProduction)
            };

            config.SetUserAgent(AmazonPayCore.AppName, AmazonPayCore.AppVersion);

            Settings = settings;
            Service  = new OffAmazonPaymentsServiceClient(AmazonPayCore.AppName, AmazonPayCore.AppVersion, settings.AccessKey, settings.SecretKey, config);
        }
Example #6
0
        public AmazonPayClient(AmazonPaySettings settings)
        {
            string appVersion = "1.0";

            try
            {
                appVersion = EngineContext.Current.Resolve <IPluginFinder>().GetPluginDescriptorBySystemName(AmazonPayCore.SystemName).Version.ToString();
            }
            catch (Exception) { }

            var config = new OffAmazonPaymentsServiceConfig()
            {
                ServiceURL = (settings.UseSandbox ? AmazonPayCore.UrlApiEuSandbox : AmazonPayCore.UrlApiEuProduction)
            };

            config.SetUserAgent(AmazonPayCore.AppName, appVersion);

            Settings = settings;
            Service  = new OffAmazonPaymentsServiceClient(AmazonPayCore.AppName, appVersion, settings.AccessKey, settings.SecretKey, config);
        }
Example #7
0
        public bool FulfillBillingAddress(AmazonPaySettings settings, Order order, AuthorizationDetails details, out string formattedAddress)
        {
            formattedAddress = "";

            if (details == null)
            {
                AmazonPayApiData data;
                details = GetAuthorizationDetails(new AmazonPayClient(settings), order.AuthorizationTransactionId, out data);
            }

            if (details == null || !details.IsSetAuthorizationBillingAddress())
            {
                return(false);
            }

            bool countryAllowsShipping, countryAllowsBilling;

            // override billing address cause it is just copy of the shipping address
            details.AuthorizationBillingAddress.ToAddress(order.BillingAddress, _countryService, _stateProvinceService, out countryAllowsShipping, out countryAllowsBilling);

            if (!countryAllowsBilling)
            {
                formattedAddress = details.AuthorizationBillingAddress.ToFormatedAddress(_countryService, _stateProvinceService);
                return(false);
            }

            order.BillingAddress.CreatedOnUtc = DateTime.UtcNow;

            if (order.BillingAddress.Email.IsEmpty())
            {
                order.BillingAddress.Email = order.Customer.Email;
            }

            _orderService.UpdateOrder(order);

            formattedAddress = details.AuthorizationBillingAddress.ToFormatedAddress(_countryService, _stateProvinceService);

            return(true);
        }
        /// <summary>
        /// Creates an API client.
        /// </summary>
        /// <param name="settings">AmazonPay settings</param>
        /// <param name="currencyCode">Currency code of primary store currency</param>
        /// <returns>AmazonPay client</returns>
        private Client CreateClient(AmazonPaySettings settings)
        {
            var descriptor = _pluginFinder.GetPluginDescriptorBySystemName(AmazonPayPlugin.SystemName);
            var appVersion = descriptor != null?descriptor.Version.ToString() : "1.0";

            Regions.supportedRegions region;
            switch (settings.Marketplace.EmptyNull().ToLower())
            {
            case "us":
                region = Regions.supportedRegions.us;
                break;

            case "uk":
                region = Regions.supportedRegions.uk;
                break;

            case "jp":
                region = Regions.supportedRegions.jp;
                break;

            default:
                region = Regions.supportedRegions.de;
                break;
            }

            var config = new Configuration()
                         .WithAccessKey(settings.AccessKey)
                         .WithClientId(settings.ClientId)
                         .WithSecretKey(settings.SecretKey)
                         .WithSandbox(settings.UseSandbox)
                         .WithApplicationName("Smartstore " + AmazonPayPlugin.SystemName)
                         .WithApplicationVersion(appVersion)
                         .WithRegion(region);

            var client = new Client(config);

            return(client);
        }
        private void AddOrderNote(AmazonPaySettings settings, Order order, string anyString = null, bool isIpn = false)
        {
            try
            {
                if (!settings.AddOrderNotes || order == null || anyString.IsEmpty())
                {
                    return;
                }

                var sb         = new StringBuilder();
                var faviconUrl = "{0}Plugins/{1}/Content/images/favicon.png".FormatInvariant(_services.WebHelper.GetStoreLocation(), AmazonPayPlugin.SystemName);

                sb.AppendFormat("<img src='{0}' class='mr-1 align-text-top' />", faviconUrl);
                sb.Append(T("Plugins.Payments.AmazonPay.AmazonDataProcessed"));
                sb.Append(":<br />");
                sb.Append(anyString);

                if (isIpn)
                {
                    order.HasNewPaymentNotification = true;
                }

                order.OrderNotes.Add(new OrderNote
                {
                    Note = sb.ToString(),
                    DisplayToCustomer = false,
                    CreatedOnUtc      = DateTime.UtcNow
                });

                _orderService.UpdateOrder(order);
            }
            catch (Exception exception)
            {
                Logger.Error(exception);
            }
        }