elnurxf /
Instamojo API v1.1 驱动程序,用于 Omnipay 3.0 PHP 支付处理库
dev-master
2020-04-30 13:38 UTC
Requires
- php: >=5.4
Requires (Dev)
- omnipay/tests: dev-master
This package is auto-updated.
Last update: 2024-09-29 05:42:39 UTC
README
Instamojo 驱动程序,用于 Omnipay 3.0 PHP 支付处理库
Omnipay 是一个与框架无关、多网关的 PHP 5.3+ 支付处理库。本包实现了 Instamojo Payments API v1.1。
安装
Omnipay 通过 Composer 安装。要安装,只需运行
composer require elnurxf/omnipay-instamojo
购买
use Omnipay\Omnipay; // Setup payment gateway $gateway = Omnipay::create('Instamojo'); $gateway->setApiKey('abc123'); $gateway->setAuthToken('abc123'); // OR $gateway->initialize([ 'api_key' => 'abc123', 'auth_token' => 'abc123', 'testMode' => true, ]); // Send purchase request $response = $gateway->purchase( [ 'amount' => '10.00', 'purpose' => 'Instamojo Payment', 'email' => 'elnurxf@gmail.com', 'buyer_name' => 'Elnur Akhundov', 'purpose' => 'Instamojo Payment', ] )->send(); // Process response if ($response->isSuccessful() && $response->isRedirect()) { // Redirect to offsite payment gateway // print_r($response->getData()); // echo $response->getTransactionStatus(); $response->redirect(); } else { // Request failed echo $response->getMessage(); }
完成购买
// Send complete purchase request $response = $gateway->completePurchase( [ 'transactionReference' => $_GET['payment_id'], ] )->send(); // Process response if ($response->isSuccessful()) { // Request was successful print_r($response->getData()); echo $response->getTransactionStatus(); } else { // Request failed echo $response->getMessage(); }
退款
// Send refund request $response = $gateway->refund( [ 'transactionReference' => $payment_id, ] )->send(); // Process response if ($response->isSuccessful()) { // Request was successful print_r($response->getData()); echo $response->getTransactionStatus(); } else { // Request failed echo $response->getMessage(); }
获取支付请求
// Send fetch payment request $response = $gateway->fetchPaymentRequest( [ 'transactionReference' => $payment_request_id, ] )->send(); // Process response if ($response->isSuccessful()) { // Request was successful print_r($response->getData()); echo $response->getTransactionStatus(); } else { // Request failed echo $response->getMessage(); }
Webhook
use Omnipay\Omnipay; // Setup payment gateway $gateway = Omnipay::create('Instamojo'); $gateway->setSalt('abc123'); // Payment notification request $response = $gateway->acceptNotification()->send(); // Process response if ($response->isSuccessful()) { // Request was successful print_r($response->getData()); echo $response->getTransactionReference(); echo $response->getTransactionStatus(); } else { // Request failed echo $response->getMessage(); }