| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
-
- namespace App\Billing;
-
- use App\Commerce\Payments\CheckoutLink;
- use App\Commerce\Payments\PaymentException;
- use App\Models\Plan;
- use App\Models\User;
-
- /**
- * The one interface the app uses for merchants' monthly subscriptions.
- * Stripe is the first provider.
- */
- interface SubscriptionGateway
- {
- /**
- * Register the merchant with the provider. Returns the provider's customer id.
- *
- * @throws PaymentException
- */
- public function createCustomer(User $user): string;
-
- /**
- * Register a plan with the provider as a monthly price.
- *
- * @return array{product: string, price: string}
- *
- * @throws PaymentException
- */
- public function createPrice(Plan $plan): array;
-
- /**
- * Create a payment page that starts a monthly subscription.
- *
- * @throws PaymentException
- */
- public function startCheckout(string $customerId, string $priceId, string $successUrl, string $cancelUrl): CheckoutLink;
-
- /**
- * The subscription that a payment page led to, or null if it was not completed.
- *
- * @throws PaymentException
- */
- public function findByCheckout(string $checkoutId): ?SubscriptionState;
-
- /**
- * @throws PaymentException
- */
- public function find(string $subscriptionId): SubscriptionState;
-
- /**
- * Move a subscription to another plan. The provider works out the price difference.
- *
- * @throws PaymentException
- */
- public function changePrice(string $subscriptionId, string $priceId): SubscriptionState;
-
- /**
- * Cancel at the end of the paid-for period, or undo that.
- *
- * @throws PaymentException
- */
- public function setCancelAtPeriodEnd(string $subscriptionId, bool $cancel): SubscriptionState;
-
- /**
- * Read a message the provider sent to our webhook address.
- * Returns null when the message is not about a subscription.
- *
- * @throws PaymentException When the message is not genuine.
- */
- public function readWebhook(string $payload, string $signature): ?SubscriptionState;
- }
|