zea / rest-library
连接到 PlacetoPay Rest api 的库
dev-main
2022-10-12 20:37 UTC
Requires
- php: >=7.4
- ext-json: *
- guzzlehttp/guzzle: ^6.5|^7.0
- psr/log: ^1.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: 3.*
- symfony/var-dumper: ^4.3
This package is not auto-updated.
Last update: 2024-09-26 06:16:19 UTC
README
使用此代码,您可以快速连接到 PlacetoPay Rest 服务。
要查看更多关于其工作方式的详细示例,请参阅示例和文档
安装
从您的项目中使用 composer
composer require zea/rest-library
或者如果您只想运行本项目中的示例,运行 "composer install" 以加载供应商自动加载
用法
创建一个包含该实例所需配置的对象
$placetopay = new Zea\RestLibrary\PlacetoPay([ 'login' => 'YOUR_LOGIN', // Provided by PlacetoPay 'tranKey' => 'YOUR_TRANSACTIONAL_KEY', // Provided by PlacetoPay 'baseUrl' => 'https://THE_BASE_URL_TO_POINT_AT', 'timeout' => 10, // (optional) 15 by default ]);
创建一个新的支付请求以获取支付响应
只需提供必要的支付信息,如果成功,您将获得处理响应,在此示例中,我们使用必须提供的最小信息,要查看完整结构,请参阅文档或示例
$reference = 'COULD_BE_THE_PAYMENT_ORDER_ID";
$request = [
'payment' => [
'reference' => $reference,
'description' => 'Testing payment',
'amount' => [
'currency' => 'USD',
'total' => 120,
],
],
'instrument' => [
'card' => [
'number' => '36545400000008',
'expiration' => '12/20',
'cvv' => '123',
'installments' => 2
]
],
'ipAddress' => '127.0.0.1',
'userAgent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36',
];
$response = $placetopay->process($request);
if ($response->isSuccessful()) {
$response->toArray()['response'];
} else {
// There was some error so check the message and log it
$response->status()->message();
}
获取之前做出的支付信息
$response = $placetopay->query('THE_INTERNAL_REFERENCE_TO_QUERY');
if ($response->isSuccessful()) {
if ($response->status()->isApproved()) {
// The payment has been approved
}
} else {
// There was some error with the connection so check the message
print_r($response->status()->message() . "\n");
}