piatkowski / przelewy24-php
用于使用P24 REST API的简单类
0.0.1
2023-01-19 10:34 UTC
Requires
- php: >=7.4
README
使用新的REST API实现Przelewy24支付功能的简单PHP类。
先决条件
- PHP >= 7.4
- cURL扩展
- 无其他依赖...
安装
composer require piatkowski/przelewy24-php
使用示例
使用授权数据创建新的P24客户端实例
$client = new \Przelewy24\Przelewy24( [ 'merchantId' => '...', 'posId' => '...', 'crc' => '...', 'reportKey' => '...', // API KEY 'sandbox' => true, ] );
注册新交易。这是最低要求选项。您可以使用更多参数(从P24文档)
$transaction = $client->transaction( [ 'sessionId' => '...', 'amount' => '...', 'currency' => 'PLN', 'description' => '...', 'email' => '...', 'urlReturn' => '...', 'urlStatus' => '...' ] );
获取支付URL
$transaction->getRedirectUrl();
创建接收P24 API通知的端点
// get incoming data from php://input $notification = $client->receiveNotification();
或
// create Notification object from raw data $notification = $client->createNotification([ 'sessionId' => '...', 'amount' => '...', 'orderId' => '...', 'currency' => '...', // optional, default: PLN ]);
现在您可以通过传递通知对象来验证交易,并获取API响应数据
$response = $client->verify( $notification ); $status = $response->getStatus(); //HTTP Status Code $data = $response->getData(); //Response data object