*/ public array $payments = []; /** @var list */ public array $started = []; public bool $failToStart = false; public ?string $successUrl = null; public ?string $cancelUrl = null; public function name(): string { return 'fake'; } public function startCheckout(Order $order, string $successUrl, string $cancelUrl): CheckoutLink { if ($this->failToStart) { throw new PaymentException('The provider is down.'); } $id = 'cs_fake_'.$order->id; $this->started[] = $order; $this->successUrl = $successUrl; $this->cancelUrl = $cancelUrl; $this->payments[$id] = new PaymentStatus($id, paid: false); return new CheckoutLink($id, 'https://pay.test/'.$id); } public function checkPayment(string $checkoutId): PaymentStatus { return $this->payments[$checkoutId] ?? throw new PaymentException('Unknown payment.'); } public function readWebhook(string $payload, string $signature): ?PaymentStatus { if ($signature !== 'valid') { throw new PaymentException('Bad signature.'); } $data = json_decode($payload, true); return isset($data['checkout_id']) ? $this->checkPayment($data['checkout_id']) : null; } /** * Pretend the shopper paid on the payment page. */ public function pay(Order $order, ?int $amount = null): void { $id = (string) $order->fresh()?->payment_checkout_id; $this->payments[$id] = new PaymentStatus($id, paid: true, reference: 'pi_fake_'.$order->id, amount: $amount ?? $order->total); } }