shahzadthathal / skipcash
Skipcash支付网关集成。
README
安装包
composer require shahzadthathal/skipcash
将Skipcash提供者添加到config/app.php中的providers
数组。
Shahzadthathal\Skipcash\Providers\SkipcashProvider::class
更新.env文件
SKIPCASH_CLIENT_ID=''
SKIPCASH_KEY_ID=''
SKIPCASH_KEY_SECRET=''
SKIPCASH_WEBHOOK_KEY=''
SKIPCASH_URL='https://skipcashtest.azurewebsites.net'
#SKIPCASH_URL='https://api.skipcash.app'
如果您想发布config skipcash helper,请执行以下命令。否则,请忽略此命令。它将在config目录下创建skipcash.php helper。
php artisan vendor:publish --tag=config
运行迁移。
这将创建skipcash_logs
表,我们将在此表中保存来自支付网关的日志。
php artisan migrate
使用此包有两种方法。
1. 第一种方法
您可以在控制器中使用内置的Trait
use Shahzadthathal\Skipcash\Traits\SkipCashPaymentGatewayTrait;
use Shahzadthathal\Skipcash\Models\SkipcashLogs;
class YourPaymentController extends Controller{
use SkipCashPaymentGatewayTrait;
//Generate payment link
//http://127.0.0.1:8000/payment/generate-payment-link
$this->generatePaymentLinkSkipcash(Request $request){
//Your custom transaciton id or order id
$transactionId = 'xyz12345';
//Sequance of the fields is important, don't move keys
$requestData = [
"Uid" =>\Str::uuid()->toString(),
"KeyId"=> env('SKIPCASH_KEY_ID'),
"Amount" => "40.00",
'FirstName' => 'Muhammad',
'LastName' => 'Shahzad',
'Phone' => '+971507520175',
'Email' => 'shahzadthathal@gmail.com',
"TransactionId" => $transactionId,
"Custom1" => 'Custom1 anything',
// Add other required fields... i.e. Custom2
];
$responseSkipcashResponse = $this->generatePaymentLinkSkipcash($requestData);
$responseSkipcashArr = json_decode($responseSkipcashResponse, true);
if(isset($responseSkipcashArr['resultObj'])){
$payUrl = $responseSkipcashArr['resultObj']['payUrl'];
header('Content-Type: application/json; charset=utf-8');
header("Location:".$payUrl);
exit;
}
}
//Validate payment
//http://127.0.0.1:8000/payment/gateway/response/skipcash
//Please update above url in SkipCash payment portal in Return URL input box.
$this->validatePaymentSkipcash(Request $request){
$payment_id = $request->get('id');
//Save logs
$currentUrlWithParams = url()->full();
$skipcashLogs = new SkipcashLogs();
$skipcashLogs->user_id = \Auth::user()->id??0;
$skipcashLogs->logs = 'returning '.$currentUrlWithParams;
$skipcashLogs->save();
//Verify payment
$responseSkipcash = $this->validatePaymentSkipcash($payment_id);
$responseSkipcashArr = json_decode($responseSkipcash, true);
$resultObj = $responseSkipcashArr['resultObj'];
//Payment success
if(isset($resultObj['statusId']) && $resultObj['statusId']===2){
//Your custom transaciton id or order id from the payment gateway
$transactionId = $resultObj['transactionId'];
dd('transactionId '.$transactionId.' is verifid payment please update your order.');
}
}
//Webhook
//http://127.0.0.1:8000/payment/gateway/response/skipcash/webhook
//Please update above url in SkipCash payment portal in Webhook URL input box.
public function paymentGatewayResponseSkipcashWebhook(Request $request){
try{
$data = $request->all();
$skipcashLogs = new SkipcashLogs();
$skipcashLogs->user_id = 0;
$skipcashLogs->logs = 'webhook '.$data;
$skipcashLogs->save();
return response()->json(['message' => 'Success'], 200);
}catch(\Exception $e){
throw $e;
}
}
}
有关更多方法,请参阅\vendor\shahzadthathal\skipcash\src\Http\Controllers\SkipCashController.php
2. 第二种方法
php artisan vendor:publish --tag=routes
上述命令将创建一个skipcash.php路由文件。请将skipcash.php包含在web.php路由文件的末尾。
require __DIR__.'/skipcash.php';
创建一个新的控制器,例如YourSkipCashController.php
,并在skipcash.php路由文件中更新它。将\vendor\shahzadthathal\skipcash\src\Http\Controllers\SkipCashController.php
的内容复制并粘贴到您的控制器中。
现在,您可以通过这些路由生成支付链接并验证支付。
http://127.0.0.1:8000/payment/generate-payment-link
http://127.0.0.1:8000/payment/gateway/response/skipcash
http://127.0.0.1:8000/payment/gateway/response/skipcash/webhook