The Dropin is a Javascript modal that allows integrators to initialise Billing Request Flows all from within their own websites.
Include the GoCardless Dropin initialise script on each page of your site:
<script src="https://pay.gocardless.com/billing/static/dropin/v2/initialise.js"></script>
You are discouraged from bundling the initialisation script or vendoring it, as GoCardless reserves the right to make non-breaking changes to the underlying implementation, which you will want your sites to pickup automatically.
We guarantee backward compatibility between major versions of the initialise script, as denoted by the script source URL.
A typical pattern is to create the Billing Request in your sites backend server, along with a Billing Request Flow, then pass the ID of that flow to the client to open the modal.
This ensures your backend can store a reference to the Billing Request, often against an internal customer record.
Provide the Billing Request Flow ID to the client to open the Dropin modal:
const handler = GoCardlessDropin.open({
// Billing Request Flow ID, generated by your backend
billingRequestFlowID,
// onSuccess receives the Billing Request that has been worked.
//
// This is called when the flow exits successfully. Depending on how the flow
// was configured, it may have completed successfully but not fulfilled the
// Billing Request- it is incumbent on the integrator to check the status of
// the request before assuming it has been fulfilled.
onSuccess: (billingRequest, billingRequestFlow) => {},
// onExit should take two arguments: an error object and a metadata object.
//
// The onExit callback is called when the customer left the flow before
// completion. This can happen because either they have voluntarily abandoned
// the flow, or because an unrecoverable error occurred.
//
// The error object is null if no error was encountered. At the time of
// writing no additional object property is documented.
//
// The metadata object is always not null. At the time of writing no
// additional object properties are documented.
onExit: (error, metadata) => {},
})
You should register callback handlers that allow your site to respond to payer activity in the Dropin, such as successful completion or exit.
If you wish to close the modal, you may do so programmatically with:
handler.exit()