smartpay-co / sdk-php
Smartpay PHP SDK 提供了从用 PHP 编写的应用程序中轻松访问 Smartpay API 的功能。
v0.8.0
2023-12-18 07:43 UTC
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
Smartpay PHP 库
Smartpay PHP 库提供了从用 PHP 编写的应用程序中轻松访问 Smartpay API 的功能。
文档
要求
- PHP 5.6+
- Smartpay
API 密钥 & 密码
。您可以在设置 > 凭据
页面上找到您的凭证,该页面位于您的 仪表板 上。
安装
安装 Composer
Composer 是 PHP 项目的依赖管理器。
从他们的网站下载 Composer: https://getcomposer.org/download/
如果您正在使用 macos 进行开发,并且使用 homebrew,您可以使用以下命令安装 Composer
brew install composer
将软件包安装到您的仓库中
composer install smartpay-co/sdk-php
使用方法
该软件包需要使用您自己的 API 密钥进行配置,您可以在仪表板上找到它们。
$api = new \Smartpay\Api('<YOUR_SECRET_KEY>', '<YOUR_PUBLIC_KEY>')
创建结账会话
您可以在 API 文档 中找到请求有效负载的描述和需求。
$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' ];
通过使用带有请求有效负载的 checkoutSession
方法创建结账会话。
$session = $api->checkoutSession($payload);
然后,您可以通过调用 redirectUrl
方法将客户重定向到会话 URL
$session->redirectUrl()
测试
安装依赖项
composer i
在文件夹中运行测试
./vendor/bin/phpunit tests
许可
该软件包作为开源软件在 MIT 许可证 的条款下提供。