Point in-app wallet top-up at the billing API (key the app already holds)
Deploy Ladill QR Plus / deploy (push) Successful in 33s
Deploy Ladill QR Plus / deploy (push) Successful in 33s
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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
73faa20fff
commit
b7adb69245
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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'))
|
||||
|
||||
Reference in New Issue
Block a user