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 name | Type | Description |
---|---|---|
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" |
notificationEmailFallback | string | Fallback email for notifying the user, only if no email was defined at the creation of the session |
disabled | boolean (default is false ) | Disables UI components such that they can not be interacted with by the user. |
Event callbacks
Event prop | Callback return object type | Description |
---|---|---|
onCheckoutSessionReady | CheckoutSessionReadyEvent | The component has received the necessary data and is ready for user interaction. |
onCheckoutSessionReadyFailed | CheckoutSessionReadyFailedEvent | The component failed to initialize. |
onCheckoutSessionTokenChange | CheckoutSessionTokenChangeEvent | The user has changed the selected token they wish to pay with from the component UI |
onCheckoutSessionStateChange | CheckoutSessionStateChangeEvent | Once 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. |
onCheckoutSessionAuthorizationConfirmed | CheckoutSessionAuthorizationConfirmedEvent | The authorization granted by the user's wallet for this token to the contract has been verified to meet he defined minimum |
onCheckoutSessionAuthorizationUpdated | CheckoutSessionAuthorizationUpdatedEvent | The user has updated their wallet's authorization to transfer the selected token to the contract |
onCheckoutSessionCreated | CheckoutSessionCreatedEvent | The payment details have been received and the transaction has been sent for processing |
onCheckoutSessionConfirmed | CheckoutSessionConfirmedEvent | The payment transaction has been confirmed to have been written on-chain |
onCheckoutSessionFailed | CheckoutSessionFailedEvent | The 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
andonNetworkChange
(defined above asinitLoopConnectCheckout
properties) can be provided in the same format to theLoopConnectCheckoutSession
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
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);
}
/>
State | Event data object type | Description |
---|---|---|
idle | CheckoutSessionStateChangeEventIdle | The initial state of the component prior to initiating the payment process, as well as the state set after a payment failure |
confirmingBalance | CheckoutSessionStateChangeEventConfirmingBalance | Awaiting a response back from the blockchain to confirm the wallet's balance is sufficient in the selected token on the wallet's current network |
confirmingAuthorization | CheckoutSessionStateChangeEventConfirmingAuthorization | Awaiting 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 |
updatingAuthorization | CheckoutSessionStateChangeEventUpdatingAuthorization | The wallet's authorization was insufficient and is now awaiting confirmation that the user has completed their wallet's prompt to update the amount |
signingMessage | CheckoutSessionStateChangeEventSigningMessage | Awaiting a signed message from the user's wallet which has prompted them to authorize Loop Crypto to process the payment |
creatingPayment | CheckoutSessionStateChangeEventCreatingPayment | All of the required checks have been confirmed and the payment is being sent for processing |
confirmingPayment | CheckoutSessionStateChangeEventConfirmingPayment | If the transactions is being processed synchronously, this state indicates that the component is awaiting confirmation of the transaction on-chain |
complete | CheckoutSessionStateChangeEventComplete | The component remains in this state once the payment data has been received and confirmed to be sufficient to process the payment |
onCheckoutSessionFailed
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 type | Description |
---|---|
insufficientBalance | The wallet connected does not have the sufficient amount of token equivalent to the amount of USD specified by paymentUsdAmount on the current network |
insufficientAuthorization | The 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 |
signedMessageRequired | The wallet failed to sign a message to approve the transfer of the payment token |
paymentFailed | There was a problem obtaining approval of the payment details having been sent for processing |
transactionFailed | There 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);
`}
/>
Property | CSS property or type | Description |
---|---|---|
--loop-connect-color-primary | <color> | Used as an accent color, primarily for button background, but not exclusively backgrounds |
--loop-connect-color-on-primary | color | Used as the text or accent color when shown within subcomponents colored with the primary color |
--loop-connect-radius | border-radius | Defines the roundness of box corners. Also applies to the entire widget, unless ``--loop-connect-widget-radius` overrides it |
--loop-connect-color-text | color | Defines the color of text |
--loop-connect-font | font | Assigns the size, weight, style and family for the font used as the main copy within the component |
--loop-connect-widget-border | border | Defines the border around the entire component |
--loop-connect-widget-radius | border-radius | Defines the roundness of the corners of the component. Will override --loop-connect-radius if set |
--loop-connect-widget-padding | padding | Specifies the padding around the outside of the main component |
--loop-connect-widget-shadow | box-shadow | Specifies the styling of the outer shadow around the main component |
--loop-connect-widget-background | background | Assigns the background proprties of the main component |
--loop-connect-input-border | border | Overrides the default border style of input and select subcomponents |
--loop-connect-input-background | background | Assigns a background properties of input and select subcomponents |
--loop-connect-wallet-border | border | Overrides the default border style of the panel displaying the connected wallet address |
--loop-connect-wallet-background | background | Assigns a background properties to the panel displaying the connected wallet address |
Note that the
customStyles
property can also be provided to theinitLoopConnectCheckout
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>
);
Updated 5 days ago