Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sunaoka/amazon-pay-api-sdk-php-laravel
Amazon Pay API SDK (PHP) for Laravel
https://github.com/sunaoka/amazon-pay-api-sdk-php-laravel
amazon-pay laravel php
Last synced: 25 days ago
JSON representation
Amazon Pay API SDK (PHP) for Laravel
- Host: GitHub
- URL: https://github.com/sunaoka/amazon-pay-api-sdk-php-laravel
- Owner: sunaoka
- License: apache-2.0
- Created: 2023-02-13T06:31:24.000Z (over 1 year ago)
- Default Branch: develop
- Last Pushed: 2024-03-29T00:38:17.000Z (7 months ago)
- Last Synced: 2024-04-29T16:42:16.204Z (6 months ago)
- Topics: amazon-pay, laravel, php
- Language: PHP
- Homepage: https://packagist.org/packages/sunaoka/amazon-pay-api-sdk-php-laravel
- Size: 43 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Amazon Pay API SDK (PHP) for Laravel
[![Latest Stable Version](https://poser.pugx.org/sunaoka/amazon-pay-api-sdk-php-laravel/v/stable)](https://packagist.org/packages/sunaoka/amazon-pay-api-sdk-php-laravel)
[![License](https://poser.pugx.org/sunaoka/amazon-pay-api-sdk-php-laravel/license)](https://packagist.org/packages/sunaoka/amazon-pay-api-sdk-php-laravel)
[![PHP from Packagist](https://img.shields.io/packagist/php-v/sunaoka/amazon-pay-api-sdk-php-laravel)](composer.json)
[![Laravel](https://img.shields.io/badge/laravel-%3E=%206.x-red)](https://laravel.com/)
[![Test](https://github.com/sunaoka/amazon-pay-api-sdk-php-laravel/actions/workflows/test.yml/badge.svg)](https://github.com/sunaoka/amazon-pay-api-sdk-php-laravel/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/sunaoka/amazon-pay-api-sdk-php-laravel/branch/main/graph/badge.svg?token=B69XU9TMMH)](https://codecov.io/gh/sunaoka/amazon-pay-api-sdk-php-laravel)----
This library is The Laravel Framework binding for [amazon-pay-api-sdk-php](https://github.com/amzn/amazon-pay-api-sdk-php).
## Installation
```bash
composer require sunaoka/amazon-pay-api-sdk-php-laravel
```## Configurations
```bash
php artisan vendor:publish --tag=amazon-pay-config
```The settings can be found in the generated `config/amazon-pay.php` configuration file.
```php
(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,
];
```## Usage
```dotenv
# .env
AMAZON_PAY_SANDBOX=true
AMAZON_PAY_MERCHANT_ID=ABC123DEF456XY
AMAZON_PAY_STORE_ID=amzn1.application-oa2-client.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AMAZON_PAY_PUBLIC_KEY_ID=ABC123DEF456XYZ789IJK000
AMAZON_PAY_PRIVATE_KEY=keys/private.pem
AMAZON_PAY_REGION=us
AMAZON_PAY_LANGUAGE=en_US
AMAZON_PAY_CURRENCY_CODE=USD
``````php
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'),
],
];
``````html
amazon.Pay.renderButton('#AmazonPayButton', @json($button));
```
## Testing
You may use the `AmazonPay` facade's `fake` method to apply the mock response.
```php
'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
```