Skip to content

Commit

Permalink
feat: add wallet charge method in asanpardakht class
Browse files Browse the repository at this point in the history
  • Loading branch information
maryamnbyn committed Apr 24, 2023
1 parent 135fd4e commit 5027b82
Showing 1 changed file with 51 additions and 16 deletions.
67 changes: 51 additions & 16 deletions src/Provider/AsanPardakhtProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function checkWalletBalance(): JsonResponse|array
"mo" => $this->getCellNumber(),
"hi" => $this->getParameters('host_id'),
"walet" => 5,
"htran" => random_int(5000, 50000).time(),
"htran" => random_int(5000, 50000) . time(),
"hop" => AsanpardakhtStatusEnum::WalletBalanceHop->value,
"htime" => time(),
"hkey" => $this->getParameters('api_key')
Expand Down Expand Up @@ -66,13 +66,13 @@ public function checkWalletBalance(): JsonResponse|array
} catch (ClientException|\Exception $exception) {
$exceptionMessage = $this->getBalanceWalletError($exception);
throw new Exception((json_decode($exceptionMessage->content(), false))->message,
$exceptionMessage->statusCode ?? 500);
$exceptionMessage->statusCode);
}
}


/**
* @param string $input
* @param string $input
* @return string
*/
public function signRequest(string $input): string
Expand All @@ -86,7 +86,7 @@ public function signRequest(string $input): string
OPENSSL_ALGO_SHA256
);

return '1#1#'.base64_encode($binary_signature);
return '1#1#' . base64_encode($binary_signature);
}


Expand All @@ -106,7 +106,7 @@ public function payByWallet(): JsonResponse|array
"mo" => $this->getCellNumber(),
"hi" => $this->getParameters('host_id'),
"walet" => 5,
"htran" => random_int(5000, 50000).time(),
"htran" => random_int(5000, 50000) . time(),
"hop" => AsanpardakhtStatusEnum::PayByWalletHop->value,
"htime" => time(),
"stime" => time(),
Expand All @@ -127,13 +127,6 @@ public function payByWallet(): JsonResponse|array
);
}

if ($responseJson->st == AsanpardakhtStatusEnum::AccessDeniedRequest->value || $responseJson->st == AsanpardakhtStatusEnum::InsufficientInventory) { // access denied : 1332, low credit : 1330
return self::generalResponse(
code: AsanpardakhtStatusEnum::AccessDeniedResponse->value,
value: $responseJson->addData->ipgURL,
);
}

return self::generalResponse(
code: AsanpardakhtStatusEnum::FailedResponse->value,
value: $responseJson->stm,
Expand All @@ -157,6 +150,48 @@ public function payByWallet(): JsonResponse|array
}
}

/**
* @return JsonResponse|array
* @throws \JsonException
*/
public function walletCharge(): JsonResponse|array
{
$responseJson = '';

try {
$arrayData = [
"caurl" => $this->getTransaction()->callback_url,
"ao" => $this->getTransaction()->amount,
"mo" => $this->getCellNumber(),
"hi" => $this->getParameters('host_id'),
"walet" => 5,
"htran" => random_int(5000, 50000) . time(),
"hop" => AsanpardakhtStatusEnum::ChargeWallet->value,
"htime" => time(),
"stime" => time(),
"hkey" => $this->getParameters('api_key')
];

$hostRequest = $this->prepareJsonString($arrayData);

$hRequestSign = $this->signRequest($hostRequest);
$rawResponse = $this->sendInfoToAp($hostRequest, $hRequestSign, self::POST_METHOD, $this->getUrl());
$responseJson = $this->getHresponseData($rawResponse["hresp"]);

if ($responseJson['st'] == AsanpardakhtStatusEnum::SuccessRequest->value) {
return self::generalResponse(
code: AsanpardakhtStatusEnum::SuccessResponse->value,
value: $responseJson['addData']['ipgURL'],
);
}
} catch (\Exception $exception) {
return self::generalExceptionResponse(
AsanpardakhtStatusEnum::FailedResponse->value,
$exception->getMessage()
);
}
}


/**
* @return mixed
Expand Down Expand Up @@ -253,7 +288,7 @@ public function settleWalletPaymentResult(): mixed


/**
* @param \Exception $exception
* @param \Exception $exception
* @return JsonResponse
*/
public function getBalanceWalletError(\Exception $exception): JsonResponse
Expand All @@ -268,7 +303,7 @@ public function getBalanceWalletError(\Exception $exception): JsonResponse
$errorMsg = $exception->getMessage();
}

XLog::emergency('wallet service check balance failure'.' '.' message: '.$errorMsg);
XLog::emergency('wallet service check balance failure' . ' ' . ' message: ' . $errorMsg);

return self::generalExceptionResponse(
AsanpardakhtStatusEnum::FailedResponse->value,
Expand All @@ -278,7 +313,7 @@ public function getBalanceWalletError(\Exception $exception): JsonResponse


/**
* @param array $data
* @param array $data
* @return string|array|false
* @throws \JsonException
*/
Expand Down Expand Up @@ -312,7 +347,7 @@ public function reverseWalletPaymentResult(): mixed
"mo" => $this->getCellNumber(),
"hi" => $this->getParameters('host_id'),
"walet" => 5,
"htran" => random_int(5000, 50000).time(),
"htran" => random_int(5000, 50000) . time(),
"hop" => AsanpardakhtStatusEnum::ReverseRequestHop->value,
"htime" => $time,
"stime" => $time,
Expand Down

0 comments on commit 5027b82

Please sign in to comment.