smartpay-co / sdk-php
The Smartpay PHP SDK offers easy access to Smartpay API from applications written in PHP.
Installs: 6 194
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: >= 5.6
- ext-json: *
- caseyamcl/guzzle_retry_middleware: ^2.2
- guzzlehttp/guzzle: >=6.5
- ircmaxell/random-lib: ^1.2
- tuupola/base62: >= 1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: >= 2.19.3
- phpunit/phpunit: >= 5.7
- squizlabs/php_codesniffer: ^3.3
- yoast/phpunit-polyfills: ^1.0
README
Explore the docs »
Report Bug
·
Request Feature
Smartpay PHP Library
The Smartpay PHP library offers easy access to Smartpay API from applications written in PHP.
Documentation
Requirements
- PHP 5.6+
- Smartpay
API keys & secrets
. You can find your credential at thesettings > credentials
page on your dashboard.
Installation
Install Composer
Composer is a dependency manager for PHP projects.
Download Composer from their website: https://getcomposer.org/download/
If you are using macos to develop with homebrew, you can use the command to install Composer:
brew install composer
Install package to your repository:
composer install smartpay-co/sdk-php
Usage
The package needs to be configured with your own API keys, you can find them on your dashboard.
$api = new \Smartpay\Api('<YOUR_SECRET_KEY>', '<YOUR_PUBLIC_KEY>')
Create Checkout session
You can find the description and requirement for request payload in API Document.
$payload = [ 'items' => [ [ 'name' => 'オリジナルス STAN SMITH', 'amount' => 1000, 'currency' => 'JPY', 'quantity' => 1, ], [ 'currency' => 'JPY', 'amount' => 500, 'name' => 'Merchant special discount', 'kind' => 'discount' ], [ 'currency' => 'JPY', 'amount' => 100, 'name' => 'explicit taxes', 'kind' => 'tax' ] ], 'customerInfo' => [ 'accountAge' => 20, 'email' => 'merchant-support@smartpay.co', 'firstName' => '田中', 'lastName' => '太郎', 'firstNameKana' => 'たなか', 'lastNameKana' => 'たろう', 'address' => [ 'line1' => '北青山 3-6-7', 'line2' => '青山パラシオタワー 11階', 'subLocality' => '', 'locality' => '港区', 'administrativeArea' => '東京都', 'postalCode' => '107-0061', 'country' => 'JP', ], 'dateOfBirth' => '1985-06-30', 'gender' => 'male', ], 'shippingInfo' => [ 'line1' => '北青山 3-6-7', 'line2' => '青山パラシオタワー 11階', 'subLocality' => '', 'locality' => '港区', 'administrativeArea' => '東京都', 'postalCode' => '107-0061', 'country' => 'JP', ], 'reference' => 'order_ref_1234567', 'successUrl' => 'https://docs.smartpay.co/example-pages/checkout-successful', 'cancelUrl' => 'https://docs.smartpay.co/example-pages/checkout-canceled' ];
Create a checkout session by using checkoutSession
method with your request payload.
$session = $api->checkoutSession($payload);
Then, you can redirect your customer to the session url by calling redirectUrl
method:
$session->redirectUrl()
Test
Install dependencies
composer i
Run test in the folder
./vendor/bin/phpunit tests
License
The package is available as open source under the terms of the MIT License.