-
-
Notifications
You must be signed in to change notification settings - Fork 374
Creating a Billable App
First of all, its best to read up on Shopify's documentation to get to know how it works internally.
To enable billing on your app, there is configuration already in config/shopify-app.php
which is based on environment variables. Using these variables, here is what you need to setup.
Here is an example setup to get a basic app into billable mode:
SHOPIFY_BILLING_ENABLED=1
SHOPIFY_BILLING_TYPE=recurring
SHOPIFY_BILLING_PLAN="Demo Plan"
SHOPIFY_BILLING_TEST=1
SHOPIFY_BILLING_PRICE=15.00
SHOPIFY_BILLING_TRIAL_DAYS=14
Here is an explanation of the configuration, many are already set with sane-defaults:
SHOPIFY_BILLING_ENABLED=0
to disable billing state for application (default)
SHOPIFY_BILLING_ENABLED=1
to enable billing state for application
SHOPIFY_BILLING_TYPE=recurring
for recurring monthly billing (default)
SHOPIFY_BILLING_TYPE=single
for a one-time charge
SHOPIFY_BILLING_PLAN="Your plan name"
for a plan name to display to the customer
SHOPIFY_BILLING_PRICE=0.00
for a price of the plan
SHOPIFY_BILLING_TRIAL_DAYS=0
for number of days for trial (default: 7)
SHOPIFY_BILLING_TEST=0
to disable testing mode (default)
SHOPIFY_BILLING_TEST=1
to enable testing mode
SHOPIFY_BILLING_REDIRECT="/url/path"
for setting the path to handle the accepting or declining of the application charge (default: /billing/proccess)
Note: Its not recommended to change this unless you're using custom logic or overriding the billing controller.
Once you've set the required environment variables, you're ready to go.
Here's how the flow works:
- Shop installs the app
- Shop accepts the app's permissions
- Shop is presented with the billing screen to accept or decline
- 3a. If they accept, charge is activated, charge ID is saved to database, shop is sent to your app's homepage
- 3b. If they decline, charge is marked declined, shop is sent to error screen saying they did not pay.
Note: If billing is being applied on top of an existing app, when the shop accesses your app, they will sent to the billing screen.
Grandfather mode is useful when you wish to give a shop free access to your app. A simple boolean flag in the database (grandfathered
) tells the billable middleware to let them through.
UPDATE shops SET grandfathered = 1 WHERE shopify_domain = "domain.myshopify.com"
// Lookup
$shop = Shop::where('shopify_domain', 'domain.myshopify.com')->first();
// Or, for a current shop logged in
$shop = ShopifyApp::shop();
$shop->grandfathered = 1;
$shop->save();
$shop->isPaid()
will return true or false if a shop has a charge_id
in the database.
Also accessible: $shop->charge_id
to get the raw charge ID.
$shop->isGrandfathered()
will return true or false if a shop is grandfathered in.
Shopify internally handles cancelling the previous plan. You simply need to direct the shop to the billing screen to accept the new charge.
Programmatically, you can do this with the package's BillingPlan
class.
road map
Welcome to the wiki!
Please see the homepage for a list of relevant pages.