66 lines
2.0 KiB
PHP
66 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Repos\Payment\Card;
|
|
|
|
use App\Models\Payment\OnlinePaymentHistory;
|
|
use App\Repos\Payment\OnlinePaymentRepo;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
trait HandlesCardOrderPayments
|
|
{
|
|
/**
|
|
* Check payment payment visa master
|
|
*
|
|
* @param Request $request
|
|
* @return array<string, bool|string>
|
|
*/
|
|
public static function checkCardOrderPayment(Request $request): array
|
|
{
|
|
// Find order from history
|
|
$paymentHistory = OnlinePaymentHistory::where('orderId', $request->orderId)->first();
|
|
|
|
// Find related resource
|
|
$resource = (new $paymentHistory->online_paymantable_type)->find(id: $paymentHistory->online_paymantable_id);
|
|
|
|
// If resource could not be found or does not exist, then inform it via logs
|
|
if (! $resource) {
|
|
static::logResourceNotFound($request, $paymentHistory);
|
|
|
|
return static::resourceNotFound();
|
|
}
|
|
|
|
$resource->load('branch');
|
|
|
|
$bank_branch = $resource->branch;
|
|
|
|
$response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [
|
|
'language' => 'ru',
|
|
'orderId' => $request->orderId,
|
|
'userName' => $bank_branch->billing_username,
|
|
'password' => $bank_branch->billing_password,
|
|
]);
|
|
|
|
$payment_status = $response['ErrorCode'] == '0';
|
|
$returnURL = $resource->panelUrl('index');
|
|
|
|
if ($payment_status) {
|
|
$resource->update([
|
|
'paid' => true,
|
|
]);
|
|
|
|
$paymentHistory->update([
|
|
'paymentStatus' => OnlinePaymentRepo::PAID,
|
|
]);
|
|
|
|
return static::successfulPaymentResponse($paymentHistory, $bank_branch, $resource, $returnURL);
|
|
}
|
|
|
|
$paymentHistory->update([
|
|
'paymentStatus' => OnlinePaymentRepo::FAILED,
|
|
]);
|
|
|
|
return static::failedPaymentResponse($paymentHistory, $bank_branch, $resource, $returnURL);
|
|
}
|
|
}
|