moeen-basra / omnipay-jazzcash
Jazzcash 驱动程序,用于 Omnipay PHP 支付处理库
1.0.2
2023-12-24 07:47 UTC
Requires
- guzzlehttp/guzzle: ^7.8
- omnipay/common: ^3.2
- php-http/guzzle7-adapter: ^1.0
Requires (Dev)
- http-interop/http-factory-guzzle: ^1.2
- larapack/dd: ^1.1
- omnipay/tests: ^3|^4
- squizlabs/php_codesniffer: ^3
README
Jazz Jazzcash 网关,用于 Omnipay PHP 支付处理库
Omnipay 是一个不依赖框架的多网关支付处理库,适用于 PHP 5.3+。本包实现了 Omnipay 的 jazzcash 支持。
安装
通过 Composer
$ composer require moeen-basra/omnipay-jazzcash
使用方法
此网关提供了与 jazzcash 主机页面集成的无缝集成。
购买请求
use Omnipay\Omnipay; /** @var \Omnipay\Jazzcash\Gateway $gateway */ $gateway = Omnipay::create('Jazzcash'); // initialize with array $gateway->initialize([ 'merchantId' => 'your-merchant-id', 'password' => 'your-password', 'secretKey' => 'your-secret-key', ]); // or individual properties setter $gateway->setMerchantId('your-merchant-id') ->setPassword('your-password') ->setSecretKey('your-secret-key'); // set the test mode if needed $gateway->setTestMode(true); $date = CarbonImmutable::now('Asia/Karachi'); try { $parameters = [ [ 'paymentMethod' => 'MWALLET', // 'MWALLET' | 'OTC' | 'MPAY' 'transactionTimestamp' => new \DateTime(), // make sure not past date also check your server timezone 'transactionExpiryTimestamp' => new \DateTime(), // cab be future date 'billReference' => (string) $date->timestamp, 'description' => 'Test Order', 'amount' => '20', 'language' => 'EN', 'currency' => 'PKR', 'transactionId' => $date->timestamp, 'extra' => [ 'field_1' => 'value_1', 'field_2' => 'value_2', 'field_3' => 'value_3', 'field_4' => 'value_4', 'field_5' => 'value_5' ], 'returnUrl' => 'https://exmpale.com/return', ] ]; $response = $gateway->purchase($parameters)->send(); // var_dump($response->getData()); if ($response->isSuccessful() && $response instanceof RedirectIn) { // do the redirect here you can do it auto using the following return statement // return $response->getRedirectResponse(); } else { // handle failed response } } catch (\Throwable $exception) { var_dump($exception); }
注意: 检查此类以获取更多重定向逻辑 PurchaseResponse.php
完成购买
use Omnipay\Omnipay; $gateway = Omnipay::create('Jazzcash'); // initialize with array $gateway->initialize([ 'merchantId' => 'your-merchant-id', 'password' => 'your-password', 'secretKey' => 'your-secret-key', ]); try { $response = $gateway->completePurchase()->send(); if (!$response->isSuccessful()) { // handle failed logic } // always good option to cross-check the response data with gateway $inquiryResponse = $gateway->fetchTransaction([ 'transactionReference' => $response->getData()['pp_TxnRefNo'], ]) // see next step for more details } catch (\Throwable $exception) { var_dump($exception); } $response = $gateway->completePurchase()
查询请求
use Omnipay\Omnipay; $gateway = Omnipay::create('Jazzcash'); // initialize with array $gateway->initialize([ 'merchantId' => 'your-merchant-id', 'password' => 'your-password', 'secretKey' => 'your-secret-key', ]); try { $parameters = [ 'transactionReference' => '<pp_TxnRefNo>', ]; $response = $gateway->fetchTransaction($parameters)->send(); // var_dump($response->getData()); if ($response->isSuccessful()) { if ($response->getData()['pp_Status'] === 'Complete') { // the transaction is success } else { } // handle success response } else { // handle failed response } } catch (\Throwable $exception) { var_dump($exception); }
注意: 检查 FetchTransactionResponse.php 以获取更多响应状态
注意: 您可以检查测试 Mock 以获取示例响应数据。
许可证
本包遵循 MIT 许可证 发布。有关详细信息,请参阅 LICENSE 文件。
联系方式
您可以通过此邮箱联系我 moeen.basra@gamil.com