85 lines
3.0 KiB
PHP
85 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Repos\Payment\VisaMaster;
|
|
|
|
use App\Models\Payment\OnlinePaymentHistory;
|
|
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrderItem;
|
|
use App\Repos\Payment\OnlinePaymentRepo;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
trait HandlesVisaMasterPayments
|
|
{
|
|
/**
|
|
* Check payment payment visa master
|
|
*
|
|
* @param Request $request
|
|
*
|
|
* @return array{success: bool, title: string, pnr: string, branch_name: string, price_amount: string, return_url: string}
|
|
*/
|
|
public static function checkPaymentVisaMaster(Request $request): array
|
|
{
|
|
// Find order from history
|
|
$paymentHistory = OnlinePaymentHistory::where('orderId', $request->orderId)->first();
|
|
|
|
// Find related resource
|
|
$resource = VisaMasterPaymentOrderItem::where('online_payment_history_id', $paymentHistory->id)->first();
|
|
|
|
// If resource could not be found or does not exist, then inform it via logs
|
|
if (! $resource) {
|
|
static::logResourceNotFound($request, $paymentHistory);
|
|
|
|
return static::resourceNotFound();
|
|
}
|
|
|
|
$bank_branch = $resource->parent->branch;
|
|
$returnURL = url('/work-place/resources/nova-visa-master-payment-orders/'.$resource->visa_master_payment_order_id);
|
|
|
|
$response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatusExtended.do', [
|
|
'language' => 'ru',
|
|
'orderId' => $request->orderId,
|
|
'userName' => $bank_branch->billing_visa_master_username,
|
|
'password' => $bank_branch->billing_visa_master_password,
|
|
]);
|
|
|
|
if ($response->failed()) {
|
|
return static::failedPaymentResponse($paymentHistory, $bank_branch, $resource, $returnURL);
|
|
}
|
|
|
|
$payment_status = $response['errorCode'] == '0';
|
|
$cardholderName = $response['cardAuthInfo']['cardholder§§Name'] ?? '-';
|
|
$cardPan = $response['cardAuthInfo']['Pan'] ?? '-';
|
|
|
|
if ($payment_status) {
|
|
$resource->update([
|
|
'payer_name' => $cardholderName,
|
|
'payer_card' => $cardPan,
|
|
'paid' => true,
|
|
]);
|
|
|
|
$paymentHistory->update([
|
|
'paymentStatus' => OnlinePaymentRepo::PAID,
|
|
'cardholderName' => $cardholderName,
|
|
'pan' => $cardPan,
|
|
'api_response' => $response->body(),
|
|
]);
|
|
|
|
return static::successfulPaymentResponse($paymentHistory, $bank_branch, $resource, $returnURL);
|
|
}
|
|
|
|
$resource->update([
|
|
'payer_name' => $cardholderName,
|
|
'payer_card' => $cardPan,
|
|
]);
|
|
|
|
$paymentHistory->update([
|
|
'paymentStatus' => OnlinePaymentRepo::FAILED,
|
|
'cardholderName' => $cardholderName,
|
|
'pan' => $cardPan,
|
|
'api_response' => $response->body(),
|
|
]);
|
|
|
|
return static::failedPaymentResponse($paymentHistory, $bank_branch, $resource, $returnURL);
|
|
}
|
|
}
|