Checkout Sessions component

The LoopConnectCheckoutSession component renders a customizable UI for users to connect their wallet, select a token, and complete payment for a checkout session.

Usage

import { LoopConnectCheckoutSession } from "@loop-crypto/connect-checkout";

<LoopConnectCheckoutSession
    // Optional properties go here
/>

Component properties

The following optional properties ("props") can be added to the LoopConnectCheckoutSession component for more fine grain control.

Property nameTypeDescription
stateNotification"event-only" or "embedded" (default: "embedded")When set to "embedded", the component will displays messaging above the payment button to provide details to the user about the current state of the payment process. No message is shown for the "idle" state.
failureNotification"event-only" or "embedded" (default: "embedded")When set to "embedded", the component will displays messaging above the payment button to provide details to the user about failures that occurred during the payment process.
completeNotification"event-only" or "embedded" (default: "embedded")When set to "embedded", the component will replace the payment button with details about the payment awaiting confirmation on chain when the component state is "confirmingPayment"
confirmingNotification"event-only" or "embedded" (default: "embedded")When set to "embedded", the component will replace the payment button with details about the payment once confirmed and the component state is "complete"
notificationEmailFallbackstringFallback email for notifying the user, only if no email was defined at the creation of the session
disabledboolean (default is false)Disables UI components such that they can not be interacted with by the user.

Event callbacks

Event propCallback return object typeDescription
onCheckoutSessionReadyCheckoutSessionReadyEventThe component has received the necessary data and is ready for user interaction.
onCheckoutSessionReadyFailedCheckoutSessionReadyFailedEventThe component failed to initialize.
onCheckoutSessionTokenChangeCheckoutSessionTokenChangeEventThe user has changed the selected token they wish to pay with from the component UI
onCheckoutSessionStateChangeCheckoutSessionStateChangeEventOnce a user initiates a payment, this component calls back with each step to allow you to provide detailed notifications for your users. Note that you can optionally enable a state notification message to be provided to the user within the component UI using the stateNotification property detailed above. Details on the payment states is provided below.
onCheckoutSessionAuthorizationConfirmedCheckoutSessionAuthorizationConfirmedEventThe authorization granted by the user's wallet for this token to the contract has been verified to meet he defined minimum
onCheckoutSessionAuthorizationUpdatedCheckoutSessionAuthorizationUpdatedEventThe user has updated their wallet's authorization to transfer the selected token to the contract
onCheckoutSessionCreatedCheckoutSessionCreatedEventThe payment details have been received and the transaction has been sent for processing
onCheckoutSessionConfirmedCheckoutSessionConfirmedEventThe payment transaction has been confirmed to have been written on-chain
onCheckoutSessionFailedCheckoutSessionFailedEventThe payment was not created because a require step failed or was canceled by the user. Note that you can optionally enable a failure notification message to be provided to the user within the component UI using the failureNotification property detailed above. Details on the failure types is provided below.
💡

Both onWalletChange and onNetworkChange (defined above as initLoopConnectCheckout properties) can be provided in the same format to the LoopConnectCheckoutSession component for your convenience. Just note that each individual component will trigger their own provided callback for the same event occurrence, as these events are tied to the user's wallet which is a single connection shared application wide.

onCheckoutSessionStateChange

The onCheckoutSessionStateChange event handler will receive an object which contains the state property set to one of the following string values indicating the component's current state of payment.

<LoopConnectCheckoutSession
    // other props
    onCheckoutSessionStateChange={
        ({ state, message, data }) => console.log(`${state}: ${message}`, data);
    }
/>
StateEvent data object typeDescription
idleCheckoutSessionStateChangeEventIdleThe initial state of the component prior to initiating the payment process, as well as the state set after a payment failure
confirmingBalanceCheckoutSessionStateChangeEventConfirmingBalanceAwaiting a response back from the blockchain to confirm the wallet's balance is sufficient in the selected token on the wallet's current network
confirmingAuthorizationCheckoutSessionStateChangeEventConfirmingAuthorizationAwaiting a response back from the blockchain to confirm the wallet's authorization is sufficient in the selected token on the wallet's current network for the contract required
updatingAuthorizationCheckoutSessionStateChangeEventUpdatingAuthorizationThe wallet's authorization was insufficient and is now awaiting confirmation that the user has completed their wallet's prompt to update the amount
signingMessageCheckoutSessionStateChangeEventSigningMessageAwaiting a signed message from the user's wallet which has prompted them to authorize Loop Crypto to process the payment
creatingPaymentCheckoutSessionStateChangeEventCreatingPaymentAll of the required checks have been confirmed and the payment is being sent for processing
confirmingPaymentCheckoutSessionStateChangeEventConfirmingPaymentIf the transactions is being processed synchronously, this state indicates that the component is awaiting confirmation of the transaction on-chain
completeCheckoutSessionStateChangeEventCompleteThe component remains in this state once the payment data has been received and confirmed to be sufficient to process the payment

onCheckoutSessionFailed

The onCheckoutSessionFailed event handler will receive an object which contains the type property set to one of the following string values indicating the reason the payment was not sent for processing successfully.

<LoopConnectCheckoutSession
    // other props
    onCheckoutSessionFailed={
        ({ type, message, data }) => console.log(`${type}: ${message}`, data);
    }
/>
Failure typeDescription
insufficientBalanceThe wallet connected does not have the sufficient amount of token equivalent to the amount of USD specified by paymentUsdAmount on the current network
insufficientAuthorizationThe user has not granted sufficient USD equivalent authorization for this token to meet the minimumAuthorizationUsdAmount (if not specified, uses paymentUsdAmount) on the wallet's current network
signedMessageRequiredThe wallet failed to sign a message to approve the transfer of the payment token
paymentFailedThere was a problem obtaining approval of the payment details having been sent for processing
transactionFailedThere was a problem while attempting to confirm a payment on-chain

Custom styling

The component's UI can be customized by providing a string of CSS custom properties and values. The values assigned to the property must be valid CSS for that type of property, which corresponds to a CSS declaration. In the table below, each custom property is linked to the corresponding CSS property it represents to ensure clarity.

<LoopConnectCheckoutSession
    // other props
    customStyles={`
        --loop-connect-font: italic 700 1rem 'Poppins', sans-serif;
        --loop-connect-widget-shadow: 0 0 0.5rem rgba(99,99,99,0.3);
    `}
/>
PropertyCSS property or typeDescription
--loop-connect-color-primary<color>Used as an accent color, primarily for button background, but not exclusively backgrounds
--loop-connect-color-on-primarycolorUsed as the text or accent color when shown within subcomponents colored with the primary color
--loop-connect-radiusborder-radiusDefines the roundness of box corners. Also applies to the entire widget, unless ``--loop-connect-widget-radius` overrides it
--loop-connect-color-textcolorDefines the color of text
--loop-connect-fontfontAssigns the size, weight, style and family for the font used as the main copy within the component
--loop-connect-widget-borderborderDefines the border around the entire component
--loop-connect-widget-radiusborder-radiusDefines the roundness of the corners of the component. Will override --loop-connect-radius if set
--loop-connect-widget-paddingpaddingSpecifies the padding around the outside of the main component
--loop-connect-widget-shadowbox-shadowSpecifies the styling of the outer shadow around the main component
--loop-connect-widget-backgroundbackgroundAssigns the background proprties of the main component
--loop-connect-input-borderborderOverrides the default border style of input and select subcomponents
--loop-connect-input-backgroundbackgroundAssigns a background properties of input and select subcomponents
--loop-connect-wallet-borderborderOverrides the default border style of the panel displaying the connected wallet address
--loop-connect-wallet-backgroundbackgroundAssigns a background properties to the panel displaying the connected wallet address
💡

Note that the customStyles property can also be provided to the initLoopConnectCheckout as a property and will apply the styles to all Loop Connect components application-wide. Properties then applied to individual components will override those app-wide values, creating a cascade effect.

Quickstart Example

import { StrictMode } from "react";
import { createRoot } from "react-dom/client";

// 1. Import the package
import { initLoopConnectCheckout, LoopConnectCheckoutSession } from "@loop-crypto/connect-checkout";

// 2. Initialize is outside of the application
initLoopConnectCheckout({
    checkoutSessionId: "your-checkout-session-id",
});

// 3. Add the CheckoutSession component to the React application
createRoot(document.getElementById("root")).render(
    <StrictMode>
        <LoopConnectCheckoutSession />
    </StrictMode>
);