2

I am trying to integrate amazon payment gateway with my .net core project. I am wondering if there is a way to redirect the user by forming a url with required query params rather than triggering the payment from the amazon button click. But unfortunately I could not find any documentation in the amazon pay sdk for .net or 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
            };
        }

I could do paypal integration by similar way( I am using CreateQueryParameters function to form the url query for paypal) . So if anyone know if its possible to do similar integration for amazon pay, how should be the query and what would be the amazon pay end point we need to use?

ebk
  • 305
  • 8
  • 20

1 Answers1

1

This is not possible with Amazon Pay. For various reasons the Amazon Pay Checkout always starts with the JS.

However, there is a trick to work around this and build a customer experience that is pretty much the same: You can render the required button in a hidden container and instead of the click event start the checkout with the amazonPayButton.initCheckout() method: https://developer.amazon.com/docs/amazon-pay-checkout/amazon-pay-script.html#decoupling-button-render-and-checkout-or-sign-in-initiation

If you like, you can also combine this with, what they call Additional Payment Button (https://developer.amazon.com/docs/amazon-pay-apb-checkout/additional-payment-button-overview.html) which basically means, that you can submit the shipping address before starting the checkout, thus being able to omit the first redirect to Amazon Pay for getting the shipping address.

These two together allow for a payment flow that is similar to any other payment method.

marcus.kreusch
  • 648
  • 5
  • 15