willvin/przelewy24

一个简单的php支付库,实现了przelewy24支付网关。

2.0.0 2023-07-27 11:41 UTC

This package is auto-updated.

Last update: 2024-09-18 21:42:16 UTC


README

一个实现przelewy24支付网关的简单composer包。

willvin的Przelewy24支付处理库

Software License Codacy Badge

有关Przelewy24 API的更多信息,请参阅手册

安装

此网关可以使用Composer安装

$ composer require willvin/przelewy24

示例

启动交易

require_once __DIR__ . '/vendor/autoload.php';

use willvin\Przelewy24\Gateway;

$gateway = new Gateway();

$gateway->initialize([
    'merchantId' => 'YOUR MERCHANT ID HERE',
    'posId'      => 'YOUR POS ID HERE',
    'crc'        => 'YOUR CRC KEY HERE',
    'testMode'   => true, // Sets P24 gateway to use sandbox url
]);

$gateway->setPostData([
    'p24_transactionId' => 'Transaction ID',
    'p24_amount'        => 'Amount',
    'p24_description'   => 'Description',
    'p24_email'         => 'Email',
    'p24_session_id'    => $gateway->getSessionId('Transaction ID'), //pass your transaction id here or use this $gateway->getSessionId($orderId) function to generate the id
    'p24_currency'      => 'Currency',
    'p24_country'       => 'Country',
    'p24_url_return'    => 'Url to redirect user, after payment',
    'p24_url_status'    => 'Transaction status callback url',
]);

$res = $gateway->trnRegister(); // ruturns a code like this D35CD73C0E-37C7B5-059083-E8EFB7FA96

if(!$res['error']){
    $res = $gateway->trnRequest($res['token']); // trigger the payment
} else {
    echo 'Transaction failed.';
}

验证交易

require_once __DIR__ . '/vendor/autoload.php';

use willvin\Przelewy24\Gateway;

$gateway = new Gateway();

$rawData = file_get_contents('php://input');
parse_str($rawData, $p24Data);

if(!empty($p24Data)){
	$gateway->initialize([
		'merchantId' => 'YOUR MERCHANT ID HERE',
		'posId'      => 'YOUR POS ID HERE',
		'crc'        => 'YOUR CRC KEY HERE',
		'testMode'   => true, // Sets P24 gateway to use sandbox url
	]);

	$gateway->setPostData([
		'p24_session_id' => $p24Data['p24_session_id'],
		'p24_order_id' => $p24Data['p24_order_id'],
		'p24_amount' => $p24Data['p24_amount'],
		'p24_currency' => $p24Data['p24_currency']
	]);
	$res = $gateway->trnVerify(); // Use to verify the payment sent to your callback url
}

用法

初始化

require_once __DIR__ . '/vendor/autoload.php';

use willvin\Przelewy24\Gateway;

$gateway = new Gateway();

$gateway->initialize([
    'merchantId' => 'YOUR MERCHANT ID HERE',
    'posId'      => 'YOUR POS ID HERE',
    'crc'        => 'YOUR CRC KEY HERE',
    'testMode'   => true, // Sets P24 gateway to use sandbox url
]);

require_once __DIR__ . '/vendor/autoload.php';

use willvin\Przelewy24\Gateway;

$gateway = new Gateway('YOUR MERCHANT ID HERE', 'YOUR POS ID HERE', 'YOUR CRC KEY HERE', true);

设置POST数据

$gateway->setPostData([
    'p24_transactionId' => 'Transaction ID',
    'p24_amount'        => 'Amount',
    'p24_description'   => 'Description',
    'p24_email'         => 'Email',
    'p24_session_id'    => 'Session ID',
    'p24_currency'      => 'Currency',
    'p24_country'       => 'Country',
    'p24_url_return'    => 'Url to redirect user, after payment',
    'p24_url_status'    => 'Transaction status callback url',
    'p24_channel'       => $gateway::P24_CHANNEL_ALL, // you have the following channels available P24_CHANNEL_CC, P24_CHANNEL_BANK_TRANSFERS, P24_CHANNEL_MANUAL_TRANSFER, P24_CHANNEL_ALL_METHODS_24_7, P24_CHANNEL_USE_PREPAYMENT, P24_CHANNEL_ALL
]);

$gateway->addValue('p24_transactionId', 'Transaction ID');
$gateway->addValue('p24_amount', 'Amount');
$gateway->addValue('p24_description', 'Description');
$gateway->addValue('p24_email', 'Email');
$gateway->addValue('p24_session_id', 'Session ID');
$gateway->addValue('p24_currency', 'Currency');
$gateway->addValue('p24_country', 'Country');
$gateway->addValue('p24_url_return', 'Url to redirect user, after payment';
$gateway->addValue('p24_url_status', 'Transaction status callback url';
$gateway->addValue('p24_channel', $gateway::P24_CHANNEL_ALL);// you have the following channels available P24_CHANNEL_CC, P24_CHANNEL_BANK_TRANSFERS, P24_CHANNEL_MANUAL_TRANSFER, P24_CHANNEL_ALL_METHODS_24_7, P24_CHANNEL_USE_PREPAYMENT, P24_CHANNEL_ALL

其他可用的POST数据字段

p24_address

p24_language

p24_client

p24_city

p24_order_id

p24_method

p24_time_limit

p24_shipping

p24_wait_for_result

p24_encoding

p24_transfer_label

p24_phone

p24_zip

#### Shopping cart details, where X is a number 1-100 (optional 2)

p24_name_X

p24_description_X

p24_quantity_X

p24_price_X

p24_number_X

有关更多详细信息,您可以阅读przelewy24文档

注册交易

$res = $gateway->trnRegister(); // ruturns a token like this D35CD73C0E-37C7B5-059083-E8EFB7FA96

启动交易

$res = $gateway->trnRequest('Pass transaction token here'); // trigger the payment with your token

验证交易

$res = $gateway->trnVerify(); // Use to verify the payment sent to your callback url

生成会话ID

$gateway->getSessionId('Transaction ID');

支持

如果您认为您发现了一个错误,请使用GitHub问题跟踪器报告,或者更好的是,分支库并提交拉取请求。

点击“关注和星标”以在更新此存储库时收到电子邮件通知。并且也欢迎贡献。

您可以通过以下地址捐赠以支持此项目。

Buy Me A Coffee

PayPal: 捐赠

Patreon: 成为赞助者!

YouTube: 订阅willvin

安全

如果您发现任何与安全相关的问题,请通过info@willvin.com发送电子邮件,而不是使用问题跟踪器。

鸣谢

许可

MIT许可(MIT)。请参阅许可文件以获取更多信息。