-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use of stripcslashes breaks Amazon/Pay/API/Client::generateButtonSignature #13
Comments
Hi Thanks for the issue, |
So this works for me, note I have to escape the payload before turning it into a js string <?php
require '../vendor/autoload.php';
use Amazon\Pay\API\Client;
$publicKeyId = '...';
$payload = json_encode([
'storeId' => '...',
'webCheckoutDetails' => [
'checkoutReviewReturnUrl' => 'https://.../review',
],
]);
$client = new Client([
'private_key' => file_get_contents('...pem'),
'public_key_id' => $publicKeyId,
'region' => 'US',
]);
$signature = $client->generateButtonSignature($payload);
?>
<html>
<body>
<div id="AmazonPayButton"></div>
<script src="https://static-na.payments-amazon.com/checkout.js"></script>
<script type="text/javascript" charset="utf-8">
amazon.Pay.renderButton('#AmazonPayButton', {
// set checkout environment
merchantId: '...',
publicKeyId: <?php echo json_encode($publicKeyId) ?>,
ledgerCurrency: 'USD',
checkoutLanguage: 'en_US',
placement: 'Cart',
buttonColor: 'Gold',
createCheckoutSessionConfig: {
payloadJSON: <?php echo json_encode(stripcslashes($payload)) ?>, // <--- the interesting bit
signature: <?php echo json_encode($signature) ?>,
}
});
</script>
</body>
</html> But this doesn't <?php
require '../vendor/autoload.php';
use Amazon\Pay\API\Client;
$publicKeyId = '...';
$payload = json_encode([
'storeId' => '...',
'webCheckoutDetails' => [
'checkoutReviewReturnUrl' => 'https://.../review',
],
]);
$client = new Client([
'private_key' => file_get_contents('...pem'),
'public_key_id' => $publicKeyId,
'region' => 'US',
]);
$signature = $client->generateButtonSignature($payload);
?>
<html>
<body>
<div id="AmazonPayButton"></div>
<script src="https://static-na.payments-amazon.com/checkout.js"></script>
<script type="text/javascript" charset="utf-8">
amazon.Pay.renderButton('#AmazonPayButton', {
// set checkout environment
merchantId: '...',
publicKeyId: <?php echo json_encode($publicKeyId) ?>,
ledgerCurrency: 'USD',
checkoutLanguage: 'en_US',
placement: 'Cart',
buttonColor: 'Gold',
createCheckoutSessionConfig: {
payloadJSON: <?php echo json_encode($payload) ?>, // <--- no strip cslashes
signature: <?php echo json_encode($signature) ?>,
}
});
</script>
</body>
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried using this library today and was getting errors like below when clicking the checkout button in the browser:
Error Code: InvalidSignatureError
I was following the documentation here. After struggling with this issue I tried removing the call to stripcslashes on the line below.
https://github.com/amzn/amazon-pay-api-sdk-php/blob/master/Amazon/Pay/API/Client.php#L404
Without stripcslashes it looked like
$hashedButtonRequest = self::AMAZON_SIGNATURE_ALGORITHM . "\n" . $this->hexAndHash($payload);
. With that change suddenly my checkouts were working. I also found that mangling the value passed topayloadJSON
with stripcslashes got things working as an alternative to editing the library.Anyway, the stripcslashes seems to be causing issues.
The text was updated successfully, but these errors were encountered: