corefront-admin

Hey 👋

Usage no npm install needed!

<script type="module">
  import corefrontAdmin from 'https://cdn.skypack.dev/corefront-admin';
</script>

README

Core Developer Documentation

Hey 👋

Welcome to the corefront-admin sdk.

Get started by exploring our Documentation.

Install the SDK

To get started, install corefront-admin in with npm:

npm i --save corefront-admin

Setup the SDK

Next, go to your developer dashboard and create your first API Key. We recommend naming it after your app. Thereby you can see which calls come from which app.

  1. Click on your profile image and go to Api Keys
  2. Click on new key and enter a name for this key
  3. Click on Create and copy the api key afterwards

In your entry point file of your node application (e.g. server.js), enter the following code:

const corefront = require('corefront-admin')
corefront.setup('YOUR API KEY HERE')

When starting the server, the sdk will check if this API key is valid and store it for your calls.

Create a subscription

When asking a merchant to pay for your app, Shopify sends the merchant to a specific URL where the merchant can confirm the charge.

Normally you would have to create a GraphQL request based on the pricing of your app. In the response from that request, you would have a confirmationUrl, where you can redirect the user.

With the corefront-admin sdk, you can get the confirmation url way easier. First, let's setup your pricing in your developer dashboard:

Create a product

  1. Click on Products in the navigation bar
  2. Create a new product and enter your details
  3. Click on Save product and copy the product id

Right now, we only support recurring subscriptions (more to come). You can decide between annual and monthly payments. We recommend offering a trial to merchants.

Create a charge

Now that you've created a product, you can redirect the user to the confirmation url from Shopify:

//The merchant will be redirected to the return url after they confirmed the charge
const returnUrl = `https://${shop}/admin/apps/${process.env.HANDLE}/welcome`

const options = {
    test: true,
}

const chargeUrl = await corefront.billing().getChargeUrl(
    shop, 
    accessToken, 
    'YOUR PRODUCT ID', 
    returnUrl, 
    options
)

ctx.redirect(chargeUrl)

The getChargeUrl() function will return a promise. You'll get a confirmation url if the request was accepted. If something went wrong, you will get an error. So make sure to wrap this function in a try-catch block or using .then().catch().

When user is logged in that isn't the admin for this shop, the function will return an error.

Note that with the options object in this call, you can decide whether or not this will be a test charge. We recommend filtering out staff members of Shopify & enabling test charges for them, so they can use your app for free.

Get the subscription status

After you've asked the merchant to accept the subscription charges, you can get the subscription status for the specified shop by calling:

const subscription = await corefront.billing().getCurrentSubscription(shop, accessToken)

If a user doesn't have an active charge, the function will return null. Otherwise you will get an object with additional information.

Subscription object

isTrial

Indicates if the merchant is still in trial.

  • Bool

name

The name of your charge (same as in your dashboard)

  • String

price

The price the user is paying

  • Number

type

"recurring"

  • String

Create special deals with discount codes

Creating special deals for specific audiences can be a huge growth factor. However it's a lot of work to build that in with GraphQL requests. We recommend offering a longer trial or a discount on your plans.

In the Corefront developer dashboard you can create discount codes for your app in a matter of seconds.

Create a discount code

  1. Click on Discount Codes
  2. Fill out the information and click on Save discount

Discount Codes are case insensitive. If you created a discount code (e.g.: START100), your merchants can enter start100, Start100 or START100 - all of them will work.

Now, create a component in your app where merchants can enter this discount code.

Apply a discount code

You can use the discount code when getting the charge url for the subscription:

const exampleDiscount = 'START100'

const options = {
    test: true,
    discountCode: exampleDiscount,
}

const chargeUrl = await corefront.billing().getChargeUrl(
    shop, 
    accessToken, 
    'YOUR PRODUCT ID', 
    returnUrl, 
    options
)

Depending on the settings for this discount code in your developer dashboard, the merchant will get a longer trial or a percentage off of your product.

If the discount code is not valid, the merchant will receive the normal product you've created in your developer dashboard.

Roadmap

This SDK will help you save time when developing your Shopify App. We would appreciate your feedback on what other features would make your life easier.

There are a couple of things we are currently working on. For example:

  • AppUsage charges
  • One time charges
  • App credits

We also want to make it easier for you to implement pricing components in your react code, so reusable react components are also high priority for us.

Got feedback or need help setting up the SDK? Write us an email: developer@corefront.co