Headless SDK
The headless SDK provides a typesafe wrapper around the Hosted Capital API.
Installation
Install the package directly from NPM with npm install @wf-financing/headless-sdk.
To minimize bundle size and reduce the impact on partners' page load times, the SDK uses dynamic imports to load the required components of the SDK on demain.
Instantiation
Initialize the Wayflyer headless SDK using the loadSdk method, passing a companyToken for the current user.
import { WayflyerHeadlessSdk, type SdkOptionsType } from '@wf-financing/headless-sdk';
// e.g. instantiation in production mode
const wayflyerHeadlessSdk = await WayflyerHeadlessSdk.loadSdk(companyToken);
// e.g. instantiation in sandbox mode
const options: SdkOptionsType = { isSandbox: true };
const wayflyerHeadlessSdk = await WayflyerHeadlessSdk.loadSdk(companyToken, options);
⚠️ The companyToken should be minted using the Company Token endpoint on the partner's backend. See the Authentication guide for more details.
SDK Methods
getCta
Returns the configuration for the CTA to show to the user.
import type { CtaResponseType } from '@wf-financing/headless-sdk';
const cta: CtaResponseType = await wayflyerSdk.getCta();
startHostedApplication
Initiates a Wayflyer funding application for the customer. Returns a URL to a personalized Wayflyer landing page that the user should be redirected to.
import type { StartHostedApplicationRequestType, StartHostedApplicationResponseType } from '@wf-financing/headless-sdk';
const merchantData: StartHostedApplicationRequestType = {
company_data: {},
user_data: {},
partner_data: {},
};
const startHostedApplication: StartHostedApplicationResponseType = await wayflyerSdk.startHostedApplication(merchantData);
continueHostedApplication
Use this to continue a hosted application when the getCta() method returns a Continue Hosted Application CTA, as described in the "Continuing a hosted application" guide. Returns a URL to a personalized Wayflyer landing page that the user should be redirected to.
import type { ContinueHostedApplicationResponseType } from '@wf-financing/headless-sdk';
const continueHostedApplication: ContinueHostedApplicationResponseType = await wayflyerSdk.continueHostedApplication();
dismissCta
Use this method to notify that the user wants to dismiss the current CTA. Subsequent calls to getCta for this user will return null for a few days. Repeated dismissals will result in an exponential backoff.
await wayflyerSdk.dismissCta();