maree / paymob
使用 paymob 支付服务进行支付的包
dev-main
2024-04-30 17:24 UTC
This package is auto-updated.
Last update: 2024-09-30 18:21:07 UTC
README
安装
您可以通过 Composer 安装此包。
composer require maree/paymob
使用
php artisan vendor:publish --provider="maree\Paymob\PaymobServiceProvider" --tag="paymob"
然后更改您的 paymob 配置文件 config/paymob.php
"mode" => "test",//live "API_KEY" => "" , "IFRAME_ID" => "" , "INTEGRATION_ID_TEST" => "", "INTEGRATION_ID_LIVE" => "",
使用
- 支持 [ visa - master - mada ]
use Maree\Paymob\Paymob; $items = [ [ 'name' => 'pen', 'amount_cents' => 10, 'description' => "Pen Invoice", 'quantity' => 1, ], ]; $billing_data = [ "first_name" => 'mohamed', "phone_number" => '01002700084', "email" => 'm7mdmaree26@gmail.com', "last_name" => 'maree', "apartment" => "10", "floor" => "2", "street" => "25 elrahman", "building" => "40", "shipping_method" => "NA", "postal_code" => "21532", "city" => "Alexandria", "country" => "EG", "state" => "elnzha", ] ; $response = Paymob::checkout($amount_cents = 100 , $items,$billing_data ,$delivery_needed = false); //save $response['checkout_id'] in transactions history table return redirect()->to($response['redirect_url'])->send();
注意
- 在您的 paymob 账户路由中定义(回调)结账返回响应 URL,例如: https://mysite.com/payment-response
- 为响应 URL 'payment-response' 创建路由,例如:Route::get('payment-response', 'PaymentsController@paymentResponse')->name('payment-response');
- 为结账响应创建函数 'paymentResponse'
- 使用该函数检查支付是否失败或成功
在 'paymentresponse' 函数中使用
use Maree\Paymob\Paymob; $response = Paymob::checkoutResponseStatus(); $result = $response['result']; //get checkout_id to update transaction history or order status to paid $checkout_id = $result['order'];
返回响应如下
['key' => 'success' ,'msg' => 'checkout success' ,'result' => $payment_data ]
或
['key' => 'fail' , 'msg' => 'checkout failed','result' => $payment_data]
注意:您可以使用响应中的数据将交易保存到数据库中 - 'data' 键包含 'amount' 和交易 ID 等参数
- 测试卡详细信息
- 卡号:2223000000000007
- CVV:100
- 到期日期:01/39
- 卡名:Test Family
- 自定义 ECI:留空
- 自定义 CAVV:留空