sber
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Repos\Payment;
|
||||
|
||||
use App\Models\Branch\Branch;
|
||||
use App\Models\Payment\OnlinePaymentHistory;
|
||||
use App\Repos\Payment\Sber\HandlesSberPeyments;
|
||||
use App\Repos\Payment\VisaMaster\HandlesVisaMasterPayments;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
@@ -13,6 +14,7 @@ use Laravel\Nova\Makeable;
|
||||
class OnlinePaymentRepo
|
||||
{
|
||||
use HandlesVisaMasterPayments;
|
||||
use HandlesSberPeyments;
|
||||
use Makeable;
|
||||
|
||||
/**
|
||||
@@ -182,7 +184,7 @@ class OnlinePaymentRepo
|
||||
*
|
||||
* @return array<string, bool|string>
|
||||
*/
|
||||
public static function successfulPaymentResponse($paymentHistory, $bank_branch, $resource): array
|
||||
public static function successfulPaymentResponse($paymentHistory, $bank_branch, $resource, $returnURL): array
|
||||
{
|
||||
return [
|
||||
'success' => true,
|
||||
@@ -190,7 +192,7 @@ class OnlinePaymentRepo
|
||||
'pnr' => $paymentHistory->orderNumber,
|
||||
'branch_name' => $bank_branch->name,
|
||||
'price_amount' => convertToOriginalFormat($paymentHistory->amount).' TMT',
|
||||
'return_url' => url('/work-place/resources/nova-visa-master-payment-orders/'.$resource->visa_master_payment_order_id),
|
||||
'return_url' => $returnURL,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -201,7 +203,7 @@ class OnlinePaymentRepo
|
||||
* @param $bank_branch
|
||||
* @param $resource
|
||||
*/
|
||||
public static function failedPaymentResponse($paymentHistory, $bank_branch, $resource)
|
||||
public static function failedPaymentResponse($paymentHistory, $bank_branch, $resource, $returnURL)
|
||||
{
|
||||
return [
|
||||
'success' => false,
|
||||
@@ -209,7 +211,7 @@ class OnlinePaymentRepo
|
||||
'pnr' => $paymentHistory->orderNumber,
|
||||
'branch_name' => $bank_branch->name,
|
||||
'price_amount' => convertToOriginalFormat($paymentHistory->amount).' TMT',
|
||||
'return_url' => url('/work-place/resources/nova-visa-master-payment-orders/'.$resource->visa_master_payment_order_id),
|
||||
'return_url' => $returnURL,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,7 @@ trait HandlesVisaMasterPayments
|
||||
]);
|
||||
|
||||
$payment_status = $response['ErrorCode'] == '0';
|
||||
$returnURL = url('/work-place/resources/nova-visa-master-payment-orders/'.$resource->visa_master_payment_order_id);
|
||||
|
||||
if ($payment_status) {
|
||||
$resource->update([
|
||||
@@ -54,7 +55,7 @@ trait HandlesVisaMasterPayments
|
||||
'paymentStatus' => OnlinePaymentRepo::PAID,
|
||||
]);
|
||||
|
||||
return static::successfulPaymentResponse($paymentHistory, $bank_branch, $resource);
|
||||
return static::successfulPaymentResponse($paymentHistory, $bank_branch, $resource, $returnURL);
|
||||
}
|
||||
|
||||
$resource->update([
|
||||
@@ -66,6 +67,6 @@ trait HandlesVisaMasterPayments
|
||||
'paymentStatus' => OnlinePaymentRepo::FAILED,
|
||||
]);
|
||||
|
||||
return static::failedPaymentResponse($paymentHistory, $bank_branch, $resource);
|
||||
return static::failedPaymentResponse($paymentHistory, $bank_branch, $resource, $returnURL);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user