Skip to content

Commit e886b47

Browse files
committed
feat: Adds reverse transaction in wallet payment
1 parent 40c7933 commit e886b47

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

src/Enums/AsanpardakhtStatusEnum.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ enum AsanpardakhtStatusEnum: int
2828
case ReverseRequestHop = 244;
2929
case VerifyRequestHop = 2001;
3030
case SettleRequestHop = 2002;
31+
case RefundRequestHop = 2003;
3132

3233

3334
//----------------------generate by code-------------------

src/Provider/AbstractProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,20 @@ public static function generalExceptionResponse(
234234
/**
235235
* @param int $code
236236
* @param string|null $value
237+
* @param array|null $result
237238
* @param int $statusCode
238239
* @return JsonResponse
239240
*/
240241
public static function generalResponse(
241242
int $code = 0,
242243
string $value = null,
244+
array $result = null,
243245
int $statusCode = Response::HTTP_OK,
244246
): JsonResponse {
245247
return response()->json([
246248
"code" => $code,
247249
"value" => $value,
250+
"result" => $result,
248251
"x_track_id" => resolve(env('XLOG_TRACK_ID_KEY', 'xTrackId')),
249252
], $statusCode);
250253
}

src/Provider/AsanPardakhtProvider.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,60 @@ public function reverseWalletPaymentResult(): mixed
336336

337337
return $result;
338338
}
339+
340+
341+
/**
342+
* @return mixed
343+
* @throws \JsonException
344+
*/
345+
public function refundWalletPaymentResult(): mixed
346+
{
347+
$time = time();
348+
349+
$arrayData = [
350+
"ao" => $this->getTransaction()->getPayableAmount(),
351+
"mo" => $this->getCellNumber(),
352+
"hi" => $this->getParameters('host_id'),
353+
"walet" => 5,
354+
"htran" => $this->getTransaction()->getCallbackParams()['htran'],
355+
"hop" => AsanpardakhtStatusEnum::RefundRequestHop->value,
356+
"htime" => $this->getTransaction()->getCallbackParams()['htime'],
357+
"stime" => $time,
358+
"stkn" => $this->getTransaction()->getCallbackParams()['stkn'],
359+
"hkey" => $this->getParameters('api_key')
360+
];
361+
$hostRequest = $this->prepareJsonString($arrayData);
362+
363+
$hostRequestSign = $this->signRequest($hostRequest);
364+
365+
try {
366+
$rawResponse = $this->sendInfoToAp($hostRequest, $hostRequestSign, self::POST_METHOD, $this->getUrl());
367+
$responseJson = json_decode($rawResponse["hresp"], true);
368+
369+
$result = $responseJson['st'];
370+
371+
//----------------------------------successfully reversed-------------------------------------
372+
if ($responseJson['st'] == AsanpardakhtStatusEnum::SuccessRequest->value) {
373+
$this->log('successfully reversed', [], 'info');
374+
375+
$result = self::generalResponse(
376+
code: AsanpardakhtStatusEnum::SuccessResponse->value,
377+
result: $responseJson,
378+
);
379+
} else {
380+
$result = self::generalResponse(
381+
code: $result,
382+
);
383+
}
384+
} catch (ServerException $ex) {
385+
$this->log($ex->getMessage(), [], 'error');
386+
$errorJson = json_decode($ex->getResponse()->getBody()->getContents());
387+
$result = [
388+
AsanpardakhtStatusEnum::FailedResponse->value,
389+
$errorJson
390+
];
391+
}
392+
393+
return $result;
394+
}
339395
}

0 commit comments

Comments
 (0)