Skip to content

Commit c94cc1e

Browse files
committed
Document feature tickets
1 parent 061756e commit c94cc1e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,42 @@ $subscriber->missingFeature('deploy-minutes');
325325

326326
Similarly to `cantConsume`, it returns the reverse of `hasFeature`.
327327

328+
### Feature Tickets
329+
330+
Tickets are a simple way to allow your subscribers to acquire charges for a feature. When a user receives a ticket, he is allowed to consume its charges, just like he would do in a normal subscription. Tickets can be used to extend regular subscriptions-based systems (so you can, for instance, sell more charges of a given feature) or even to **build a fully pre-paid service**, where your users pay only for what they want to use.
331+
332+
#### Creating Tickets
333+
334+
To create a ticket, you can use the method `giveTicketFor`. This method expects the feature name, the expiration and optionally a number of charges (you can ignore it when creating tickets for not consumable features):
335+
336+
```php
337+
$subscriber->giveTicketFor('deploy-minutes', today()->addMonth(), 10);
338+
```
339+
340+
> This method will fire a `FeatureTicketCreated($subscriber, Feature $feature, FeatureTicket $featureTicket)` event.
341+
342+
In the example above, the user will receive ten more minutes to execute deploys until the next month.
343+
344+
#### Not Consumable Features
345+
346+
You can create tickets for not consumable features, so your subscribers will receive access to them just for a certain period:
347+
348+
```php
349+
class UserFeatureTrialController extends Controller
350+
{
351+
public function store(FeatureTrialRequest $request, User $user)
352+
{
353+
$featureName = $request->input('feature_name');
354+
$expiration = today()->addDays($request->input('trial_days'));
355+
$user->giveTicketFor($featureName, $expiration);
356+
357+
return redirect()->route('admin.users.show', $user);
358+
}
359+
}
360+
```
361+
362+
In the example above, the user will be able to try a feature for a certain amount of days.
363+
328364
## Testing
329365

330366
```bash

0 commit comments

Comments
 (0)