@@ -35,7 +35,7 @@ public function checkWalletBalance(): JsonResponse|array
3535 "mo " => $ this ->getCellNumber (),
3636 "hi " => $ this ->getParameters ('host_id ' ),
3737 "walet " => 5 ,
38- "htran " => random_int (5000 , 50000 ). time (),
38+ "htran " => random_int (5000 , 50000 ) . time (),
3939 "hop " => AsanpardakhtStatusEnum::WalletBalanceHop->value ,
4040 "htime " => time (),
4141 "hkey " => $ this ->getParameters ('api_key ' )
@@ -66,13 +66,13 @@ public function checkWalletBalance(): JsonResponse|array
6666 } catch (ClientException |\Exception $ exception ) {
6767 $ exceptionMessage = $ this ->getBalanceWalletError ($ exception );
6868 throw new Exception ((json_decode ($ exceptionMessage ->content (), false ))->message ,
69- $ exceptionMessage ->statusCode ?? 500 );
69+ $ exceptionMessage ->statusCode );
7070 }
7171 }
7272
7373
7474 /**
75- * @param string $input
75+ * @param string $input
7676 * @return string
7777 */
7878 public function signRequest (string $ input ): string
@@ -86,7 +86,7 @@ public function signRequest(string $input): string
8686 OPENSSL_ALGO_SHA256
8787 );
8888
89- return '1#1# ' . base64_encode ($ binary_signature );
89+ return '1#1# ' . base64_encode ($ binary_signature );
9090 }
9191
9292
@@ -106,7 +106,7 @@ public function payByWallet(): JsonResponse|array
106106 "mo " => $ this ->getCellNumber (),
107107 "hi " => $ this ->getParameters ('host_id ' ),
108108 "walet " => 5 ,
109- "htran " => random_int (5000 , 50000 ). time (),
109+ "htran " => random_int (5000 , 50000 ) . time (),
110110 "hop " => AsanpardakhtStatusEnum::PayByWalletHop->value ,
111111 "htime " => time (),
112112 "stime " => time (),
@@ -127,13 +127,6 @@ public function payByWallet(): JsonResponse|array
127127 );
128128 }
129129
130- if ($ responseJson ->st == AsanpardakhtStatusEnum::AccessDeniedRequest->value || $ responseJson ->st == AsanpardakhtStatusEnum::InsufficientInventory) { // access denied : 1332, low credit : 1330
131- return self ::generalResponse (
132- code: AsanpardakhtStatusEnum::AccessDeniedResponse->value ,
133- value: $ responseJson ->addData ->ipgURL ,
134- );
135- }
136-
137130 return self ::generalResponse (
138131 code: AsanpardakhtStatusEnum::FailedResponse->value ,
139132 value: $ responseJson ->stm ,
@@ -157,6 +150,48 @@ public function payByWallet(): JsonResponse|array
157150 }
158151 }
159152
153+ /**
154+ * @return JsonResponse|array
155+ * @throws \JsonException
156+ */
157+ public function walletCharge (): JsonResponse |array
158+ {
159+ $ responseJson = '' ;
160+
161+ try {
162+ $ arrayData = [
163+ "caurl " => $ this ->getTransaction ()->callback_url ,
164+ "ao " => $ this ->getTransaction ()->amount ,
165+ "mo " => $ this ->getCellNumber (),
166+ "hi " => $ this ->getParameters ('host_id ' ),
167+ "walet " => 5 ,
168+ "htran " => random_int (5000 , 50000 ) . time (),
169+ "hop " => AsanpardakhtStatusEnum::ChargeWallet->value ,
170+ "htime " => time (),
171+ "stime " => time (),
172+ "hkey " => $ this ->getParameters ('api_key ' )
173+ ];
174+
175+ $ hostRequest = $ this ->prepareJsonString ($ arrayData );
176+
177+ $ hRequestSign = $ this ->signRequest ($ hostRequest );
178+ $ rawResponse = $ this ->sendInfoToAp ($ hostRequest , $ hRequestSign , self ::POST_METHOD , $ this ->getUrl ());
179+ $ responseJson = $ this ->getHresponseData ($ rawResponse ["hresp " ]);
180+
181+ if ($ responseJson ['st ' ] == AsanpardakhtStatusEnum::SuccessRequest->value ) {
182+ return self ::generalResponse (
183+ code: AsanpardakhtStatusEnum::SuccessResponse->value ,
184+ value: $ responseJson ['addData ' ]['ipgURL ' ],
185+ );
186+ }
187+ } catch (\Exception $ exception ) {
188+ return self ::generalExceptionResponse (
189+ AsanpardakhtStatusEnum::FailedResponse->value ,
190+ $ exception ->getMessage ()
191+ );
192+ }
193+ }
194+
160195
161196 /**
162197 * @return mixed
@@ -253,7 +288,7 @@ public function settleWalletPaymentResult(): mixed
253288
254289
255290 /**
256- * @param \Exception $exception
291+ * @param \Exception $exception
257292 * @return JsonResponse
258293 */
259294 public function getBalanceWalletError (\Exception $ exception ): JsonResponse
@@ -268,7 +303,7 @@ public function getBalanceWalletError(\Exception $exception): JsonResponse
268303 $ errorMsg = $ exception ->getMessage ();
269304 }
270305
271- XLog::emergency ('wallet service check balance failure ' . ' ' . ' message: ' . $ errorMsg );
306+ XLog::emergency ('wallet service check balance failure ' . ' ' . ' message: ' . $ errorMsg );
272307
273308 return self ::generalExceptionResponse (
274309 AsanpardakhtStatusEnum::FailedResponse->value ,
@@ -278,7 +313,7 @@ public function getBalanceWalletError(\Exception $exception): JsonResponse
278313
279314
280315 /**
281- * @param array $data
316+ * @param array $data
282317 * @return string|array|false
283318 * @throws \JsonException
284319 */
@@ -312,7 +347,7 @@ public function reverseWalletPaymentResult(): mixed
312347 "mo " => $ this ->getCellNumber (),
313348 "hi " => $ this ->getParameters ('host_id ' ),
314349 "walet " => 5 ,
315- "htran " => random_int (5000 , 50000 ). time (),
350+ "htran " => random_int (5000 , 50000 ) . time (),
316351 "hop " => AsanpardakhtStatusEnum::ReverseRequestHop->value ,
317352 "htime " => $ time ,
318353 "stime " => $ time ,
0 commit comments