AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SubscriptionGateway.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Billing;
  3. use App\Commerce\Payments\CheckoutLink;
  4. use App\Commerce\Payments\PaymentException;
  5. use App\Models\Plan;
  6. use App\Models\User;
  7. /**
  8. * The one interface the app uses for merchants' monthly subscriptions.
  9. * Stripe is the first provider.
  10. */
  11. interface SubscriptionGateway
  12. {
  13. /**
  14. * Register the merchant with the provider. Returns the provider's customer id.
  15. *
  16. * @throws PaymentException
  17. */
  18. public function createCustomer(User $user): string;
  19. /**
  20. * Register a plan with the provider as a monthly price.
  21. *
  22. * @return array{product: string, price: string}
  23. *
  24. * @throws PaymentException
  25. */
  26. public function createPrice(Plan $plan): array;
  27. /**
  28. * Create a payment page that starts a monthly subscription.
  29. *
  30. * @throws PaymentException
  31. */
  32. public function startCheckout(string $customerId, string $priceId, string $successUrl, string $cancelUrl): CheckoutLink;
  33. /**
  34. * The subscription that a payment page led to, or null if it was not completed.
  35. *
  36. * @throws PaymentException
  37. */
  38. public function findByCheckout(string $checkoutId): ?SubscriptionState;
  39. /**
  40. * @throws PaymentException
  41. */
  42. public function find(string $subscriptionId): SubscriptionState;
  43. /**
  44. * Move a subscription to another plan. The provider works out the price difference.
  45. *
  46. * @throws PaymentException
  47. */
  48. public function changePrice(string $subscriptionId, string $priceId): SubscriptionState;
  49. /**
  50. * Cancel at the end of the paid-for period, or undo that.
  51. *
  52. * @throws PaymentException
  53. */
  54. public function setCancelAtPeriodEnd(string $subscriptionId, bool $cancel): SubscriptionState;
  55. /**
  56. * Read a message the provider sent to our webhook address.
  57. * Returns null when the message is not about a subscription.
  58. *
  59. * @throws PaymentException When the message is not genuine.
  60. */
  61. public function readWebhook(string $payload, string $signature): ?SubscriptionState;
  62. }