dnetix/redirection
连接到PlacetoPay Checkout服务的库
2.1.1
2023-05-24 17:45 UTC
Requires
- php: >=7.4
- ext-json: *
- guzzlehttp/guzzle: ^6.5|^7.0
- psr/log: ^1.0|^2.0|^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: 3.*
- symfony/var-dumper: ^4.3
This package is auto-updated.
Last update: 2024-09-24 20:40:08 UTC
README
使用此代码,您可以快速连接到PlacetoPay Checkout服务。
为了查看更多关于其工作方式的示例,请参阅示例和文档
从版本1迁移
- 将设置参数
url
更改为baseUrl
- 如果您已为rest设置了
timeout
,则将其更改为设置的根 - 抛出
PlacetoPayServiceException
而不是返回ERROR状态响应
安装
使用项目中的composer
composer require dnetix/redirection
或者,如果您只想运行此项目中的示例,运行"composer install"以加载供应商自动加载
用法
创建一个具有该实例所需配置的对象
$placetopay = new Dnetix\Redirection\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 ]);
创建新的付款请求以获取会话付款URL
只需提供所需的付款信息,如果成功,您将获得一个进程URL;在这个例子中,我们使用需要提供的最小信息,要查看完整的结构,请参阅文档或示例
$reference = 'COULD_BE_THE_PAYMENT_ORDER_ID";
$request = [
'payment' => [
'reference' => $reference,
'description' => 'Testing payment',
'amount' => [
'currency' => 'USD',
'total' => 120,
],
],
'expiration' => date('c', strtotime('+2 days')),
'returnUrl' => 'http://example.com/response?reference=' . $reference,
'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->request($request);
if ($response->isSuccessful()) {
// STORE THE $response->requestId() and $response->processUrl() on your DB associated with the payment order
// Redirect the client to the processUrl or display it on the JS extension
$response->processUrl();
} else {
// There was some error so check the message and log it
$response->status()->message();
}
获取之前创建的会话的信息
$response = $placetopay->query('THE_REQUEST_ID_TO_QUERY');
if ($response->isSuccessful()) {
// In order to use the functions please refer to the Dnetix\Redirection\Message\RedirectInformation class
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");
}