Skip to content

Commit 28b4c2c

Browse files
committed
unified AP htran using Postgres sequence
1 parent 9410123 commit 28b4c2c

File tree

4 files changed

+48
-15
lines changed

4 files changed

+48
-15
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Support\Facades\DB;
5+
6+
return new class extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
DB::statement('CREATE SEQUENCE IF NOT EXISTS ap_trans_id START 1000000000000;');
16+
}
17+
18+
/**
19+
* Reverse the migrations.
20+
*
21+
* @return void
22+
*/
23+
public function down()
24+
{
25+
DB::statement('DROP SEQUENCE IF EXISTS ap_trans_id;');
26+
}
27+
};

src/LaraWalletServiceProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public function boot(): void
2828
protected function registerPublishing(): void
2929
{
3030
$this->publishes([
31-
__DIR__.'/../config/wallet.php' => config_path('wallet.php'),
32-
], 'config');
31+
__DIR__.'/../config/wallet.php' => config_path('wallet.php')], 'larawallet-configs');
32+
$this->publishes([
33+
__DIR__.'/../migrations/' => database_path('migrations')], 'larawallet-migrations');
3334
}
3435
}

src/Provider/AbstractProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Containers\AppSection\Transaction\Models\Transaction;
66
use App\Containers\AppSection\Wallet\Models\WalletProvider;
7+
use App\Ship\Models\Serial;
78
use Illuminate\Contracts\Foundation\Application;
89
use Illuminate\Contracts\View\Factory;
910
use Illuminate\Contracts\View\View;
@@ -185,4 +186,9 @@ public static function generalViewErrorResponse($view, $withErrors): Factory|Vie
185186
{
186187
return view($view)->withErrors([$withErrors]);
187188
}
189+
190+
protected function getWalletTransactionId(string $seq = 'ap_trans_id'): int
191+
{
192+
return Serial::getNextVal($seq);
193+
}
188194
}

src/Provider/AsanPardakhtProvider.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,25 @@ public function checkWalletBalance(): JsonResponse|array
3535
'mo' => $this->getCellNumber(),
3636
'hi' => $this->getParameters('host_id'),
3737
'walet' => 5,
38-
'htran' => $this->getWalletChargeTransactionId(),
38+
'htran' => $this->getWalletTransactionId(),
3939
'hop' => AsanpardakhtStatusEnum::WalletBalanceHop->value,
4040
'htime' => time(),
4141
'hkey' => $this->getParameters('api_key'),
4242
]);
4343

44-
$hostRequestSign = $this->signRequest($hostRequest);
45-
$rawResponse = $this->sendInfoToAp($hostRequest, $hostRequestSign, self::POST_METHOD, $this->getUrl());
44+
$rawResponse = $this->sendInfoToAp(
45+
$hostRequest,
46+
$this->signRequest($hostRequest),
47+
self::POST_METHOD,
48+
$this->getUrl()
49+
);
4650
$responseJson = json_decode($rawResponse['hresp'], false, 512, JSON_THROW_ON_ERROR);
4751

4852
if ($responseJson->st !== 1100) {
4953
$credit = 0;
5054

5155
if (property_exists($responseJson, 'wball')) {
52-
$credit = $responseJson->wball / 10;
56+
$credit = $responseJson->wball / 10; // this API returns fucking RIAL!!!
5357
}
5458

5559
return self::generalResponse(
@@ -95,7 +99,7 @@ public function getBalanceWalletError(\Exception $exception): JsonResponse
9599
{
96100
if (method_exists($exception, 'getResponse') && ! empty($exception->getResponse())) {
97101
$errorJson = json_decode($exception->getResponse()->getBody()->getContents());
98-
$errorMsg = $errorJson != null && property_exists(
102+
$errorMsg = ! is_null($errorJson) && property_exists(
99103
$errorJson,
100104
'description'
101105
) ? $errorJson->description : $exception->getMessage();
@@ -126,7 +130,7 @@ public function payByWallet(): JsonResponse|array
126130
'mo' => $this->getCellNumber(),
127131
'hi' => $this->getParameters('host_id'),
128132
'walet' => 5,
129-
'htran' => $this->getTransaction()->getWalletTransactionId(),
133+
'htran' => $this->getWalletTransactionId(),
130134
'hop' => AsanpardakhtStatusEnum::PayByWalletHop->value,
131135
'htime' => time(),
132136
'stime' => time(),
@@ -189,7 +193,7 @@ public function reverseWalletPaymentResult(): mixed
189193
'mo' => $this->getCellNumber(),
190194
'hi' => $this->getParameters('host_id'),
191195
'walet' => 5,
192-
'htran' => $this->getTransaction()->getWalletTransactionId(),
196+
'htran' => $this->getWalletTransactionId(),
193197
'hop' => AsanpardakhtStatusEnum::ReverseRequestHop->value,
194198
'htime' => $time,
195199
'stime' => $time,
@@ -232,7 +236,7 @@ public function walletCharge(): JsonResponse|array
232236
'mo' => $this->getCellNumber(),
233237
'hi' => $this->getParameters('host_id'),
234238
'walet' => 5,
235-
'htran' => $this->getWalletChargeTransactionId(),
239+
'htran' => $this->getWalletTransactionId(),
236240
'hop' => AsanpardakhtStatusEnum::ChargeWallet->value,
237241
'htime' => time(),
238242
'stime' => time(),
@@ -400,9 +404,4 @@ public function refundWalletPaymentResult(): mixed
400404

401405
return $result;
402406
}
403-
404-
private function getWalletChargeTransactionId(): int
405-
{
406-
return 900000000000 + time();
407-
}
408407
}

0 commit comments

Comments
 (0)