Deploy Ladill QR Plus / deploy (push) Successful in 40s
When a user hits an action they can't afford (e.g. creating a QR code with 0/low balance), open an in-app two-step modal instead of bouncing them to the central wallet page. Step 1 explains pay-as-you-go billing + shows the action cost and current balance; step 2 takes an amount and starts a Paystack checkout via the central identity wallet-topup API, returning the user where they were. - service-topup-modal: rebuilt as two-step (billing explainer -> amount/pay) - IdentityClient::walletTopup + WalletTopupController + POST /wallet/topup - balanceGate.openTopup / qrCustomizer.redirectTopup now prefer the modal, falling back to the wallet page only when no modal is wired - qr-codes index + create render the modal and open it on insufficient balance Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
76 lines
2.0 KiB
PHP
76 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Identity;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class IdentityClient
|
|
{
|
|
/** @return array<string, mixed> */
|
|
public function mailboxLinkStatus(string $publicId): array
|
|
{
|
|
$response = $this->request()->get($this->url('/identity/mailbox-link'), [
|
|
'user' => $publicId,
|
|
]);
|
|
|
|
$response->throw();
|
|
|
|
return (array) $response->json('data', []);
|
|
}
|
|
|
|
/** @return array<string, mixed> */
|
|
public function linkMailbox(string $publicId, string $mailboxAddress): array
|
|
{
|
|
$response = $this->request()->put($this->url('/identity/mailbox-link'), [
|
|
'user' => $publicId,
|
|
'mailbox_address' => $mailboxAddress,
|
|
]);
|
|
|
|
$response->throw();
|
|
|
|
return (array) $response->json('data', []);
|
|
}
|
|
|
|
/** @return array<string, mixed> */
|
|
public function unlinkMailbox(string $publicId): array
|
|
{
|
|
$response = $this->request()->delete($this->url('/identity/mailbox-link'), [
|
|
'user' => $publicId,
|
|
]);
|
|
|
|
$response->throw();
|
|
|
|
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'))
|
|
->acceptJson()
|
|
->timeout(15);
|
|
}
|
|
|
|
private function url(string $path): string
|
|
{
|
|
return rtrim((string) config('identity.api_url'), '/').$path;
|
|
}
|
|
}
|