alejociro / redirection
用于连接PlacetoPay Checkout服务的库
1.0.15
2023-06-06 20:29 UTC
Requires
- php: >=7.1
- ext-json: *
- guzzlehttp/guzzle: ^5.3|^6.5|^7.0
- psr/log: ^1.0|^2.0|^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^7.5.20|^9.5
- squizlabs/php_codesniffer: 3.*
- symfony/var-dumper: ^4.3
This package is not auto-updated.
Last update: 2024-09-25 02:27:43 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");
}