Skip to content

Commit

Permalink
Merge branch 'release/v1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sunaoka committed Mar 13, 2024
2 parents f602128 + 57e0a69 commit dda6aef
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 76 deletions.
24 changes: 20 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,51 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
laravel: [ 6, 7, 8, 9, 10 ]
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
laravel: [ 6, 7, 8, 9, 10, 11 ]
exclude:
- php: 7.2
laravel: 8
- php: 7.2
laravel: 9
- php: 7.2
laravel: 10
- php: 7.2
laravel: 11
- php: 7.3
laravel: 9
- php: 7.3
laravel: 10
- php: 7.3
laravel: 11
- php: 7.4
laravel: 9
- php: 7.4
laravel: 10
- php: 7.4
laravel: 11
- php: 8.0
laravel: 10
- php: 8.0
laravel: 11
- php: 8.1
laravel: 6
- php: 8.1
laravel: 7
- php: 8.1
laravel: 11
- php: 8.2
laravel: 6
- php: 8.2
laravel: 7
- php: 8.2
laravel: 8
- php: 8.3
laravel: 6
- php: 8.3
laravel: 7
- php: 8.3
laravel: 8

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

Expand All @@ -54,7 +70,7 @@ jobs:
tools: composer:v2

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install dependencies
run: |
Expand All @@ -69,7 +85,7 @@ jobs:
run: vendor/bin/phpunit --coverage-clover=coverage.xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
Expand Down
3 changes: 3 additions & 0 deletions .phpstan/classAliases.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

class_alias(\Sunaoka\AmazonPay\Laravel\Facade\AmazonPay::class, 'AmazonPay');
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![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-6.x%20%7C%207.x%20%7C%208.x%20%7C%209.x%20%7C%2010.x-red)](https://laravel.com/)
[![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)

Expand All @@ -29,7 +29,7 @@ The settings can be found in the generated `config/amazon-pay.php` configuration
<?php

return [
'sandbox' => (bool)env('AMAZON_PAY_SANDBOX', 'true'),
'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'),
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"php": "^7.2 || ^8.0",
"ext-json": "*",
"amzn/amazon-pay-api-sdk-php": "^2.0",
"illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0"
"illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0"
},
"require-dev": {
"orchestra/testbench": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0",
"orchestra/testbench": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
"phpstan/phpstan": "^1.9"
},
"autoload": {
Expand Down
24 changes: 12 additions & 12 deletions config/amazon-pay.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php

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'),
'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'),
'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,
Expand Down
8 changes: 8 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
parameters:

bootstrapFiles:
- .phpstan/classAliases.php

level: 9

checkMissingIterableValueType: false

editorUrl: 'file://%%file%%:%%line%%'

editorUrlTitle: 'file://%%file%%:%%line%%'

paths:
- src/
- tests/
42 changes: 16 additions & 26 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Client extends \Amazon\Pay\API\Client
];

/**
* @param array|null $config
* @param array|null $config
*
* @throws Exception
*/
Expand All @@ -51,7 +51,7 @@ public function __construct($config = null)
throw new LogicException('The "region" is required');
}

if (!in_array(strtolower($config['region']), $this->availableRegions, true)) {
if (! in_array(strtolower($config['region']), $this->availableRegions, true)) {
throw new LogicException("{$config['region']} is not a valid region");
}

Expand All @@ -61,8 +61,6 @@ public function __construct($config = null)
/**
* Get Amazon Pay script URL
*
* @return string
*
* @throws Exception
*/
public function getAmazonPayScript(): string
Expand All @@ -77,29 +75,27 @@ public function getAmazonPayScript(): string
}

/**
* @param string $method
* @param string $urlFragment
* @param string|array $payload
* @param array|null $headers
* @param array|null $queryParams
*
* @return array
* @param string $method
* @param string $urlFragment
* @param string|array $payload
* @param array|null $headers
* @param array|null $queryParams
*
* @throws Exception
*/
public function apiCall($method, $urlFragment, $payload, $headers = null, $queryParams = null): array
{
if ($this->fakeResponse !== null) {
$response = [
'status' => $this->fakeStatus,
'method' => $method,
'url' => $urlFragment,
'headers' => $headers ?? [],
'request' => is_array($payload) ? json_encode($payload) : $payload,
'response' => json_encode($this->fakeResponse),
'status' => $this->fakeStatus,
'method' => $method,
'url' => $urlFragment,
'headers' => $headers ?? [],
'request' => is_array($payload) ? json_encode($payload) : $payload,
'response' => json_encode($this->fakeResponse),
'request_id' => Str::uuid()->toString(),
'retries' => 0,
'duration' => 0,
'retries' => 0,
'duration' => 0,
];

$this->fakeResponse = null;
Expand All @@ -110,13 +106,7 @@ public function apiCall($method, $urlFragment, $payload, $headers = null, $query
return parent::apiCall($method, $urlFragment, $payload, $headers, $queryParams); // @codeCoverageIgnore
}

/**
* @param array|null $response
* @param int $status
*
* @return void
*/
public function fake(array $response = null, int $status = 200): void
public function fake(?array $response = null, int $status = 200): void
{
$this->fakeResponse = $response;
$this->fakeStatus = $status;
Expand Down
10 changes: 4 additions & 6 deletions src/Facade/AmazonPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@
/**
* @method static \Mockery\MockInterface spy() Convert the facade into a Mockery spy.
* @method static \Mockery\MockInterface partialMock() Initiate a partial mock on the facade.
* @method static \Mockery\Expectation shouldReceive(string|array ...$methodNames) Initiate a mock expectation on the facade.
* @method static void swap($instance) Hotswap the underlying instance behind the facade.
* @method static void clearResolvedInstance(string $name) Clear a resolved facade instance.
* @method static void clearResolvedInstances() Clear all of the resolved instances.
* @method static \Mockery\Expectation shouldReceive(string|array ...$methodNames) Initiate a mock expectation on the facade.
* @method static void swap($instance) Hotswap the underlying instance behind the facade.
* @method static void clearResolvedInstance(string $name) Clear a resolved facade instance.
* @method static void clearResolvedInstances() Clear all of the resolved instances.
*
* @mixin Client
*/
class AmazonPay extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor(): string
{
Expand Down
5 changes: 3 additions & 2 deletions src/Provider/AmazonPayServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ class AmazonPayServiceProvider extends ServiceProvider
public function register(): void
{
$this->mergeConfigFrom(
dirname(__DIR__, 2) . '/config/amazon-pay.php',
dirname(__DIR__, 2).'/config/amazon-pay.php',
'amazon-pay'
);

$this->app->singleton('AmazonPay', function ($app) {
$config = $app->make('config')->get('amazon-pay');

return new Client($config);
});

Expand All @@ -34,7 +35,7 @@ public function boot(): void
{
if ($this->app->runningInConsole()) {
$this->publishes(
[dirname(__DIR__, 2) . '/config/amazon-pay.php' => $this->app->configPath('amazon-pay.php')],
[dirname(__DIR__, 2).'/config/amazon-pay.php' => $this->app->configPath('amazon-pay.php')],
'amazon-pay-config'
);
}
Expand Down
35 changes: 19 additions & 16 deletions tests/AmazonPayServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,46 @@ public function testGetAmazonPayScript(): void
public function testFake(): void
{
$fakeResponse = [
'refundId' => 'S01-5105180-3221187-R022311',
'chargeId' => 'S01-5105180-3221187-C056351',
'refundAmount' => [
'amount' => '14.00',
'currencyCode' => 'USD'
'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'
'softDescriptor' => 'Descriptor',
'creationTimestamp' => '20190714T155300Z',
'statusDetails' => [
'state' => 'RefundInitiated',
'reasonCode' => null,
'reasonDescription' => null,
'lastUpdatedTimestamp' => '20190714T155300Z',
],
'releaseEnvironment' => 'Sandbox',
];

\AmazonPay::fake($fakeResponse);

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

$actual = \AmazonPay::createRefund($payload, []);

/** @var array{refundId: string} $response */
$response = json_decode($actual['response'], true);

self::assertSame($fakeResponse['refundId'], $response['refundId']);


\AmazonPay::fake($fakeResponse);

$actual = \AmazonPay::getRefund('S01-5105180-3221187-R022311');

/** @var array{refundId: string} $response */
$response = json_decode($actual['response'], true);

self::assertSame($fakeResponse['refundId'], $response['refundId']);
Expand Down
18 changes: 12 additions & 6 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
class TestCase extends \Orchestra\Testbench\TestCase
{
/**
* @inerhitDoc
* Get package providers.
*
* @param \Illuminate\Foundation\Application $app
* @return array<int, class-string<\Illuminate\Support\ServiceProvider>>
*/
protected function getPackageProviders($app): array
{
Expand All @@ -20,7 +23,10 @@ protected function getPackageProviders($app): array
}

/**
* @inerhitDoc
* Get package aliases.
*
* @param \Illuminate\Foundation\Application $app
* @return array<string, class-string<\Illuminate\Support\Facades\Facade>>
*/
protected function getPackageAliases($app): array
{
Expand All @@ -30,15 +36,15 @@ protected function getPackageAliases($app): array
}

/**
* @inerhitDoc
* @param \Illuminate\Foundation\Application|array{config: \Illuminate\Config\Repository} $app
*/
protected function defineEnvironment($app): void
{
$app['config']->set('amazon-pay', [
'public_key_id' => 'public_key_id',
'private_key' => 'private_key',
'sandbox' => true,
'region' => 'us',
'private_key' => 'private_key',
'sandbox' => true,
'region' => 'us',
]);
}
}

0 comments on commit dda6aef

Please sign in to comment.