faizpay / php-payment-sdk
用于操作FaizPay支付API的SDK。
v1.0.4
2021-09-05 14:23 UTC
Requires
- ext-json: *
- firebase/php-jwt: ^5.2
Requires (Dev)
- phpunit/phpunit: ^8
README
用于操作FaizPay支付API的SDK。
文档
完整文档可以在以下地址找到: https://documentation.faizpay.com
要求
PHP 7.0.0及更高版本。
安装
您可以通过Composer安装绑定。运行以下命令
composer require faizpay/php-payment-sdk
要使用绑定,请使用Composer的自动加载
require_once('vendor/autoload.php');
依赖项
入门指南
简单的新的支付看起来像
use FaizPay\PaymentSDK\Connection; use FaizPay\PaymentSDK\Payment; $connection = Connection::createConnection( $terminalId = '8afa74ae-6ef9-48bb-93b2-9fe8be53db50', $terminalSecret = '55d7d5ed-be22-4321-bb3f-aec8524d8be2' ); $payment = Payment::createPayment( $connection, $orderId = 'AA-11', $amount = '10.00' ); $payment->process();
Webhook / 通知处理
use FaizPay\PaymentSDK\Connection; use FaizPay\PaymentSDK\NotificationHandler; $connection = Connection::createConnection($terminalId, $terminalSecret); $notificationHandler = NotificationHandler::createNotificationHandler($connection, $token = $_POST['token']); // extract the order id $orderId = $notificationHandler->getOrderID(); // fetch the order from your database $data = findFromDatabase($orderId); // if order is not found in system if (checkIfEntryFound($data)) { echo "Invalid Token"; die(); } // validate if the requested payment matches with token if (!$notificationHandler->validateAmount($data['amount'])) { echo "Invalid Token"; die(); } // all checks are passed - update the database to mark payment complete updateDatabase($orderId, ['completed' => true]);
可选:为新支付设置用户或预选提供商
use FaizPay\PaymentSDK\Connection; use FaizPay\PaymentSDK\Payment; use FaizPay\PaymentSDK\Provider; use FaizPay\PaymentSDK\User; $connection = Connection::createConnection($terminalId, $terminalSecret); $payment = Payment::createPayment( $connection, $orderId = 'AA-11', $amount = '10.00' ); $user = User::createUser( $email = 'john.doe@test.com', $firstName = 'John', $lastName = 'Doe', $contactNumber = '07000845953' ); $payment->setUser($user); $provider = Provider::createProvider( $providerId = 'lloyds-bank', $sortCode = '123456', $accountNumber = '12345678' ); $payment->setProvider($provider);