From ed65172b07617daf247743bd0216768489075fd4 Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Tue, 9 Sep 2025 11:33:28 +0500 Subject: [PATCH] wip --- app/Helpers/helpers.php | 64 +++++++++++-------- .../Models/SberPaymentOrder.php | 4 ++ app/Nova/Actions/Sber/SyncWithSystem.php | 13 +++- 3 files changed, 52 insertions(+), 29 deletions(-) diff --git a/app/Helpers/helpers.php b/app/Helpers/helpers.php index 5e2e8a3..38f84d5 100644 --- a/app/Helpers/helpers.php +++ b/app/Helpers/helpers.php @@ -447,44 +447,49 @@ function syncWithBankSystem( $amount = $online_payment_tmt_amount; $payPurpose = $pay_purpose; - $curl = curl_init(); + return [ + 'amount' => $amount, + 'amount_formatted' => number_format($amount, 2, '.', ''), + ]; - curl_setopt_array($curl, [ - CURLOPT_URL => 'http://10.3.158.102:8888/api/paytrn/new', - CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => '', - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 0, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => sprintf('{ - "ecomId": "%s", - "agentId": "%s", - "eposId": "%s", - "account": "%s", - "rrn": "%s", - "amount": "%s", - "payPurpose": "%s" - }', $ecomId, $agentId, $eposId, $account, $rrn, $amount, $payPurpose), - CURLOPT_HTTPHEADER => [ - 'Authorization: Basic YWRtaW46UUFad3N4MTIz', - 'Content-Type: application/json', - ], - ]); + // $curl = curl_init(); - $response = curl_exec($curl); + // curl_setopt_array($curl, [ + // CURLOPT_URL => 'http://10.3.158.102:8888/api/paytrn/new', + // CURLOPT_RETURNTRANSFER => true, + // CURLOPT_ENCODING => '', + // CURLOPT_MAXREDIRS => 10, + // CURLOPT_TIMEOUT => 0, + // CURLOPT_FOLLOWLOCATION => true, + // CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + // CURLOPT_CUSTOMREQUEST => 'POST', + // CURLOPT_POSTFIELDS => sprintf('{ + // "ecomId": "%s", + // "agentId": "%s", + // "eposId": "%s", + // "account": "%s", + // "rrn": "%s", + // "amount": "%s", + // "payPurpose": "%s" + // }', $ecomId, $agentId, $eposId, $account, $rrn, $amount, $payPurpose), + // CURLOPT_HTTPHEADER => [ + // 'Authorization: Basic YWRtaW46UUFad3N4MTIz', + // 'Content-Type: application/json', + // ], + // ]); - curl_close($curl); + // $response = curl_exec($curl); - return $response; + // curl_close($curl); + + // 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'} + * @return array{username?: string, password?: string, onlinePaymentResource?: OnlinePaymentHistory, relatedResource?: mixed, error?: string, type?: 'danger'|'modal'} */ function getSberCredentials(SberPaymentOrderItem $item): array { @@ -502,6 +507,8 @@ function getSberCredentials(SberPaymentOrderItem $item): array return ['error' => 'Bu resource tapylmady', 'type' => 'danger']; } + $relatedResource->loadMissing(['branch']); + if (! $relatedResource->branch) { return ['error' => 'Şahamça bilen birikdirilmedik', 'type' => 'danger']; } @@ -517,5 +524,6 @@ function getSberCredentials(SberPaymentOrderItem $item): array 'username' => $username, 'password' => $password, 'onlinePaymentResource' => $onlinePaymentResource, + 'relatedResource' => $relatedResource, ]; } diff --git a/app/Modules/SberPaymentOrder/Models/SberPaymentOrder.php b/app/Modules/SberPaymentOrder/Models/SberPaymentOrder.php index 98bf407..5b4be75 100644 --- a/app/Modules/SberPaymentOrder/Models/SberPaymentOrder.php +++ b/app/Modules/SberPaymentOrder/Models/SberPaymentOrder.php @@ -25,6 +25,10 @@ use Spatie\MediaLibrary\InteractsWithMedia; * @property int $user_id * @property string $address * @property array $sender_datas + * @property ?string $sender_full_name + * @property ?string $sender_passport_serie + * @property ?string $sender_passport_number + * @property ?string $sender_deposit_account * @property array $payment_reciever * @property string $documents * @property string $status diff --git a/app/Nova/Actions/Sber/SyncWithSystem.php b/app/Nova/Actions/Sber/SyncWithSystem.php index 3acb6d0..abf9b0b 100644 --- a/app/Nova/Actions/Sber/SyncWithSystem.php +++ b/app/Nova/Actions/Sber/SyncWithSystem.php @@ -44,9 +44,20 @@ class SyncWithSystem extends Action /** @var \App\Models\Payment\OnlinePaymentHistory $onlinePaymentResource */ $onlinePaymentResource = $result['onlinePaymentResource']; + /** @var \App\Modules\SberPaymentOrder\Models\SberPaymentOrder $sberPaymentOrder */ + $sberPaymentOrder = $result['relatedResource']; + $response = checkOnlinePayment($onlinePaymentResource->orderId, $result['username'], $result['password']); - // syncWithBankSystem(); + info(syncWithBankSystem( + online_payment_order_uuid: $onlinePaymentResource->orderId, + bank_unique_code: $sberPaymentOrder->branch->unique_code, + online_payment_terminal_id: $response['terminalId'], + user_deposit_account: $sberPaymentOrder->sender_deposit_account, + online_payment_auth_ref_num: $response['authRefNum'], + online_payment_tmt_amount: $response['paymentAmountInfo']['depositedAmount'], + pay_purpose: $sberPaymentOrder->created_at->translatedFormat('F').' '.$sberPaymentOrder->created_at->format('Y') + )); return Action::modal('modal-response', [ 'title' => 'HALKBANK API',