From 0b63d9098e85f4dfa052de5f7187ae93cea36f24 Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Tue, 9 Sep 2025 11:06:36 +0500 Subject: [PATCH] wip --- app/Helpers/helpers.php | 87 +++++++++++++++++++ .../Controllers/OnlinePaymentController.php | 43 --------- app/Nova/Actions/Sber/SyncWithSystem.php | 39 ++++++++- 3 files changed, 125 insertions(+), 44 deletions(-) diff --git a/app/Helpers/helpers.php b/app/Helpers/helpers.php index 80bd5ef..03383c8 100644 --- a/app/Helpers/helpers.php +++ b/app/Helpers/helpers.php @@ -1,6 +1,7 @@ post('https://mpi.gov.tm/payment/rest/getOrderStatusExtended.do', [ + 'language' => 'ru', + 'orderId' => $orderId, + 'userName' => $username, + 'password' => $password, + ]); + + return $response; +} + +/** + * Sync with bank system + * + * @param string $online_payment_order_uuid + * @param string $bank_unique_code + * @param string $online_payment_terminal_id + * @param string $user_deposit_account + * @param string $online_payment_auth_ref_num + * @param string $online_payment_tmt_amount + * @param string $pay_purpose + * + * @return mixed + */ +function syncWithBankSystem( + $online_payment_order_uuid, + $bank_unique_code, + $online_payment_terminal_id, + $user_deposit_account, + $online_payment_auth_ref_num, + $online_payment_tmt_amount, + $pay_purpose +): mixed +{ + $ecomId = $online_payment_order_uuid; + $agentId = $bank_unique_code; + $eposId = $online_payment_terminal_id; + $account = $user_deposit_account; + $rrn = $online_payment_auth_ref_num; + $amount = $online_payment_tmt_amount; + $payPurpose = $pay_purpose; + + $curl = curl_init(); + + 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', + ], + ]); + + $response = curl_exec($curl); + + curl_close($curl); + + return $response; +} diff --git a/app/Http/Controllers/OnlinePaymentController.php b/app/Http/Controllers/OnlinePaymentController.php index dd8d381..fb06c78 100644 --- a/app/Http/Controllers/OnlinePaymentController.php +++ b/app/Http/Controllers/OnlinePaymentController.php @@ -73,47 +73,4 @@ class OnlinePaymentController extends Controller return view(OnlinePaymentRepo::statusView(), $data); } - - public function runActions($paymentHistory, $bank, $response, $resource): void - { - $ecomId = $paymentHistory->orderId; - $agentId = $bank->unique_code; - $eposId = $response['terminalId']; - $account = $resource->parent->sender_datas[0]['deposit_account']; - $rrn = $response['authRefNum']; - $amount = $resource->tmt_payment_amount; - $payPurpose = $resource->created_at->translatedFormat('F').' '.$resource->created_at->format('Y'); - - $curl = curl_init(); - - 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', - ], - ]); - - $response = curl_exec($curl); - - curl_close($curl); - - info($response); - } } diff --git a/app/Nova/Actions/Sber/SyncWithSystem.php b/app/Nova/Actions/Sber/SyncWithSystem.php index d5ed692..4de517f 100644 --- a/app/Nova/Actions/Sber/SyncWithSystem.php +++ b/app/Nova/Actions/Sber/SyncWithSystem.php @@ -2,10 +2,13 @@ namespace App\Nova\Actions\Sber; +use App\Models\Payment\OnlinePaymentHistory; +use App\Nova\Actions\CheckOnlinePayment; use Illuminate\Bus\Queueable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Support\Collection; use Laravel\Nova\Actions\Action; +use Laravel\Nova\Actions\ActionResponse; use Laravel\Nova\Fields\ActionFields; use Laravel\Nova\Http\Requests\NovaRequest; @@ -30,7 +33,41 @@ class SyncWithSystem extends Action */ public function handle(ActionFields $fields, Collection $models) { - // + /** @var \App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem $item */ + $item = $models->first(); + + /** @var \App\Models\Payment\OnlinePaymentHistory $onlinePaymentResource */ + $onlinePaymentResource = OnlinePaymentHistory::find($item->online_payment_history_id); + + 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'); + } + + $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); + + // syncWithBankSystem(); + + return Action::modal('modal-response', [ + 'title' => 'HALKBANK API', + 'html' => CheckOnlinePayment::resultHTML($response), + ]); } /**