Web SDK
The Web SDK is a ready-to-use Web UI that you can easily embed into any web application, it provides a simple interface to onboard merchants into your account.
Usage
import { credify } from '@credifyit/web-sdk'
const sdk = credify.smb.init({
appKey: 'crd_1qwYswxroY5KxR...', // the APP_KEY provided by credify
token: 'eyJhbGciOiJIUzI1NiI...', // merchant token
})
// `sdk.rootEl` Returns the HTML element to render, this you can attach to your DOM the way you need.
document.querySelector('#credify-root').appendChild(sdk.rootEl)
document.querySelector('#submit-btn').addEventListener('click', () => {
// start collection
sdk.collect()
.then(() => {
console.log('collection in-progress!')
})
.catch((err) => {
console.error(err)
})
})
sdk.getStatus().then((status) => {
console.log(status)
// prints the same Merchant Status as the `/company/merchants/{id}` endpoint
/*
{
"id": "<id>",
"external_id": "<provided-id>",
"latest_update": "2008-01-10T11:00:00Z",
"is_fetching": true,
"stores": [{
"id": "507f191e810c19729de860c1",
"type": "SHOPIFY",
"name": "shop abc",
"status":"READY",
},{
"id": "7f97823810c1629de191e0ea",
"type":"AMAZON",
"name": "shop xyz",
"status":"QUEUED",
}]
}
*/
})
That's it, the SDK will show the UI and handle everything from there.
SDK Token
info
The SDK token is different from the token generated by Credify's API. It is generated the integrator.
You need to generate the token provided to the SDK as follows:
- It has to be signed with the
APP_SECRET
key provided by credify. - It has to include the following properties in the payload:
type: 'USER'
: a constant value.merchant_id
: the merchant id according to the provider for later correlation.allowed_integrations
: an array of allowed integrations to show to the merchant, use "*" to show all integrations.- options are:
["SHOPIFY", "AMAZON"]
- options are:
- Has to have audience set to credify, i.e.
aud: "credify.live"
- Has to have the issuer set to
APP_KEY
, i.e.iss: <APP_KEY>
- Our APIs will respect the
exp
claim set from your side as well.
caution
Any token that fails to meet the above criteria will be treated as invalid token and will result in HTTP 401 UNAUTHORIZED
.