course-link / omnipay-polish-payments
Omnipay支付处理库的波兰支付驱动程序
0.0.8
2023-05-18 21:51 UTC
Requires
- php: ^8.1
- ext-json: *
- omnipay/common: ~3.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.0
- mockery/mockery: ^1.5
- pestphp/pest: ^1.22
- php-http/guzzle7-adapter: ^1.0
- php-http/message: ^1.13
- php-http/message-factory: ^1.0
- php-http/mock-client: ^1.5
- phpunit/phpunit: ^9.3
README
Omnipay PHP支付处理库的波兰网关支持。
安装
composer require course-link/omnipay-polish-payments
示例
以下是如何使用Omnipay的简单示例。如您所见,Omnipay具有一致、经过深思熟虑的API。尽可能多地,我们尝试抽象各种支付网关之间的差异。
进行购买
require_once __DIR__ . '/vendor/autoload.php'; use Omnipay\Omnipay; use CourseLink\Omnipay\Customer; // Select gateway $gateway = Omnipay::create('imoje'); $gateway = Omnipay::create('Paynow'); $gateway = Omnipay::create('PayU'); $gateway = Omnipay::create('Przelewy24'); $gateway = Omnipay::create('Tpay'); $gateway->initialize([]); // Pass gateway specific options // Send purchase request $response = $gateway->purchase([ // Minimum options to use with any of package gateways 'customer' => new Customer([ 'name' => 'John Doe', 'firstName' => 'John', 'lastName' => 'Doe', 'email' => 'johnny@example.com', 'address' => 'Testowa 25', 'city' => 'Warszawa', 'postcode' => '00-000', 'country' => 'PL' ]), 'language' => 'pl', 'amount' => 99.99, 'description' => 'Ebook', 'client_ip' => '127.0.0.1', 'currency' => 'pln', 'transaction_id' => '1', 'notifyUrl' => 'https://example.com/notify-url', 'paymentMethod' => 150 // required for tpay gateway ])->send(); // Process response if ($response->isSuccessful()) { // Payment was successful // This will never happen, since user will always be redirected to off-site payment gateway print_r($response); } elseif ($response->isRedirect()) { // Redirect to offsite payment gateway $response->redirect(); } else { // Payment failed echo $response->getMessage(); }
接受网关通知
require_once __DIR__ . '/vendor/autoload.php'; use Omnipay\Omnipay; // Select gateway $gateway = Omnipay::create('imoje'); $gateway = Omnipay::create('Paynow'); $gateway = Omnipay::create('PayU'); $gateway = Omnipay::create('Przelewy24'); $gateway = Omnipay::create('Tpay'); $gateway->initialize([]); // Pass gateway specific options $notification = $gateway->acceptNotification(); $status = $notification->getTransactionStatus(); $data = $notification->getData(); $transactionReference = $notification->getTransactionReference(); if ($gateway->supportsCompletePurchase()) { // This is required for Przelewy24 $response = $gateway->completePurchase(array_merge($purchaseOptions, $data))->send(); }
配置
imoje
网关
use Omnipay\Omnipay; $gateway = Omnipay::create('imoje'); $gateway->initialize([ 'merchant_id' => '', 'service_id' => '', 'service_key' => '', 'auth_token' => '', 'test_mode' => false, 'verify_ip_address' => true, 'notification_ip_addresses' => [ ], ]);
购买
$response = $gateway->purchase([ 'customer' => new Customer([ 'firstName' => 'John', //required 'lastName' => 'Doe', // required 'email' => 'johnny@example.com', // required ]), 'language' => 'pl', //required 'amount' => 99.99, //required 'description' => 'Ebook', 'currency' => 'pln', //required 'transaction_id' => '1', //required 'notifyUrl' => 'https://example.com/notify-url', 'returnUrl' => 'https://example.com/return-url', 'cancelUrl' => 'https://example.com/cancel-url', ])->send();
通知
$notification = $gateway->acceptNotification( options: [], // request body, if empty values are taken from httpRequest headers: [] // if empty values are taken from httpRequest ); $status = $notification->getTransactionStatus(); $data = $notification->getData(); $transactionReference = $notification->getTransactionReference();
Paynow
网关
use Omnipay\Omnipay; $gateway = Omnipay::create('Paynow'); $gateway->initialize([ 'api_key' => '', 'signature_key' => '', 'test_mode' => true, ]);
购买
$response = $gateway->purchase([ 'customer' => new Customer([ 'firstName' => 'John', 'lastName' => 'Doe', 'email' => 'johnny@example.com', //required 'phone' => '+48123456789' ]), 'language' => 'pl', 'amount' => 99.99, //required 'description' => 'Ebook', //required 'currency' => 'pln', 'transaction_id' => '1', //required 'returnUrl' => 'https://example.com/return-url', ])->send();
通知
$notification = $gateway->acceptNotification( options: [], // request body, if empty values are taken from httpRequest headers: [] // if empty values are taken from httpRequest ); $status = $notification->getTransactionStatus(); $data = $notification->getData(); $transactionReference = $notification->getTransactionReference();
PayU
Http客户端配置
PayU需要配置Http客户端
'allow_redirects' => false,
网关
use Omnipay\Omnipay; $gateway = Omnipay::create('PayU'); $gateway->initialize([ 'pos_id' => '', 'signature_key' => '', 'client_id' => '', 'client_secret' => '', 'test_mode' => true, 'verify_ip_address' => true, 'notification_ip_addresses' => [ ], ]);
购买
$response = $gateway->purchase([ 'customer' => new Customer([ 'firstName' => 'John', //required 'lastName' => 'Doe', //required 'email' => 'johnny@example.com', //required 'phone' => '+48123456789' ]), 'language' => 'pl', 'amount' => 99.99, //required 'description' => 'Ebook', //required 'client_ip' => '127.0.0.1', //required 'currency' => 'pln', //required 'transaction_id' => '1', 'notifyUrl' => 'https://example.com/notify-url', 'returnUrl' => 'https://example.com/return-url', ])->send();
通知
$notification = $gateway->acceptNotification( options: [], // request body, if empty values are taken from httpRequest headers: [] // if empty values are taken from httpRequest ); $status = $notification->getTransactionStatus(); $data = $notification->getData(); $transactionReference = $notification->getTransactionReference();
Przelewy24
网关
use Omnipay\Omnipay; $gateway = Omnipay::create('Przelewy24'); $gateway->initialize([ 'posId' => '', 'merchantId' => '', 'crcKey' => '', 'reportKey' => '', 'test_mode' => false, 'verify_ip_address' => true, 'notification_ip_addresses' => [ ], ]);
购买
$response = $gateway->purchase([ 'customer' => new Customer([ 'name' => 'John Doe', 'email' => 'johnny@example.com', //required 'address' => 'Testowa 25', 'city' => 'Warszawa', 'postcode' => '00-000', 'phone' => '+48123456789' 'country' => 'PL' //required ]), 'language' => 'pl', 'amount' => 99.99, //required 'description' => 'Ebook', //required 'currency' => 'pln', //required 'transaction_id' => '1', //required 'notifyUrl' => 'https://example.com/notify-url', 'returnUrl' => 'https://example.com/return-url', //required ])->send();
通知
$notification = $gateway->acceptNotification( options: [], // request body, if empty values are taken from httpRequest headers: [] // if empty values are taken from httpRequest ); // Przelewy24 requires to complete purchase after accepting notification $response = $gateway->completePurchase(array_merge($purchaseOptions, $notificationData))->send(); $status = $notification->getTransactionStatus(); $data = $notification->getData(); $transactionReference = $notification->getTransactionReference();
Tpay
网关
use Omnipay\Omnipay; $gateway = Omnipay::create('Tpay'); $gateway->initialize([ 'merchant_id' => '', 'service_id' => '', 'service_key' => '', 'auth_token' => '', 'test_mode' => false, 'verify_ip_address' => true, 'notification_ip_addresses' => [ ], ]);
购买
$response = $gateway->purchase([ 'customer' => new Customer([ 'name' => 'John Doe', //required 'email' => 'johnny@example.com', //required 'address' => 'Testowa 25', 'city' => 'Warszawa', 'postcode' => '00-000', 'phone' => '+48123456789' 'country' => 'PL' ]), 'language' => 'pl', 'amount' => 99.99, //required 'description' => 'Ebook', //required 'currency' => 'pln', //required 'notifyUrl' => 'https://example.com/notify-url', 'returnUrl' => 'https://example.com/return-url', 'cancelUrl' => 'https://example.com/cancel-url', 'paymentMethod' => 150 // required ])->send();
通知
当使用Tpay时:无论交易状态(tr_status)如何,只要所有验证都正确,商家系统应打印TRUE响应。
$notification = $gateway->acceptNotification( options: [], // request body, if empty values are taken from httpRequest headers: [] // if empty values are taken from httpRequest ); $status = $notification->getTransactionStatus(); $data = $notification->getData(); $transactionReference = $notification->getTransactionReference();