Skip to main content
You can connect Loop to any billing system to manage subscriptions and invoicing while using Loop to process payments. Below are directions on how to accept payment with Loop and create a susbcription and record the first payment in Chargebee.

First Payment Flow

Initialize the widget with the relevant details Here are some commonly used properties. All the properties are listed here.
Property nameType or exampleDescription
minimumAuthorizationUsdAmountnumber, eg. 199 (for $1.99)The minimum USD equivalent the user must authorize from their wallet in the selected token to complete the payment. If no value is set, the invoice amount will be used.
awaitConfirmationboolean (default is true)Controls whether confirmation of the transaction on-chain is part of the payment flow. If false, the user will only wait for the PayIn to be created before the component’s state is set to “complete”.
invoiceRefIdstringA reference to an invoice being paid.

This will be blank if you are creating a new subscription in Chargebee
awaitConfirmationboolean (default is true)If the user is signing up with a free trial, this should be false because no payment happens today If the user is upgrading and should pay today, this should be set to true
billDatenumber (date in seconds)Bill date when the payment is due. Pays immediately if left empty
Create the Chargebee subscription Set the onPayInCreated event handler to create the Chargebee subscription. Here is a sample approach: The object passed to onPayInCreated function contains the Loop payIn object with ID. Call a server endpoint that creates the Chargebee user and subscription: 
  • Chargebee Customer.create - returns the customer
  • Chargebee subscription.createWithItems  - creates the subscription for the customer and returns the first invoice.
Mark the newly created invoice as paid in Chargebee.   Update Loop’s Payin Use the invoice from the response to update the PayIn in Loop to reflect the correct invoiceRefId Sample Loop SDK call to update: 
sdk.payin.update(payinId, {externalInvoiceRef: invoiceId})
At this point, everything has been created in Loop and Chargebee.

Processing Next invoices

To process follow-up invoices, the Loop flow is very simple.  SDK Sample
const result = await loop.payins.create({
        merchantId,
        amount: invoice.amountDue, 
        amountType: "fiat",
        billDate: invoice.dueDate,
        customerId: "cus_8a214", // Loop Customer ID
        subscriptionRefId: "8asukSOXdulGOV", // Chargebee Subscription ID
        invoiceRefId: "inv__10" // Chargebee Invoice ID
    });
This command will create a payin record in Loop, scheduling a payment to process on it’s bill date. The payin.created event will trigger to confirm the payin has been successfully created.  On the due date, Loop will process the payment and send a payment.processed event that confirms the transaction has been processed.  More information about the webhook structure can be found on the Webhooks Event page. If there is a pending payin that is 10 minutes past due, the missed_payin.payment webhook will fire.