paynl / sdk
2.2.0
2023-11-14 10:31 UTC
Requires
- ext-curl: *
- ext-json: *
- php-curl-class/php-curl-class: ^8.3||^9.0
Requires (Dev)
- php-coveralls/php-coveralls: ^1.0
- phpunit/phpunit: ^4.8
Suggests
- ext-simplexml: *
- dev-master
- 2.2.0
- v2.1.1
- v2.1.0
- dev-feature/2.x-dev / 2.0.x-dev
- v2.0.1
- v2.0.0
- 1.6.7
- 1.6.6
- v1.6.5
- v1.6.3
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.20
- v1.5.19
- 1.5.18
- v1.5.17
- v1.5.16
- v1.5.15
- v1.5.14
- 1.5.13
- v1.5.12
- v1.5.11
- v1.5.10
- v1.5.9
- v1.5.8
- v1.5.7
- v1.5.6
- v1.5.5
- v1.5.4
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.1
- v1.4.0
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.10
- v1.2.9
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.15
- v1.1.14
- v1.1.13
- v1.1.12
- v1.1.11
- v1.1.10
- v1.1.9
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.7
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-version1
This package is auto-updated.
Last update: 2024-08-27 07:57:34 UTC
README
Pay.nl PHP SDK
安装
此SDK使用composer。
Composer是PHP中依赖管理的工具。它允许您声明项目依赖的库,并为您管理(安装/更新)它们。
有关如何使用/安装composer的更多信息,请访问:https://github.com/composer/composer
要将Pay.nl PHP SDK安装到您的项目中,只需
$ composer require paynl/sdk
不使用composer的安装
如果您没有使用composer的经验,可以不使用composer使用SDK。
您可以在项目的发布页面下载zip文件。
- 下载包的zip文件(SDKvx.x.x.zip)。
- 解压zip文件内容,并将vendor目录上传到您的服务器。
- 在您的项目中,需要文件vendor/autoload.php
- 现在您可以在项目中使用SDK
要求
PAY. PHP SDK已测试到PHP版本8.2,并需要PHP cURL扩展。
快速入门和示例
设置配置
require __DIR__ . '/vendor/autoload.php'; # Replace tokenCode apitoken and serviceId with your own. \Paynl\Config::setTokenCode('AT-####-####'); \Paynl\Config::setApiToken('****************************************'); \Paynl\Config::setServiceId('SL-####-####');
获取可用的支付方式
require __DIR__ . '/vendor/autoload.php'; \Paynl\Config::setTokenCode('AT-####-####'); \Paynl\Config::setApiToken('****************************************'); \Paynl\Config::setServiceId('SL-####-####'); $paymentMethods = \Paynl\Paymentmethods::getList(); var_dump($paymentMethods);
开始交易
require __DIR__ . '/vendor/autoload.php'; \Paynl\Config::setTokenCode('AT-####-####'); \Paynl\Config::setApiToken('****************************************'); \Paynl\Config::setServiceId('SL-####-####'); $result = \Paynl\Transaction::start(array( # Required 'amount' => 10.00, 'returnUrl' => Paynl\Helper::getBaseUrl().'/return.php', # Optional 'currency' => 'EUR', 'exchangeUrl' => Paynl\Helper::getBaseUrl().'/exchange.php', 'paymentMethod' => 10, 'bank' => 1, 'description' => 'demo betaling', 'testmode' => 1, 'extra1' => 'ext1', 'extra2' => 'ext2', 'extra3' => 'ext3', 'products' => array( array( 'id' => 1, 'name' => 'een product', 'price' => 5.00, 'tax' => 0.87, 'qty' => 1, ), array( 'id' => 2, 'name' => 'ander product', 'price' => 5.00, 'tax' => 0.87, 'qty' => 1, ) ), 'language' => 'EN', 'ipaddress' => '127.0.0.1', 'invoiceDate' => new DateTime('2016-02-16'), 'deliveryDate' => new DateTime('2016-06-06'), // in case of tickets for an event, use the event date here 'enduser' => array( 'initials' => 'T', 'lastName' => 'Test', 'gender' => 'M', 'birthDate' => new DateTime('1990-01-10'), 'phoneNumber' => '0612345678', 'emailAddress' => 'test@test.nl', ), 'address' => array( 'streetName' => 'Test', 'houseNumber' => '10', 'zipCode' => '1234AB', 'city' => 'Test', 'country' => 'NL', ), 'invoiceAddress' => array( 'initials' => 'IT', 'lastName' => 'ITEST', 'streetName' => 'Istreet', 'houseNumber' => '70', 'zipCode' => '5678CD', 'city' => 'ITest', 'country' => 'NL', ), )); # Save this transactionid and link it to your order $transactionId = $result->getTransactionId(); # Redirect the customer to this url to complete the payment $redirect = $result->getRedirectUrl();
在返回页面上,将用户重定向到感谢页或返回结账
require __DIR__ . '/vendor/autoload.php'; \Paynl\Config::setTokenCode('AT-####-####'); \Paynl\Config::setApiToken('****************************************'); $transactionId = $_REQUEST['orderId']; $transaction = \Paynl\Transaction::status($transactionId); # Manual transfer transactions are always pending when the user is returned if( $transaction->isPaid() || $transaction->isPending()) { # Redirect to thank you page } elseif($transaction->isCanceled()) { # Redirect back to checkout }
在交换脚本中,处理订单
require __DIR__ . '/vendor/autoload.php'; \Paynl\Config::setTokenCode('AT-####-####'); \Paynl\Config::setApiToken('****************************************'); $transactionId = $_REQUEST['order_id']; $transaction = \Paynl\Transaction::status($transactionId); if($transaction->isPaid() || $transaction->isAuthorized()) { # Process the payment } elseif($transaction->isCanceled()) { # Payment canceled, restock items } # Always respond with TRUE| echo "TRUE| "; # Optionally you can send a message after TRUE|, you can view these messages in the logs. # https://admin.pay.nl/logs/payment_state echo ($transaction->isPaid() || $transaction->isAuthorized())?'Paid':'Not paid';
故障转移网关
在断电的情况下,设置故障转移网关如下
use Paynl\Config; use Paynl\Transaction; require __DIR__ . '/vendor/autoload.php'; Config::setTokenCode('AT-####-####'); Config::setApiToken('****************************************'); Config::setServiceId('SL-####-####'); # Setting Failover gateway (for available cores, call Config::getCores()) Config::setCore( Config::CORE2 ); # Or for SDK versions lower then 1.6.7, use: Config::setApiBase('https://rest.achterelkebetaling.nl'); $requiredArguments = []; // See: Start a transaction example $result = Transaction::start($requiredArguments);
测试
请运行vendor/bin/phpunit --bootstrap vendor/autoload.php tests/
以测试应用程序