2

我正在尝试将亚马逊支付网关与我的 .net 核心项目集成。我想知道是否有一种方法可以通过形成具有所需查询参数的 url 来重定向用户,而不是通过点击亚马逊按钮触发付款。但不幸的是,我在 amazon pay sdk for .net 或 amazon pay developer docs 中找不到任何文档。

public async Task PostRedirectPayment(PaymentTransaction paymentTransaction)
        {
            var order = await _orderService.GetOrderByGuid(paymentTransaction.OrderGuid);
            //create common query parameters for the request
            var queryParameters = await CreateQueryParameters(order);

            await AddOrderTotalParameters(queryParameters, order);
            var Signature=SignParameters(queryParameters, secretKey);
            IDictionary<String, String> SortedParameters = new SortedDictionary<String, String>(queryParameters, StringComparer.Ordinal);
            SortedParameters.Add("signature", System.Web.HttpUtility.UrlEncode(Signature));


            //remove null values from parameters
            queryParameters = SortedParameters.Where(parameter => !string.IsNullOrEmpty(parameter.Value))
           .ToDictionary(parameter => parameter.Key, parameter => parameter.Value);

            //var url = JsonConvert.SerializeObject(SortedParameters);
            var url = QueryHelpers.AddQueryString(GetAmazonPayUrl(), queryParameters);
            _httpContextAccessor.HttpContext.Response.Redirect(url);
        }

private async Task<IDictionary<string, string>> CreateQueryParameters(Order order)
        {   
            //create query parameters
            return new Dictionary<string, string>
            {
                

                //the character set and character encoding
                // ["charset"] = "utf-8",

                //set return method to "2" (the customer redirected to the return URL by using the POST method, and all payment variables are included)
                //["rm"] = "2",
                ["accessKey"] = "my access key",
                ["sellerId"] = "my seller id",
                ["lwaClientId"] = "my client id",

                //PDT, IPN and cancel URL
                ["return"] = $"{storeLocation}/PDTHandler?custom={order.OrderGuid}",
                //["notify_url"] = $"{storeLocation}/IPNHandler",
                ["cancelReturnURL"] = $"{storeLocation}/CancelOrder",

                //order identifier
                ["sellerOrderId"] = order.OrderNumber.ToString(),
                //["custom"] = order.OrderGuid.ToString(),
                ["sellerNote"]="",
                ["currencyCode"] = order.CustomerCurrencyCode,

               

                ["shippingAddressRequired"]="false",
                ["paymentAction"]= "AuthorizeAndCapture"
                //shipping address, if exists
                ["no_shipping"] = order.ShippingStatusId == ShippingStatus.ShippingNotRequired ? "1" : "2",
                ["address_override"] = order.ShippingStatusId == ShippingStatus.ShippingNotRequired ? "0" : "1",
                ["first_name"] = order.ShippingAddress?.FirstName,
                ["last_name"] = order.ShippingAddress?.LastName,
                ["address1"] = order.ShippingAddress?.Address1,
                ["address2"] = order.ShippingAddress?.Address2,
                ["city"] = order.ShippingAddress?.City,

                ["stateOrRegion"] = stateProvince,
                ["country"] = countryCode,
                ["postalCode"] = order.ShippingAddress?.ZipPostalCode,
                ["email"] = order.ShippingAddress?.Email
            };
        }

我可以通过类似的方式进行贝宝集成(我正在使用 CreateQueryParameters 函数来形成贝宝的 url 查询)。因此,如果有人知道是否可以为亚马逊支付进行类似的集成,那么查询应该如何以及我们需要使用的亚马逊支付端点是什么?

4

1 回答 1

1

亚马逊支付无法做到这一点。由于各种原因,Amazon Pay Checkout 总是以 JS 开头。

但是,有一个技巧可以解决这个问题并构建几乎相同的客户体验:您可以在隐藏的容器中呈现所需的按钮,而不是点击事件,使用以下amazonPayButton.initCheckout()方法开始结帐:https://developer .amazon.com/docs/amazon-pay-checkout/amazon-pay-script.html#decoupling-button-render-and-checkout-or-sign-in-initiation

如果您愿意,您也可以将其与他们所谓的附加付款按钮https://developer.amazon.com/docs/amazon-pay-apb-checkout/additional-payment-button-overview.html)结合起来,基本上意味着,您可以在开始结帐之前提交送货地址,从而可以省略第一次重定向到 Amazon Pay 以获取送货地址。

这两者一起允许类似于任何其他支付方式的支付流程。

于 2021-11-13T17:56:04.060 回答