Implement the Plugin Installation Flow
Bold encourages developers to use integrations in order to extend Bold Checkout, instead of plugins. There are two types of integrations: private and public. For more information, refer to Extend Bold Checkout.
Merchants install public plugins via the Checkout Marketplace, which is found in the Bold Checkout app. The following gif shows the typical process for installing a plugin:
There are several stages of communication between Bold and the plugin to enable this installation flow. The following steps explain how to set up this exchange.
These steps are also shown in the oauth.js
file of the Checkout Example Plugin.
Identify and request required scopes
When a merchant clicks Install, Checkout Marketplace displays the scopes that the plugin requires. Each scope describes the operation the plugin would like to perform. For more information, refer to the scopes section of the Plugins page.
The following steps explain how to configure your plugin to display the appropriate scopes when prompted.
Refer to these lines in the Checkout Example Plugin for a sample implementation of these steps.
Define the scopes your plugin requires
Each action requires a certain scope. The full list of actions and their associated scopes can be found in the Plugin Action Reference — use this page to determine which scopes your plugin needs.
If you decide that your plugin requires different scopes than it originally requested, the merchant must uninstall and reinstall the plugin to use those scopes on that store.
Bold calls the Install Redirect URL
When a merchant clicks Install, Bold Checkout calls your plugin's Install Redirect URL (which you provided to Bold in the Plugin Intake Form) with information about the merchant's store.
The following code snippet shows the call Bold makes to your plugin. In this call,
platform
is the platform of the store.shop
is the platform-specific identifier of the store.
GET https://examplestore.myplatform.com/install?platform={platform}&shop={shop}
Plugin replies with scopes
Your plugin must accept this call, create a list of scopes, and respond to Bold with a redirect.
The following code snippet shows an example of this redirect. In this response,
platform
is the platform of the store.shop
is the platform-specific identifier of the store.client_id
is the publicly-available identifier for your plugin.scope
is the space-delimited list of scopes that your plugin requires.
res.redirect(
`https://cashier.boldcommerce.com/api/v1/${platform}/${shop}/oauth/authorize?client_id=${client_id}&scope=${scope}&response_type=code`
);
When Bold receives this redirect from the plugin, Checkout Marketplace displays the scopes requested and prompts the merchant to accept or deny them.
Authorize the plugin
After examining the scopes that the plugin requests, a merchant can click Allow or Cancel.
The following steps explain how to authorize an installation of the plugin on the store if the merchant clicks Allow.
Refer to these lines in the Checkout Example Plugin for a sample implementation of these steps.
Bold calls the Authorize Redirect URL
After a merchant clicks Allow, Bold calls your plugin's Authorize Redirect URL (which you provided to Bold in the Plugin Intake Form).
The following code snippet shows the call Bold makes to your plugin. In this call,
platform
is the platform of the store.shop
is the platform-specific identifier of the store.code
is a temporary authorization code generated by Bold.
GET https://example-plugin.com/authorize?platform={platform}&shop={shop}&code={code}
This call notifies the plugin that someone would like to install it.
Exchange temporary code for an access token
In order for the plugin to make calls to Bold on behalf of a certain merchant, it needs an API access token. The plugin must request that API access token for every store it is installed on.
The following snippet shows an example of this call from the plugin to Bold. In this call,
client_id
is the publicly-available identifier for your plugin.client_secret
is the string provided by Bold to ensure secure communication between the plugin and Bold.code
is the code provided when Bold called your Authorize Redirect URL.grant_type
is the type of authorization the plug requests.
POST https://cashier.boldcommerce.com/api/v1/{platform}/{shop}/oauth/access_token
--data {
"client_id": "d5cb40ab-05af-4168-b1e0-a37660824779",
"client_secret": "kjjcEyJdRzn1dusPU5aAChHZC1s3DWHS0ZdRKgxxIUbEPf6wqPRZTpJjUPmUj116",
"code": "mnU8xUaGr1ACMDl793tnJEN7gBmT9SN8YLFcmRh7q72hIsy61HeYfHRUyjW0SxSL",
"grant_type": "authorization_code"
}
In response to this call, Bold sends a response with information about the store and the API access token. The following snippet shows an example:
{
"shop": "examplestore.myplatform.com",
"platform": "shopify",
"access_token": "yPdckrPdqOHkyBkx0spIgNhXLi5jI8uXaNxXvJqOJ7g0N2ljAvJqBGpgEsclsfkt",
"scope": "add_tags provide_discounts",
"token_type": "bearer"
}
The access_token
represents an installation of the plugin on one store. The plugin must store each access_token
in a database. Use the access token in future calls made on behalf of the store.