This commit is contained in:
2025-09-10 18:48:09 +05:00
parent ef7c30a235
commit 50996ddacd
8 changed files with 203 additions and 23 deletions

View File

@@ -5,6 +5,7 @@ use App\Models\Payment\OnlinePaymentHistory;
use App\Models\System\Roles\Permission;
use App\Models\System\Verification;
use App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem;
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrderItem;
use App\Nova\Resources\Order\Card\CardTransaction\Actions\DownloadCardTransaction;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request as GuzzleRequest;
@@ -521,7 +522,7 @@ function getSberCredentials(SberPaymentOrderItem $item): array
];
}
function syncWithAzatAPI(SberPaymentOrderItem $orderItem): array
function syncSberWithAzatAPI(SberPaymentOrderItem $orderItem): array
{
$result = getSberCredentials($orderItem);
@@ -572,7 +573,120 @@ function syncWithAzatAPI(SberPaymentOrderItem $orderItem): array
$message = 'Error';
if (isset($systemResponse->msgSys)) {
$message .= ' ' . $systemResponse->msgSys;
$message .= ' '.$systemResponse->msgSys;
}
return [
'error' => $message,
'type' => 'modal',
];
}
$orderItem->update([
'synced_with_system' => true,
]);
return [
'success' => true,
'type' => 'modal',
];
}
/**
* Get Sber credentials for a given payment item.
*
* @param SberPaymentOrderItem $item
* @return array{username?: string, password?: string, onlinePaymentResource?: OnlinePaymentHistory, relatedResource?: mixed, error?: string, type?: 'danger'|'modal'}
*/
function getVisaCredentials(VisaMasterPaymentOrderItem $item): array
{
/** @var \App\Models\Payment\OnlinePaymentHistory|null $onlinePaymentResource */
$onlinePaymentResource = OnlinePaymentHistory::find($item->online_payment_history_id);
if (! $onlinePaymentResource) {
return ['error' => 'Online payment resource tapylmady', 'type' => 'danger'];
}
$relatedResource = (new $onlinePaymentResource->online_paymantable_type)
->find(id: $onlinePaymentResource->online_paymantable_id);
if (! $relatedResource) {
return ['error' => 'Bu resource tapylmady', 'type' => 'danger'];
}
$relatedResource->loadMissing(['branch']);
if (! $relatedResource->branch) {
return ['error' => 'Şahamça bilen birikdirilmedik', 'type' => 'danger'];
}
$username = $relatedResource->branch->billing_visa_master_username;
$password = $relatedResource->branch->billing_visa_master_password;
if (empty($username) || empty($password)) {
return ['error' => 'Ulanyjy ady bilen açar sözi gabat gelmedi', 'type' => 'modal'];
}
return [
'username' => $username,
'password' => $password,
'onlinePaymentResource' => $onlinePaymentResource,
'relatedResource' => $relatedResource,
];
}
function syncVisaWithAzatAPI(VisaMasterPaymentOrderItem $orderItem): array
{
$result = getVisaCredentials($orderItem);
if (isset($result['error'])) {
return $result;
}
/** @var \App\Models\Payment\OnlinePaymentHistory $onlinePaymentResource */
$onlinePaymentResource = $result['onlinePaymentResource'];
/** @var \App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder $sberPaymentOrder */
$visaPaymentOrder = $result['relatedResource'];
$response = checkOnlinePayment($onlinePaymentResource->orderId, $result['username'], $result['password']);
if ($response['errorCode'] != 0) {
return [
'error' => $response['errorMessage'],
'type' => 'modal',
];
}
$systemRawResponse = syncWithBankSystem(
online_payment_order_uuid: $onlinePaymentResource->orderId,
bank_unique_code: $visaPaymentOrder->branch->unique_code,
online_payment_terminal_id: $response['terminalId'],
user_deposit_account: number_format($visaPaymentOrder->sender_deposit_account, 0, '', ''),
online_payment_auth_ref_num: $response['authRefNum'],
online_payment_tmt_amount: $orderItem->tmt_payment_amount,
pay_purpose: $orderItem->created_at->translatedFormat('F').' '.$orderItem->created_at->format('Y')
);
if ($systemRawResponse == null) {
return [
'error' => 'Connection issue to SYSTEM',
'type' => 'modal',
];
}
$systemResponse = json_decode($systemRawResponse);
$success = false;
if (is_object($systemResponse)) {
$success = $systemResponse->errCode == 0;
}
if (! $success) {
$message = 'Error';
if (isset($systemResponse->msgSys)) {
$message .= ' '.$systemResponse->msgSys;
}
return [