I have a webcart and I am trying to add amazon checkout button into it. I got some php code from the internet to create checkout button and when I click on the generated button it takes me to amazon and shows the order details also. But when I try to sign in to amazon it gives error. I tried to read amazon’s help on checkout button integration but it makes no sense. I just want to checkout and not create a cart in xml or jquery etc. How can I create a simple Pay via Amazon button like we do in Paypal ?
Please help. It seems amazon has made even this simplest thing to be most complex. Please check the code:
<?php
// Read more about IOPN at: http://amazonpayments.s3.amazonaws.com/documents/Instant_Order_Processing_Notification_API_Guide_UK.pdf
// Key from Amazon
$merchant_id = '***************';
$aws_access_key_id = '************************';
$aws_secret_access_key = '**********/**********';
// Set up cart
$form['aws_access_key_id'] = $aws_access_key_id;
$form['currency_code'] = 'USD';
$form['item_merchant_id_1'] = $merchant_id;
$form['item_price_1'] = 10;
$form['item_quantity_1'] = 1;
$form['item_sku_1'] = "ORDER-1";
$form['item_title_1'] = "Test Order";
//$form['custom'] = 123;
ksort($form);
// Encode order as string and calculate signature
$order = '';
foreach ($form as $key => $value) {
$order .= $key . "=" . rawurlencode($value) . "&";
}
$form['merchant_signature'] = base64_encode(hash_hmac('sha1', $order, $aws_secret_access_key, true));
// Return string with Amazon javascript and HTML form
// Assumes you already have jQuery loaded elsewhere on page
// URL's link to live site, not sandbox!
$amazon_order_html =
'<script type="text/javascript" src="https://images-na.ssl-images-amazon.com/images/G/01/cba/js/widget/widget.js"></script>
<form method="post" action="https://payments.amazon.com/checkout/' . $merchant_id . '">';
foreach ( $form as $key => $value ) {
$amazon_order_html .= '<input type="hidden" name="' . $key . '" value="' . $value . '" />';
}
$amazon_order_html .= '<input alt="Checkout with Amazon Payments" src="https://payments.amazon.com/gp/cba/button?ie=UTF8&color=orange&background=white&cartOwnerId=' . $merchant_id . '&size=large" type="image"></form>';
echo $amazon_order_html;
?>
It takes me to amazon and shows the order details and amount etc. but when I try to sign in, then it gives following error:
Important Message
We’re sorry, but there’s a problem with this order. Please contact the merchant directly for assistance in completing this order.
Well, I’m stumped. Do you have any documentation related to interacting with Amazon’s checkout service? I’m not seeing anything inherently obvious here, and I’m not familiar with their checkout service.
Documentation is there but it does not have any sample code of example on how to do it. After searching a lot I found this piece of code which does’nt seems to be working
Can you provide the generated HTML form that doesn’t seem to be working? And for reference it looks like you are trying to use this for integrating with Amazon.
Going through the documentation, it all looks right to me. The only thing you may want to try is using ‘10.00’ for your price, maybe it requires a full decimal? But I’m not seeing anything wrong with your implementation.