PHP code example of sunaoka / amazon-pay-api-sdk-php-laravel

1. Go to this page and download the library: Download sunaoka/amazon-pay-api-sdk-php-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sunaoka / amazon-pay-api-sdk-php-laravel example snippets




return [
    'sandbox'              => (bool)env('AMAZON_PAY_SANDBOX', true),
    'merchant_id'          => env('AMAZON_PAY_MERCHANT_ID'),
    'store_id'             => env('AMAZON_PAY_STORE_ID'),
    'public_key_id'        => env('AMAZON_PAY_PUBLIC_KEY_ID'),
    'private_key'          => env('AMAZON_PAY_PRIVATE_KEY'),
    'region'               => env('AMAZON_PAY_REGION'),
    'language'             => env('AMAZON_PAY_LANGUAGE'),
    'currency_code'        => env('AMAZON_PAY_CURRENCY_CODE'),
    'algorithm'            => env('AMAZON_PAY_ALGORITHM'),
    'override_service_url' => env('AMAZON_PAY_OVERRIDE_SERVICE_URL'),
    'proxy'                => !empty(env('AMAZON_PAY_PROXY_HOST')) ? [
        'host'     => env('AMAZON_PAY_PROXY_HOST'),
        'port'     => env('AMAZON_PAY_PROXY_PORT'),
        'username' => env('AMAZON_PAY_PROXY_USERNAME'),
        'password' => env('AMAZON_PAY_PROXY_PASSWORD'),
    ] : null,
];



$payload = [
    'storeId'            => config('amazon-pay.store_id'),
    'webCheckoutDetails' => [
        'checkoutReviewReturnUrl' => 'http://localhost/checkout/review',
        'checkoutResultReturnUrl' => 'http://localhost/checkout/result',
        'checkoutCancelUrl'       => 'http://localhost/checkout/cancel',
    ],
];

$signature = \AmazonPay::generateButtonSignature($payload);

$button = [
    'merchantId'                  => config('amazon-pay.merchant_id'),
    'ledgerCurrency'              => config('amazon-pay.currency_code'),
    'sandbox'                     => config('amazon-pay.sandbox'),
    'checkoutLanguage'            => config('amazon-pay.language'),
    'productType'                 => 'PayAndShip',
    'placement'                   => 'Cart',
    'createCheckoutSessionConfig' => [
        'payloadJSON' => $payload,
        'signature'   => $signature,
        'publicKeyId' => config('amazon-pay.public_key_id'),
        'algorithm'   => config('amazon-pay.algorithm'),
    ],
];



\AmazonPay::fake([
    'refundId'           => 'S01-5105180-3221187-R022311',
    'chargeId'           => 'S01-5105180-3221187-C056351',
    'refundAmount'       => [
        'amount'       => '14.00',
        'currencyCode' => 'USD'
    ],
    'softDescriptor'     => 'Descriptor',
    'creationTimestamp'  => '20190714T155300Z',
    'statusDetails'      => [
        'state'                => 'RefundInitiated',
        'reasonCode'           => null,
        'reasonDescription'    => null,
        'lastUpdatedTimestamp' => '20190714T155300Z'
    ],
    'releaseEnvironment' => 'Sandbox',
]);

$payload = [
    'chargeId'       => 'S01-5105180-3221187-C056351',
    'refundAmount'   => [
        'amount'       => '14.00',
        'currencyCode' => 'USD',
    ],
    'softDescriptor' => 'Descriptor',
];

$response = \AmazonPay::createRefund($payload, []);
$result = json_decode($response['response'], true);

echo $result['refundId']; // S01-5105180-3221187-R022311
bash
php artisan vendor:publish --tag=amazon-pay-config