From b7adb692452a381bfa33c4140e94d43136655183 Mon Sep 17 00:00:00 2001 From: isaacclad Date: Fri, 26 Jun 2026 06:23:03 +0000 Subject: [PATCH] Point in-app wallet top-up at the billing API (key the app already holds) qr-plus authenticates to the monolith with a billing service key, not an identity key, so the modal's top-up now goes through BillingClient::topup -> POST /api/billing/topup. Drops the unused IdentityClient::walletTopup. Co-Authored-By: Claude Opus 4.8 --- app/Http/Controllers/WalletTopupController.php | 6 +++--- app/Services/Billing/BillingClient.php | 16 ++++++++++++++++ app/Services/Identity/IdentityClient.php | 18 ------------------ 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/app/Http/Controllers/WalletTopupController.php b/app/Http/Controllers/WalletTopupController.php index d0fe811..55f1ee9 100644 --- a/app/Http/Controllers/WalletTopupController.php +++ b/app/Http/Controllers/WalletTopupController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\Services\Identity\IdentityClient; +use App\Services\Billing\BillingClient; use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; @@ -15,7 +15,7 @@ use Illuminate\Http\Request; */ class WalletTopupController extends Controller { - public function store(Request $request, IdentityClient $identity): JsonResponse|RedirectResponse + public function store(Request $request, BillingClient $billing): JsonResponse|RedirectResponse { $validated = $request->validate([ 'amount' => ['required', 'numeric', 'min:5', 'max:5000'], @@ -25,7 +25,7 @@ class WalletTopupController extends Controller $returnUrl = $validated['return_url'] ?? (string) (url()->previous() ?: url('/')); try { - $checkoutUrl = $identity->walletTopup( + $checkoutUrl = $billing->topup( (string) $request->user()->public_id, (float) $validated['amount'], $returnUrl, diff --git a/app/Services/Billing/BillingClient.php b/app/Services/Billing/BillingClient.php index 4c7caef..546fc33 100644 --- a/app/Services/Billing/BillingClient.php +++ b/app/Services/Billing/BillingClient.php @@ -35,6 +35,22 @@ class BillingClient return (int) ($this->get('/balance', ['user' => $publicId])['balance_minor'] ?? 0); } + /** + * Start a Paystack checkout to top up the central wallet; returns the + * checkout URL. Backs the in-app two-step "Add funds" modal. + */ + public function topup(string $publicId, float $amount, string $returnUrl): string + { + $res = Http::withToken($this->token())->acceptJson()->timeout(15)->post($this->base().'/topup', [ + 'user' => $publicId, + 'amount' => $amount, + 'return_url' => $returnUrl, + ]); + $res->throw(); + + return (string) ($res->json()['checkout_url'] ?? ''); + } + public function canAfford(string $publicId, int $amountMinor): bool { return (bool) ($this->get('/can-afford', ['user' => $publicId, 'amount_minor' => $amountMinor])['affordable'] ?? false); diff --git a/app/Services/Identity/IdentityClient.php b/app/Services/Identity/IdentityClient.php index 9553b16..6033f57 100644 --- a/app/Services/Identity/IdentityClient.php +++ b/app/Services/Identity/IdentityClient.php @@ -43,24 +43,6 @@ class IdentityClient return (array) $response->json('data', []); } - /** - * Start a central-wallet Paystack top-up for an account and return the - * Paystack checkout URL. Backs the in-app "Add funds" modal so users top up - * without leaving the app for the central wallet page. - */ - public function walletTopup(string $publicId, float $amount, string $returnUrl): string - { - $response = $this->request()->post($this->url('/identity/wallet-topup-account'), [ - 'user' => $publicId, - 'amount' => $amount, - 'return_url' => $returnUrl, - ]); - - $response->throw(); - - return (string) $response->json('data.checkout_url', ''); - } - private function request() { return Http::withToken((string) config('identity.api_key'))