sunaoka / laravel-paypayopa-sdk-php
PayPay's Open Payment API Service Provider for Laravel
v1.1.0
2024-08-06 05:51 UTC
Requires
- php: ^8.1
- illuminate/support: ^10.0 || ^11.0
- paypayopa/php-sdk: ^2.0
Requires (Dev)
- laravel/pint: ^1.17.0
- orchestra/testbench: ^8.23 || ^9.0
- phpstan/phpstan: ^1.11
This package is auto-updated.
Last update: 2024-11-06 06:21:53 UTC
README
Installation
composer require sunaoka/laravel-paypayopa-sdk-php
Configurations
php artisan vendor:publish --tag=paypay-config
The settings can be found in the generated config/paypay.php
configuration file.
<?php return [ 'api_key' => env('PAYPAY_API_KEY'), 'api_secret' => env('PAYPAY_API_SECRET'), 'merchant_id' => env('PAYPAY_MERCHANT_ID'), 'production_mode' => (bool) env('PAYPAY_PRODUCTION_MODE', false), ];
Usage
use PayPay\OpenPaymentAPI\Models\CreateQrCodePayload; $payload = new CreateQrCodePayload(); $payload->setMerchantPaymentId('merchant_id'); $payload->setCodeType('ORDER_QR'); $response = \PayPay::code()->createQRCode($payload);
Testing
You may use the PayPay
facade's fake
method to apply the mock handler.
For more information on mock handlers, please refer to the Testing Guzzle Clients.
use GuzzleHttp\Psr7\Response; use PayPay\OpenPaymentAPI\Models\CreateQrCodePayload; $fakeResponse = [ 'resultInfo' => [ 'code' => 'SUCCESS', 'message' => 'Success', 'codeId' => '08100001', ], 'data' => [ 'codeId' => '04-ABCDEFGHIJKLMNOP', 'url' => 'https://example.com/00000000ABCDEFGHIJKLMNOP', 'expiryDate' => 1719965100, 'merchantPaymentId' => 'Merchant Payment ID', 'amount' => [ 'amount' => 1000, 'currency' => 'JPY', ], 'orderDescription' => 'Description', 'orderItems' => [[ 'name' => 'Item Name', 'quantity' => 1000, 'unit_price' => [ 'amount' => 1, 'currency' => 'JPY', ], ]], 'codeType' => 'ORDER_QR', 'requestedAt' => 1719964800, 'redirectType' => 'WEB_LINK', 'isAuthorization' => false, 'deeplink' => 'paypay://payment?link_key=https%3A%2F%2Fexample.com%2F00000000ABCDEFGHIJKLMNOP', ], ]; \PayPay::fake([ new Response(201, body: json_encode($fakeResponse, JSON_THROW_ON_ERROR)), ]); $payload = new CreateQrCodePayload(); $payload->setMerchantPaymentId('merchant_id'); $payload->setCodeType('ORDER_QR'); $response = \PayPay::code()->createQRCode($payload);