| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
-
- namespace Tests\Support;
-
- use App\Commerce\Payments\MerchantAccounts;
- use App\Commerce\Payments\MerchantAccountStatus;
- use App\Commerce\Payments\PaymentException;
- use App\Models\Store;
-
- /**
- * Merchants' Stripe accounts for tests. Nothing leaves the machine.
- * Tests set what Stripe "says" about an account in $statuses.
- */
- final class FakeMerchantAccounts implements MerchantAccounts
- {
- /** @var array<string, MerchantAccountStatus> */
- public array $statuses = [];
-
- /** @var list<string> */
- public array $created = [];
-
- /** @var list<array{account: string, return: string, refresh: string}> */
- public array $links = [];
-
- /** @var list<string> */
- public array $fpxRequested = [];
-
- public int $statusCalls = 0;
-
- public bool $down = false;
-
- public function create(Store $store, string $email): string
- {
- $this->failIfDown();
-
- $id = 'acct_fake_'.$store->id;
- $this->created[] = $id;
- $this->statuses[$id] ??= new MerchantAccountStatus(false, false, false);
-
- return $id;
- }
-
- public function setupLink(string $accountId, string $returnUrl, string $refreshUrl): string
- {
- $this->failIfDown();
-
- $this->links[] = ['account' => $accountId, 'return' => $returnUrl, 'refresh' => $refreshUrl];
-
- return 'https://connect.stripe.test/setup/'.$accountId;
- }
-
- public function status(string $accountId): MerchantAccountStatus
- {
- $this->failIfDown();
- $this->statusCalls++;
-
- return $this->statuses[$accountId] ?? throw new PaymentException('Unknown account.');
- }
-
- public function requestFpx(string $accountId): void
- {
- $this->failIfDown();
-
- $this->fpxRequested[] = $accountId;
- }
-
- /**
- * Pretend the merchant finished Stripe's form and Stripe approved the account.
- */
- public function approve(string $accountId, bool $payouts = true): void
- {
- $this->statuses[$accountId] = new MerchantAccountStatus(true, $payouts, true);
- }
-
- private function failIfDown(): void
- {
- if ($this->down) {
- throw new PaymentException('Stripe is down.');
- }
- }
- }
|