Plans

You'll notice the default plans, in config, have keys. These keys are used to identify the plans so that you can reference them when you figure out what features each plan allows.

Maybe you have a set of plans resembling the following:

'plans' => [
    'free' => (object) [
        'id' => -1,
        'name' => 'Free',
        'description' => 'None of the fun.',
        'price' => 0,
    ],
    'yearly' => (object) [
        'id' => 123456,
        'name' => 'Yearly subscription',
        'description' => 'All of the fun.',
        'price' => 25,
        'currency' => '$',
        'interval' => 'year',
    ],
],

You don't have to have a free plan, but it is a nice way of showing new users what their account is currently set up. If you remove the free plan, and users go to the billing page; they'll see all your plans, but none of them will be selected. That might be confusing, but that might also be what you're trying to do.

If you'd like to use localization strings for name, description, and interval; you can append _lang to the key:

'yearly' => (object) [
    'id' => 123456,
    'name_lang' => 'plans.yearly_name',
    'description_lang' => 'plans.yearly_description',
    'price' => 25,
    'currency' => '$',
    'interval_lang' => 'plans.yearly_interval',
],

You should give meaningful key names to your plans. Avoid the following keys, because they mean special things to Peddle:

  • free
  • subscribed
  • admin
  • grace

When someone subscribes to one of your configured plans; you can restrict or broaden their access to features of your application by using one of the following helpers...

In Blade templates, you can use the @peddle helper:

@peddle('free')
    You are on a free account. Subscribe here...
@endpeddle

@peddle('subscribed')
    You are, now or in the past, subscribed to one of our plans...
@endpeddle

@peddle('admin')
    Your email address is recognised as an admin account.
@endpeddle

@peddle('yearly')
    You are subscribed to the plan with the "yearly" key.
@endpeddle

@peddle('grace)
    You were subscribed to a plan, but you've cancelled and are on a grace period.
@endpeddle

You can also reach into the underlying Cashier Paddle subscription code; if you need greater control:

@if(auth()->user()->subscription()->onGracePeriod())
    You have cancelled, but still have access to all the features until...
@endif

All of the @peddle keys work, using the peddle method on the Gitstore\Peddle\Models\Peddle model:

if ($user->peddle('yearly')) {
    // ...do something special for this subscriber
}

@peddle and the peddle() method are a little magical. We want it to be really easy to figure out what kind of user you're dealing with; so we added the special keys. Everything we're doing is built on top of Cashier Paddle , so you can default to doing what that library allows, if you prefer.