Used to check for browser translation.
用于检测浏览器翻译。
ブラウザの翻訳を検出する
Components

CheckoutTable


The CheckoutTable component provides a complete, out-of-the-box solution for displaying a pricing table and handling the entire checkout flow. It fetches pricing table data by ID, allows users to select a plan, and then either redirects them to a checkout page or renders an inline payment form.

This component is a high-level abstraction that internally uses PricingTable for display and CheckoutForm for payment processing, simplifying the integration of subscription or one-time payment flows.

How It Works#

The component follows a clear, logical flow to guide the user from plan selection to payment completion.

Success

Error

User selects a plan

Success

Yes

No (Embedded)

Payment Success

Payment Error

Error

CheckoutTable Mounted with 'id'

Fetch Pricing Table Data

Display PricingTable

Display Error Message

handleSelect()

Create Checkout Session via API

mode === 'standalone' ?

Redirect to Checkout URL

Update URL hash with Session ID

Render CheckoutForm

onPaid() callback

onError() callback

Show Toast Error


Props#

The CheckoutTable component requires a PaymentProvider to be present in the component tree. For more details, refer to the PaymentProvider documentation.

Prop

Type

Required

Description

id

string

Yes

The ID of the pricing table to display. This must start with prctbl_.

mode

'standalone' | 'embedded'

No

Determines the checkout behavior. In 'standalone' mode, the user is redirected to a separate checkout page. In 'embedded' mode (default), the CheckoutForm is rendered inline, replacing the pricing table.

onPaid

(data: TCheckout) => void

No

Callback function executed when the payment is successfully completed. It receives the final checkout session data.

onError

(err: Error) => void

No

Callback function executed if an error occurs during the payment process.

onChange

(session: TCheckout) => void

No

Callback function executed whenever the checkout session state changes (e.g., from pending to processing).

extraParams

object

No

An object containing extra query parameters to be sent when creating the checkout session.

goBack

() => void

No

A function that is called when the user clicks the "back" button on the CheckoutForm. This enables navigation back to the pricing table view in embedded mode.

theme

object | 'inherit'

No

A custom Material-UI theme object to style the component. Set to 'inherit' to use the ambient theme without an additional ThemeProvider.

Usage Scenarios#

CheckoutTable can be configured for two primary user experiences: a full-page redirect or a seamless embedded flow.

Standalone Mode#

In standalone mode, the component handles plan selection and then redirects the user to a dedicated, hosted checkout page. This is the simplest way to integrate.

import { CheckoutTable, PaymentProvider } from '@blocklet/payment-react';

function MyPaymentPage() {
const paymentProps = {
serviceHost: 'https://payment.arcblock.io',
// other required provider props
};

return (
<PaymentProvider {...paymentProps}>
<div style={{ height: '600px', width: '100%' }}>
<CheckoutTable
id="prctbl_xxxxxxxxxxxx" // Replace with your actual pricing table ID
mode="standalone"
/>
</div>
</PaymentProvider>
);
}

When a user clicks a subscription button in the pricing table, window.location.replace is called to navigate them to the checkout URL provided by the payment service API.

Embedded Mode#

In embedded mode (the default behavior), the entire checkout process happens within your application. After a plan is selected, the pricing table is replaced by the CheckoutForm component.

This mode relies on the URL hash (#) to store and retrieve the checkout session ID, enabling a smooth, single-page application experience.

import { CheckoutTable, PaymentProvider } from '@blocklet/payment-react';

function MyEmbeddedCheckout() {
const paymentProps = {
serviceHost: 'https://payment.arcblock.io',
// other required provider props
};

const handlePaymentSuccess = (checkoutData) => {
console.log('Payment successful!', checkoutData);
alert('Thank you for your payment!');
};

const handlePaymentError = (error) => {
console.error('Payment failed:', error);
alert('There was an issue with your payment.');
};

const handleGoBack = () => {
// The component handles clearing the URL hash internally.
// You can add custom logic here if needed.
console.log('User returned to the pricing table view.');
};

return (
<PaymentProvider {...paymentProps}>
<div style={{ height: '800px', width: '100%' }}>
<CheckoutTable
id="prctbl_xxxxxxxxxxxx" // Replace with your actual pricing table ID
onPaid={handlePaymentSuccess}
onError={handlePaymentError}
goBack={handleGoBack}
/>
</div>
</PaymentProvider>
);
}

In this example:

  • The onPaid and onError callbacks are used to handle the final state of the transaction.
  • The goBack prop enables a back button on the payment form, allowing users to return to the plan selection screen without losing context.