diff --git a/migrations/2023_06_30_021642_create_sequence_for_ap_wallet.php b/migrations/2023_06_30_021642_create_sequence_for_ap_wallet.php new file mode 100644 index 0000000..14f3686 --- /dev/null +++ b/migrations/2023_06_30_021642_create_sequence_for_ap_wallet.php @@ -0,0 +1,27 @@ +publishes([ - __DIR__.'/../config/wallet.php' => config_path('wallet.php'), - ], 'config'); + __DIR__.'/../config/wallet.php' => config_path('wallet.php')], 'larawallet-configs'); + $this->publishes([ + __DIR__.'/../migrations/' => database_path('migrations')], 'larawallet-migrations'); } } diff --git a/src/Provider/AbstractProvider.php b/src/Provider/AbstractProvider.php index f8ff970..9c58e2e 100644 --- a/src/Provider/AbstractProvider.php +++ b/src/Provider/AbstractProvider.php @@ -4,6 +4,7 @@ use App\Containers\AppSection\Transaction\Models\Transaction; use App\Containers\AppSection\Wallet\Models\WalletProvider; +use App\Ship\Models\Serial; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\View; @@ -185,4 +186,9 @@ public static function generalViewErrorResponse($view, $withErrors): Factory|Vie { return view($view)->withErrors([$withErrors]); } + + protected function getWalletTransactionId(string $seq = 'ap_trans_id'): int + { + return Serial::getNextVal($seq); + } } diff --git a/src/Provider/AsanPardakhtProvider.php b/src/Provider/AsanPardakhtProvider.php index 815d58d..4fceb86 100644 --- a/src/Provider/AsanPardakhtProvider.php +++ b/src/Provider/AsanPardakhtProvider.php @@ -35,21 +35,25 @@ public function checkWalletBalance(): JsonResponse|array 'mo' => $this->getCellNumber(), 'hi' => $this->getParameters('host_id'), 'walet' => 5, - 'htran' => $this->getWalletChargeTransactionId(), + 'htran' => $this->getWalletTransactionId(), 'hop' => AsanpardakhtStatusEnum::WalletBalanceHop->value, 'htime' => time(), 'hkey' => $this->getParameters('api_key'), ]); - $hostRequestSign = $this->signRequest($hostRequest); - $rawResponse = $this->sendInfoToAp($hostRequest, $hostRequestSign, self::POST_METHOD, $this->getUrl()); + $rawResponse = $this->sendInfoToAp( + $hostRequest, + $this->signRequest($hostRequest), + self::POST_METHOD, + $this->getUrl() + ); $responseJson = json_decode($rawResponse['hresp'], false, 512, JSON_THROW_ON_ERROR); if ($responseJson->st !== 1100) { $credit = 0; if (property_exists($responseJson, 'wball')) { - $credit = $responseJson->wball / 10; + $credit = $responseJson->wball / 10; // this API returns fucking RIAL!!! } return self::generalResponse( @@ -95,7 +99,7 @@ public function getBalanceWalletError(\Exception $exception): JsonResponse { if (method_exists($exception, 'getResponse') && ! empty($exception->getResponse())) { $errorJson = json_decode($exception->getResponse()->getBody()->getContents()); - $errorMsg = $errorJson != null && property_exists( + $errorMsg = ! is_null($errorJson) && property_exists( $errorJson, 'description' ) ? $errorJson->description : $exception->getMessage(); @@ -126,7 +130,7 @@ public function payByWallet(): JsonResponse|array 'mo' => $this->getCellNumber(), 'hi' => $this->getParameters('host_id'), 'walet' => 5, - 'htran' => $this->getTransaction()->getWalletTransactionId(), + 'htran' => $this->getWalletTransactionId(), 'hop' => AsanpardakhtStatusEnum::PayByWalletHop->value, 'htime' => time(), 'stime' => time(), @@ -189,7 +193,7 @@ public function reverseWalletPaymentResult(): mixed 'mo' => $this->getCellNumber(), 'hi' => $this->getParameters('host_id'), 'walet' => 5, - 'htran' => $this->getTransaction()->getWalletTransactionId(), + 'htran' => $this->getWalletTransactionId(), 'hop' => AsanpardakhtStatusEnum::ReverseRequestHop->value, 'htime' => $time, 'stime' => $time, @@ -232,7 +236,7 @@ public function walletCharge(): JsonResponse|array 'mo' => $this->getCellNumber(), 'hi' => $this->getParameters('host_id'), 'walet' => 5, - 'htran' => $this->getWalletChargeTransactionId(), + 'htran' => $this->getWalletTransactionId(), 'hop' => AsanpardakhtStatusEnum::ChargeWallet->value, 'htime' => time(), 'stime' => time(), @@ -400,9 +404,4 @@ public function refundWalletPaymentResult(): mixed return $result; } - - private function getWalletChargeTransactionId(): int - { - return 900000000000 + time(); - } }