AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

FakeMerchantAccounts.php 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. /** @var list<string> "account:method" for every payment method asked for. */
  22. public array $methodsRequested = [];
  23. public int $statusCalls = 0;
  24. public bool $down = false;
  25. public function create(Store $store, string $email): string
  26. {
  27. $this->failIfDown();
  28. $id = 'acct_fake_'.$store->id;
  29. $this->created[] = $id;
  30. $this->statuses[$id] ??= new MerchantAccountStatus(false, false, false);
  31. return $id;
  32. }
  33. public function setupLink(string $accountId, string $returnUrl, string $refreshUrl): string
  34. {
  35. $this->failIfDown();
  36. $this->links[] = ['account' => $accountId, 'return' => $returnUrl, 'refresh' => $refreshUrl];
  37. return 'https://connect.stripe.test/setup/'.$accountId;
  38. }
  39. public function status(string $accountId): MerchantAccountStatus
  40. {
  41. $this->failIfDown();
  42. $this->statusCalls++;
  43. return $this->statuses[$accountId] ?? throw new PaymentException('Unknown account.');
  44. }
  45. public function requestMethod(string $accountId, string $method): void
  46. {
  47. $this->failIfDown();
  48. $this->methodsRequested[] = $accountId.':'.$method;
  49. if ($method === 'fpx') {
  50. $this->fpxRequested[] = $accountId;
  51. }
  52. }
  53. /**
  54. * Pretend the merchant finished Stripe's form and Stripe approved the account.
  55. */
  56. public function approve(string $accountId, bool $payouts = true): void
  57. {
  58. $this->statuses[$accountId] = new MerchantAccountStatus(true, $payouts, true);
  59. }
  60. private function failIfDown(): void
  61. {
  62. if ($this->down) {
  63. throw new PaymentException('Stripe is down.');
  64. }
  65. }
  66. }