This commit is contained in:
2025-09-09 11:14:24 +05:00
parent 5cb2f9027c
commit 40565033b6
2 changed files with 75 additions and 38 deletions

View File

@@ -4,6 +4,7 @@ use App\Events\EventType;
use App\Models\Payment\OnlinePaymentHistory;
use App\Models\System\Roles\Permission;
use App\Models\System\Verification;
use App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem;
use App\Nova\Resources\Order\Card\CardTransaction\Actions\DownloadCardTransaction;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request as GuzzleRequest;
@@ -437,8 +438,7 @@ function syncWithBankSystem(
$online_payment_auth_ref_num,
$online_payment_tmt_amount,
$pay_purpose
): mixed
{
): mixed {
$ecomId = $online_payment_order_uuid;
$agentId = $bank_unique_code;
$eposId = $online_payment_terminal_id;
@@ -479,3 +479,43 @@ function syncWithBankSystem(
return $response;
}
/**
* Get Sber credentials for a given payment item.
*
* @param SberPaymentOrderItem $item
* @return array{username?: string, password?: string, onlinePaymentResource?: OnlinePaymentHistory, error?: string, type?: 'danger'|'modal'}
*/
function getSberCredentials(SberPaymentOrderItem $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'];
}
if (! $relatedResource->branch) {
return ['error' => 'Şahamça bilen birikdirilmedik', 'type' => 'danger'];
}
$username = $relatedResource->branch->billing_sber_username;
$password = $relatedResource->branch->billing_sber_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,
];
}

View File

@@ -2,7 +2,6 @@
namespace App\Nova\Actions\Sber;
use App\Models\Payment\OnlinePaymentHistory;
use App\Nova\Actions\CheckOnlinePayment;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
@@ -36,35 +35,16 @@ class SyncWithSystem extends Action
/** @var \App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem $item */
$item = $models->first();
$result = getSberCredentials($item);
if (isset($result['error'])) {
$this->handleError($result);
}
/** @var \App\Models\Payment\OnlinePaymentHistory $onlinePaymentResource */
$onlinePaymentResource = OnlinePaymentHistory::find($item->online_payment_history_id);
$onlinePaymentResource = $result['onlinePaymentResource'];
if (! $onlinePaymentResource) {
return ActionResponse::danger('Online payment resource tapylmady');
}
$relatedResource = (new $onlinePaymentResource->online_paymantable_type)
->find(id: $onlinePaymentResource->online_paymantable_id);
if (! $relatedResource) {
return ActionResponse::danger('Bu resource tapylmady');
}
if (! $relatedResource->branch) {
return ActionResponse::danger('Şahamça bilen birikdirilmedik');
}
$username = $relatedResource->branch->billing_sber_username;
$password = $relatedResource->branch->billing_sber_password;
if ($username == '') {
return Action::modal('modal-response', [
'title' => 'HALKBANK API',
'body' => 'Ulanyjy ady bilen açar sözi gabat gelmedi',
]);
}
$response = checkOnlinePayment($onlinePaymentResource->orderId, $username, $password);
$response = checkOnlinePayment($onlinePaymentResource->orderId, $result['username'], $result['password']);
// syncWithBankSystem();
@@ -84,4 +64,21 @@ class SyncWithSystem extends Action
{
return [];
}
/**
* Handle error
*
* @param array $result
*/
private function handleError(array $result): mixed
{
if ($result['type'] === 'modal') {
return Action::modal('modal-response', [
'title' => 'HALKBANK API',
'body' => $result['error'],
]);
}
return ActionResponse::danger($result['error']);
}
}