sber
This commit is contained in:
73
app/Repos/Payment/Sber/HandlesSberPeyments.php
Normal file
73
app/Repos/Payment/Sber/HandlesSberPeyments.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repos\Payment\Sber;
|
||||
|
||||
use App\Models\Payment\OnlinePaymentHistory;
|
||||
use App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem;
|
||||
use App\Repos\Payment\OnlinePaymentRepo;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
trait HandlesSberPeyments
|
||||
{
|
||||
/**
|
||||
* Check payment payment visa master
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return array<string, bool|string>
|
||||
*/
|
||||
public static function checkPaymentSber(Request $request): array
|
||||
{
|
||||
// Find order from history
|
||||
$paymentHistory = OnlinePaymentHistory::where('orderId', $request->orderId)->first();
|
||||
|
||||
// Find related resource
|
||||
$resource = SberPaymentOrderItem::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;
|
||||
|
||||
$response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [
|
||||
'language' => 'ru',
|
||||
'orderId' => $request->orderId,
|
||||
'userName' => $bank_branch->billing_sber_username,
|
||||
'password' => $bank_branch->billing_sber_password,
|
||||
]);
|
||||
|
||||
$payment_status = $response['ErrorCode'] == '0';
|
||||
|
||||
$returnURL = url('/work-place/resources/nova-sber-payment-orders/'.$resource->sber_payment_order_id);
|
||||
|
||||
if ($payment_status) {
|
||||
$resource->update([
|
||||
'payer_name' => $response['cardholderName'],
|
||||
'payer_card' => $response['Pan'],
|
||||
'paid' => true,
|
||||
]);
|
||||
|
||||
$paymentHistory->update([
|
||||
'paymentStatus' => OnlinePaymentRepo::PAID,
|
||||
]);
|
||||
|
||||
return static::successfulPaymentResponse($paymentHistory, $bank_branch, $resource, $returnURL);
|
||||
}
|
||||
|
||||
$resource->update([
|
||||
'payer_name' => $response['cardholderName'] ?? '-',
|
||||
'payer_card' => $response['Pan'] ?? '-',
|
||||
]);
|
||||
|
||||
$paymentHistory->update([
|
||||
'paymentStatus' => OnlinePaymentRepo::FAILED,
|
||||
]);
|
||||
|
||||
return static::failedPaymentResponse($paymentHistory, $bank_branch, $resource, $returnURL);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user