DRAFT - Not implemented

Recurring payment plans

Setting up plans

Create a Plan for each payment plan you'd like to provide. A good place to do this is in a database seeder.

\App\Plan::create([
    'handle' => 'standard',
    'name' => 'Standard Package',
    'price' => 5.00,
    'trial_days' => 7
]);
\App\Plan::create([
    'handle' => 'premium',
    'name' => 'Premium Package',
    'price' => 10.00,
    'trial_days' => 0
]);

Activating plans

Activating plans follows the same process as activating a one-off charge.

// Action: MyController@switchPlan
$shop = ...;
$plan = ...;

$redirectUrl = \URL::action('MyController@afterSwitchPlan');
$confirmUrl = $shop->switchPlan($plan, $redirectUrl);

return redirect()->to($confirmUrl);

Esc/Shopify will handle attempting to activate the charge, then redirect the user to $redirectUrl with old_plan_id and new_plan_id parameters.

// Action: MyController@afterSwitchPlan
$shop = ...;

$currentPlan = $shop->getPlan(); // Either null or a Plan

// The same if the new plan was declined, otherwise different.
$oldPlanId = $request->get('old_plan_id');
$newPlanId = $request->get('new_plan_id');


// You can test if the shop is on a certain plan by referring to it's handle or an instance.
if ($shop->onPlan('premium')) {
}
if ($shop->onPlan(\App\Plan::find(2)) {
}

results matching ""

    No results matching ""