58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Gateway\Zarinpal;
|
|
|
|
use App\Models\Product;
|
|
use App\Models\Transaction;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class ZarinpalApi
|
|
{
|
|
public static function getGateway(Transaction $transaction, $description)
|
|
{
|
|
$user = auth()->user();
|
|
$merchantId = config('zarinpal.merchant_id');
|
|
$response = Http::connectTimeout(2)->timeout(2)->retry(3, 500, throw: false)->post(config('zarinpal.url.request'), [
|
|
'merchant_id' => $merchantId,
|
|
'amount' => $transaction->amount * 10,
|
|
'description' => $description,
|
|
'callback_url' => 'https://payment.vada.ir/api/zarinpal/check-transaction',
|
|
'metadata' => [
|
|
'mobile' => $user->mobile
|
|
],
|
|
]);
|
|
|
|
if ($response['data'] == []) {
|
|
return ["message" => "failed", 'status' => false];
|
|
}
|
|
|
|
return [
|
|
'data' => [
|
|
'url' => config('zarinpal.url.pay') . $response['data']['authority'],
|
|
'authority' => $response['data']['authority']
|
|
],
|
|
'status' => true
|
|
];
|
|
}
|
|
|
|
public static function checkTransaction(Transaction $transaction)
|
|
{
|
|
$merchantId = config('zarinpal.merchant_id');
|
|
$response = Http::retry(3, 500, throw: false)->post(config('zarinpal.url.verify'), [
|
|
'merchant_id' => $merchantId,
|
|
'amount' => $transaction->amount * 10,
|
|
'authority' => $transaction->authority,
|
|
]);
|
|
|
|
if ($response['data'] == [] || $response['data']['code'] == 101) {
|
|
return [
|
|
'status' => false,
|
|
];
|
|
}
|
|
|
|
return [
|
|
'status' => true,
|
|
];
|
|
}
|
|
}
|