sinarajabpour1998 / gateway
v1.5.2
2021-12-22 14:30 UTC
Requires
- php: 7.1.*|7.2.*|7.3.*|7.4.*|8.*
- laravel/framework: 7.*|8.*
- maryamnbyn/vandar-laravel: 1.*
- sinarajabpour1998/parsian_gateway: 1.*
- sinarajabpour1998/pasargad_gateway: 1.*
README
支付网关集成Laravel包。
💎 可用驱动列表
如何安装和配置sinarajabpour1998/gateway包?
⬇️ 安装
composer require sinarajabpour1998/gateway
发布配置文件
php artisan vendor:publish --tag=gateway
迁移表,将事务表添加到数据库
php artisan migrate
📖 如何使用包中的驱动
-
在/config/gateway.php中设置配置
-
使用此示例代码进行请求支付
<?php // Parsian Driver $transaction = Transaction::driver('parsian') ->amount(2000) ->orderId(2000) ->callbackUrl('callback_parsian') ->detail(['auto_redirect' => false]) // if we want to get {token, url} and not auto redirect to Bank Gateway. ->pay(); // Pasargad Driver $transaction = Transaction::driver('pasargad') ->amount(2000) ->orderId(2000) ->callbackUrl('callback_pasargad') ->detail(['auto_redirect' => false]) // if we want to get {token, url} and not auto redirect to Bank Gateway. ->pay(); // Vandar Driver $transaction = Transaction::driver('vandar') ->amount(2000) ->orderId(2000) ->callbackUrl('callback_vandar') ->detail(['auto_redirect' => false]) // if we want to get {token, url} and not auto redirect to Bank Gateway. ->pay();
-
使用此示例代码进行验证支付
// Parsian Driver, that use POST type Route::post('/callback_parsian', function () { $verify = Transaction::driver('parsian')->request(request()->all())->verify(); }); // Pasargad Driver, that use GET type Route::get('/callback_pasargad', function () { $verify = Transaction::driver('pasargad')->request(request()->all())->verify(); }); // Vandar Driver, that use GET type request()->merge(['transId' => $order->transaction->id]); $result = Transaction::driver('vandar')->request(request()->all())->verify();
-
-
-
在您的模型(例如 Payment, Invoice, Order, ...)中使用此Trait(具有许多事务并与事务模型有关)
// Use the Trait use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Sinarajabpour1998\Gateway\Traits\HasTransaction; class Order extends Model { use HasFactory, HasTransaction; } // After add the Trait we can use this relations $order->transaction; // get latest transaction from this order $order->transactions; // get the all transactions for this order $order->pendingTransactions; // get the pending transactions for this order $order->successfulTransactions; // get the successful transactions for this order $order->failedTransactions; // get the failed transactions for this order $order->refundedTransactions; // get the refunded transactions for this order
-
获取事务的父级或此事务属于哪个模型
// Set the namespace of your model in /config/transaction.php 'model' => 'App\Models\Order', // Use relation for get a parent of this transaction $transaction->parent;
-
事务模型的数据和追加
// Default $transaction->id; $transaction->order_id; $transaction->amount; $transaction->driver; $transaction->status; $transaction->ref_no; $transaction->token; $transaction->created_at; $transaction->updated_at; // Appends $transaction->gateway; // Label of driver $transaction->toman; // Get price to taman (convert rial to toman) $transaction->status_label; // Label of status
需求
- PHP v7.0或以上
- Laravel v7.0或以上
- parsian_gateway
- pasargad_gateway
- vandar-laravel