first commit
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Gateway\AsanPardakht;
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class AsanPardakhtApi
|
||||
{
|
||||
public static function getGateway(Transaction $transaction)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$response = Http::connectTimeout(5)->timeout(5)/* ->retry(3, 100, throw: false) */
|
||||
->acceptJson()
|
||||
->contentType('application/json')
|
||||
->withHeaders([
|
||||
'usr' => config('asanpardakht.user'),
|
||||
'pwd' => config('asanpardakht.password'),
|
||||
])
|
||||
->post(config('asanpardakht.url.request'), [
|
||||
'merchantConfigurationId' => config('asanpardakht.merchant_config_id'),
|
||||
'serviceTypeId' => 1,
|
||||
'localInvoiceId' => $transaction->id,
|
||||
'amountInRials' => $transaction->amount * 10,
|
||||
'localDate' => now()->format('Ymd His'),
|
||||
'additionalData' => json_encode([
|
||||
'mobile' => $user->mobile
|
||||
]),
|
||||
'callbackURL' => "https://payment.vada.ir/api/asanpardakht/check-transaction?localInvoiceId=$transaction->id" . (request()->get('platform') ? '&platform=' . request()->get('platform') : ''),
|
||||
'paymentId' => "0",
|
||||
]);
|
||||
|
||||
if (!$response->successful()) {
|
||||
return ["message" => "failed", 'status' => false];
|
||||
}
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'url' => 'https://payment.vada.ir/api/asanpardakht/pay?token=' . $response->json() . '&mobile=' . $user->mobile,
|
||||
'authority' => $response->json()
|
||||
],
|
||||
'status' => true
|
||||
];
|
||||
}
|
||||
|
||||
public static function checkTransaction(Transaction $transaction)
|
||||
{
|
||||
$transactionResponse = self::transactionResult($transaction);
|
||||
if (!$transactionResponse) {
|
||||
return [
|
||||
'status' => false,
|
||||
];
|
||||
}
|
||||
|
||||
self::verify($transactionResponse['payGateTranID']);
|
||||
self::settlement($transactionResponse['payGateTranID']);
|
||||
|
||||
return [
|
||||
'status' => true,
|
||||
];
|
||||
}
|
||||
|
||||
public static function transactionResult(Transaction $transaction)
|
||||
{
|
||||
$response = Http::connectTimeout(5)->timeout(5)->retry(3, 100, throw: false)
|
||||
->acceptJson()
|
||||
->contentType('application/json')
|
||||
->withHeaders([
|
||||
'usr' => config('asanpardakht.user'),
|
||||
'pwd' => config('asanpardakht.password'),
|
||||
])
|
||||
->get(config('asanpardakht.url.result'), [
|
||||
'LocalInvoiceId' => $transaction->id,
|
||||
'MerchantConfigurationId' => config('asanpardakht.merchant_config_id'),
|
||||
]);
|
||||
|
||||
if (!$response->successful()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
public static function verify($payGateTranId)
|
||||
{
|
||||
$response = Http::connectTimeout(5)->timeout(5)->retry(3, 100, throw: false)
|
||||
->acceptJson()
|
||||
->contentType('application/json')
|
||||
->withHeaders([
|
||||
'usr' => config('asanpardakht.user'),
|
||||
'pwd' => config('asanpardakht.password'),
|
||||
])
|
||||
->post(config('asanpardakht.url.verify'), [
|
||||
'merchantConfigurationId' => config('asanpardakht.merchant_config_id'),
|
||||
'payGateTranId' => (int) $payGateTranId,
|
||||
]);
|
||||
|
||||
if (!$response->successful()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
public static function settlement($payGateTranId)
|
||||
{
|
||||
$response = Http::connectTimeout(5)->timeout(5)->retry(3, 100, throw: false)
|
||||
->acceptJson()
|
||||
->contentType('application/json')
|
||||
->withHeaders([
|
||||
'usr' => config('asanpardakht.user'),
|
||||
'pwd' => config('asanpardakht.password'),
|
||||
])
|
||||
->post(config('asanpardakht.url.settlement'), [
|
||||
'merchantConfigurationId' => config('asanpardakht.merchant_config_id'),
|
||||
'payGateTranId' => (int) $payGateTranId,
|
||||
]);
|
||||
|
||||
if (!$response->successful()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $response->json();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Gateway\Digipay;
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class DigiPayApi
|
||||
{
|
||||
public static function getToken()
|
||||
{
|
||||
$token = Cache::remember('digipay_token', 3600, function () {
|
||||
return Http::connectTimeout(5)->timeout(5)->retry(3, 100, throw: false)
|
||||
->asForm()
|
||||
->withHeaders([
|
||||
'Authorization' => 'Basic ' . config('digipay.api_key')
|
||||
])
|
||||
->post(config('digipay.url.login'), [
|
||||
'username' => config('digipay.username'),
|
||||
'password' => config('digipay.password'),
|
||||
'grant_type' => 'password',
|
||||
])['access_token'];
|
||||
});
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
public static function getGateway(Transaction $transaction)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$response = Http::connectTimeout(5)->timeout(5)->retry(3, 100, throw: false)
|
||||
->withToken(self::getToken())
|
||||
->post(config('digipay.url.request'), [
|
||||
'providerId' => $transaction->uuid,
|
||||
'amount' => $transaction->amount * 10,
|
||||
'userType' => 0,
|
||||
'redirectUrl' => 'https://payment.vada.ir/api/digipay/check-transaction',
|
||||
'cellNumber' => $user->mobile,
|
||||
]);
|
||||
|
||||
if (!isset($response['payUrl'])) {
|
||||
return ["message" => "failed", 'status' => false];
|
||||
}
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'url' => $response['payUrl'],
|
||||
'authority' => $response['ticket']
|
||||
],
|
||||
'status' => true
|
||||
];
|
||||
}
|
||||
|
||||
public static function checkTransaction($trackingCode)
|
||||
{
|
||||
$response = Http::retry(3, 100, throw: false)
|
||||
->withToken(self::getToken())
|
||||
->post(str_replace(':trackingCode', $trackingCode, config('digipay.url.verify')));
|
||||
|
||||
if ($response['result']['status'] != 0) {
|
||||
return [
|
||||
'status' => false,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?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,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user