Collect MoMo MSISDN and open waiting page on Pay.
Deploy Ladill Mini / deploy (push) Successful in 42s
Deploy Ladill Mini / deploy (push) Successful in 42s
Payment QR was still Paystack-only: no customer_phone and mobile iframe sheet. Require MoMo number, pass it to Ladill Pay, and full-page redirect for mtn_momo waiting URLs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,12 +2,14 @@
|
||||
|
||||
namespace App\Services\Pay;
|
||||
|
||||
use Illuminate\Http\Client\Response;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Client for the platform Ladill Pay HTTP API — checkout and settlement for
|
||||
* merchant↔buyer money. Paystack is the processor today; settlement lands in
|
||||
* the one UserWallet via Platform Billing.
|
||||
* merchant↔buyer money. Provider is configured on the platform
|
||||
* (PAY_DEFAULT_PROVIDER); settlement lands via wallet or direct MoMo.
|
||||
*/
|
||||
class PayClient
|
||||
{
|
||||
@@ -25,9 +27,8 @@ class PayClient
|
||||
public function createCheckout(array $payload): array
|
||||
{
|
||||
$res = Http::withToken($this->token())->acceptJson()->timeout(15)->post($this->base().'/checkouts', $payload);
|
||||
$res->throw();
|
||||
|
||||
return (array) $res->json();
|
||||
return $this->jsonOrFail($res, 'Could not start checkout. Please try again.');
|
||||
}
|
||||
|
||||
public function verify(string $reference): array
|
||||
@@ -35,16 +36,36 @@ class PayClient
|
||||
$res = Http::withToken($this->token())->acceptJson()->timeout(15)->post($this->base().'/checkouts/verify', [
|
||||
'reference' => $reference,
|
||||
]);
|
||||
$res->throw();
|
||||
|
||||
return (array) $res->json();
|
||||
return $this->jsonOrFail($res, 'Could not verify payment. Please try again.');
|
||||
}
|
||||
|
||||
public function show(string $reference): array
|
||||
{
|
||||
$res = Http::withToken($this->token())->acceptJson()->timeout(10)->get($this->base().'/orders/'.$reference);
|
||||
$res->throw();
|
||||
|
||||
return $this->jsonOrFail($res, 'Could not load payment order.');
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
private function jsonOrFail(Response $res, string $fallback): array
|
||||
{
|
||||
if ($res->failed()) {
|
||||
throw new RuntimeException($this->errorMessage($res, $fallback));
|
||||
}
|
||||
|
||||
return (array) $res->json();
|
||||
}
|
||||
|
||||
private function errorMessage(Response $res, string $fallback): string
|
||||
{
|
||||
$message = $res->json('error') ?? $res->json('message');
|
||||
if (is_array($message)) {
|
||||
$message = collect($message)->flatten()->first();
|
||||
}
|
||||
|
||||
$message = trim((string) ($message ?? ''));
|
||||
|
||||
return $message !== '' ? $message : $fallback;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user