AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

FakeMerchantAccounts.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Tests\Support;
  3. use App\Commerce\Payments\MerchantAccounts;
  4. use App\Commerce\Payments\MerchantAccountStatus;
  5. use App\Commerce\Payments\PaymentException;
  6. use App\Models\Store;
  7. /**
  8. * Merchants' Stripe accounts for tests. Nothing leaves the machine.
  9. * Tests set what Stripe "says" about an account in $statuses.
  10. */
  11. final class FakeMerchantAccounts implements MerchantAccounts
  12. {
  13. /** @var array<string, MerchantAccountStatus> */
  14. public array $statuses = [];
  15. /** @var list<string> */
  16. public array $created = [];
  17. /** @var list<array{account: string, return: string, refresh: string}> */
  18. public array $links = [];
  19. /** @var list<string> */
  20. public array $fpxRequested = [];
  21. public int $statusCalls = 0;
  22. public bool $down = false;
  23. public function create(Store $store, string $email): string
  24. {
  25. $this->failIfDown();
  26. $id = 'acct_fake_'.$store->id;
  27. $this->created[] = $id;
  28. $this->statuses[$id] ??= new MerchantAccountStatus(false, false, false);
  29. return $id;
  30. }
  31. public function setupLink(string $accountId, string $returnUrl, string $refreshUrl): string
  32. {
  33. $this->failIfDown();
  34. $this->links[] = ['account' => $accountId, 'return' => $returnUrl, 'refresh' => $refreshUrl];
  35. return 'https://connect.stripe.test/setup/'.$accountId;
  36. }
  37. public function status(string $accountId): MerchantAccountStatus
  38. {
  39. $this->failIfDown();
  40. $this->statusCalls++;
  41. return $this->statuses[$accountId] ?? throw new PaymentException('Unknown account.');
  42. }
  43. public function requestFpx(string $accountId): void
  44. {
  45. $this->failIfDown();
  46. $this->fpxRequested[] = $accountId;
  47. }
  48. /**
  49. * Pretend the merchant finished Stripe's form and Stripe approved the account.
  50. */
  51. public function approve(string $accountId, bool $payouts = true): void
  52. {
  53. $this->statuses[$accountId] = new MerchantAccountStatus(true, $payouts, true);
  54. }
  55. private function failIfDown(): void
  56. {
  57. if ($this->down) {
  58. throw new PaymentException('Stripe is down.');
  59. }
  60. }
  61. }