sin迪巴德 / za因卡什
Requires (Dev)
- firebase/php-jwt: ^5.4
This package is auto-updated.
Last update: 2024-09-07 16:03:48 UTC
README
Laravel #1 Zaincash支付网关
这是一个用于支付网关集成的Laravel软件包。本软件包支持Laravel 5.5+
。
安装
该软件包可以通过Composer安装
$ composer require sindibad/zaincash
配置
如果您没有使用Laravel 5.5
或更高版本,则需要添加提供者和别名。(否则跳过此部分)
在您的config/app.php
文件中添加以下两行。
// In your providers array. 'providers' => [ ... sindibad\zaincash\provider\ZaincashServiceProvider::class, ], // In your aliases array. 'aliases' => [ ... 'ZainCash' => Zaincash\Payment\facades\ZainCash::class, ],
然后运行php artisan vendor:publish
以在您的配置目录中发布config/payment.php
文件,以及视图目录中的zaincash/callback.blade.php
文件。
在配置文件中,您可以设置使用所有付款的初始配置。但是,您也可以在运行时更改这些值,例如eloquent_storage
、callback_url
、lang
、eloquent_storage
。
然后填写zaincashGateway.php
文件的凭证
"eloquent_storage" => true, // Once enabled, package will create transaction_zaincash table(through zaincash:migrate command) and fill it's values when new transaction is submitted "callback_url" => "default", // default, <your website domain>/[your custom segment] for callback response "merchant_id" => "", "token" => '', //Secret key for jwt encode "msisdn" => "", "lang" => "en", //ar,en "production" => false,//Once set to true production url's will be used otherwise test url's are consumed ... ]
如何使用
发票
您的Invoice
包含您的付款详情,因此我们首先讨论Invoice
类。它主要用于交易初始化目的;
处理发票
在执行任何操作之前,您需要使用Invoice
类来创建发票。请注意,如果您计划使用EloquentStorage,请使用以下Artisan命令
php artisan zaincash:migrate
在您的代码中,使用它如下
// At the top of the file. use sindibad\zaincash\facades\ZainCash; ... // Create new invoice. $invoice = new Invoice; // Set invoice amount. $invoice->amount(1000); // Set orderId if available, so you can get the value back on callback $invoice->setOrderId($request->orderid); // Set additional description or project type $invoice->setServiceType("mydescription"); // As mentioned this can be set either in config file or directly in Invoice accessor // !Note that once you set it here this will be priority and not the config file values $invoice->setLang("en"); // Callback url for callback response you can also set it to `default` for testing etc. $invoice->setCallbackUrl("https://:8000/customcallback"); // As mentioned before enabling EloquentStorage will create transaction_zaincash table inside your main db with transaction records $invoice->setEnableElequentStorage(true); // This parameter is set for main zaincash view files. it will set back button text $invoice->setBackBtnText("back"); // Redirect url for main views back button $invoice->setBackBtnUrl("https://:8000/"); // you could also add extra parameters to invoice and get them back in callback response //you need to define a key for your Extra,note that you will use this key to receive your extra in callback $invoice->appendExtra("key" , "value"); //Finally, use pay to initialize your transaction $pay = $invoice->pay(); //You can access redirect url for payment within ['url'] index $redirect_url=$pay['url']; //Get error messages $invoice->getErrors();
回调响应
此方法用于检索网关回调响应。它以JWT令牌作为输入参数。默认情况下,回调响应输入名称为token
,但您可以更改它,如果源回调不同。如果令牌未在请求中设置,则状态将设置为'取消'
处理回调响应
$payment= ZainCash::callBackResponse();
$payment
包含以下参数
amount
:交易现金金额status
:成功、失败、取消、重复、无效令牌orderId
:交易的orderIdpayment
:有效载荷数据operationId
:操作IDconfig
:默认配置设置extras
:Invoice中设置的整个额外集serviceType
:服务类型initDate
:以时间戳格式表示的交易时间backButtonText
:返回按钮文本backButtonLink
:返回按钮链接errorMessage
:如果有错误信息transaction
:此参数在将eloquent存储设置为true时返回
您也可以使用以下方式为每个参数使用getter方法
$payment= ZainCash::callBackResponse(); $payment->getStatus(); //when you're using getExtra method remember to pass default value as second parameter even tough it is optional $response->getExtra("user_id" , -1);
收到的付款事件
您还可以使用zaincash内部事件来接收付款信息。创建一个新事件,并在您的EventListener中定义PaymentReceivedEvent::class
。在您的事件中,使用它如下
public function handle($event) { $event->getPayment(); //Logic }