mirror of
https://github.com/anikeen-com/id.git
synced 2026-11-04 22:59:41 +00:00
Document trials without a payment method
trial_payment_method (TrialPaymentMethod::REQUIRED, the default, or ::OPTIONAL) on app subscriptions, subscriptions and checkout sessions: an optional trial can be confirmed without a payment method and is cancelled at its end if there is still none (cancellation_reason and subscription.cancelled data.reason CancellationReason::TRIAL_ENDED_WITHOUT_PAYMENT_METHOD). subscription.trial_will_end carries data.payment_method_missing.
This commit is contained in:
11 files changed
+151
-3
No files matched your search
+41
-1
@@ -383,10 +383,50 @@ $subscription = $user->subscriptions()->create([
|
||||
```
|
||||
|
||||
A few days before the trial ends, Anikeen ID sends `subscription.trial_will_end`
|
||||
(`EventType::SUBSCRIPTION_TRIAL_WILL_END`), e.g. to remind the user. Cancelling during the trial
|
||||
(`EventType::SUBSCRIPTION_TRIAL_WILL_END`), e.g. to remind the user; `data.payment_method_missing`
|
||||
tells you whether the user still has to add a payment method. Cancelling during the trial
|
||||
bills nothing. Trials work the same for app subscriptions and per subscription of a checkout
|
||||
session.
|
||||
|
||||
By default the user needs a payment method to confirm a trial. With `trial_payment_method`
|
||||
`TrialPaymentMethod::OPTIONAL` (only together with a trial; `TrialPaymentMethod::REQUIRED` is the
|
||||
default) the user can confirm it without one, as long as nothing else has to be paid: in a
|
||||
checkout session every subscription has to be such a trial. The confirmation page tells the user
|
||||
to add a payment method before the trial ends. If there is still none then, the subscription is
|
||||
**cancelled** at the trial's end instead of billed: `status` `cancelled`, `cancellation_reason`
|
||||
`CancellationReason::TRIAL_ENDED_WITHOUT_PAYMENT_METHOD`, `subscription.cancelled` with
|
||||
`data.reason` set to the same value, and no `subscription.renewed`. Adding a payment method later
|
||||
doesn't bring it back – create a new subscription. The trial still counts for `trial_once`.
|
||||
Anikeen ID also mails the user a few days before such a trial ends without a payment method.
|
||||
|
||||
```php
|
||||
use Anikeen\Id\Enums\CancellationReason;
|
||||
use Anikeen\Id\Enums\TrialPaymentMethod;
|
||||
use Anikeen\Id\Webhooks\EventType;
|
||||
|
||||
$subscription = $user->appSubscriptions()->create([
|
||||
'group' => $teamId,
|
||||
'name' => 'Uptimr Pro',
|
||||
'unit' => 'month',
|
||||
'price' => 19.00,
|
||||
'trial_days' => 14,
|
||||
'trial_payment_method' => TrialPaymentMethod::OPTIONAL,
|
||||
]);
|
||||
|
||||
// in your webhook handler
|
||||
$data = $event['data'];
|
||||
|
||||
match ($event['type']) {
|
||||
EventType::SUBSCRIPTION_TRIAL_WILL_END => $data['payment_method_missing']
|
||||
? Reminder::addPaymentMethod($data['object']['id'])
|
||||
: null,
|
||||
EventType::SUBSCRIPTION_CANCELLED => $data['reason'] === CancellationReason::TRIAL_ENDED_WITHOUT_PAYMENT_METHOD
|
||||
? Pass::downgrade($data['object']['id'])
|
||||
: Pass::revoke($data['object']['id']),
|
||||
default => null,
|
||||
};
|
||||
```
|
||||
|
||||
#### Discounts
|
||||
|
||||
A `discount` (e.g. a coupon) lowers the price of billed periods: every discounted period gets a
|
||||
|
||||
Reference in new issue
Block a user