@blocklet/payment-react 1.22.32 → 1.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/.aigne/doc-smith/translation-cache.yaml +2 -2
  2. package/.aigne/doc-smith/upload-cache.yaml +342 -0
  3. package/docs/assets/diagram/auto-topup-diagram-0.ja.jpg +0 -0
  4. package/docs/assets/diagram/auto-topup-diagram-0.zh-TW.jpg +0 -0
  5. package/docs/assets/diagram/auto-topup-diagram-0.zh.jpg +0 -0
  6. package/docs/assets/diagram/components-business-overdue-invoice-payment-01.ja.jpg +0 -0
  7. package/docs/assets/diagram/components-business-overdue-invoice-payment-01.jpg +0 -0
  8. package/docs/assets/diagram/components-business-overdue-invoice-payment-01.zh-TW.jpg +0 -0
  9. package/docs/assets/diagram/components-business-overdue-invoice-payment-01.zh.jpg +0 -0
  10. package/docs/assets/diagram/components-checkout-checkout-donate-01.ja.jpg +0 -0
  11. package/docs/assets/diagram/components-checkout-checkout-donate-01.jpg +0 -0
  12. package/docs/assets/diagram/components-checkout-checkout-donate-01.zh-TW.jpg +0 -0
  13. package/docs/assets/diagram/components-checkout-checkout-donate-01.zh.jpg +0 -0
  14. package/docs/assets/diagram/components-checkout-checkout-table-01.ja.jpg +0 -0
  15. package/docs/assets/diagram/components-checkout-checkout-table-01.jpg +0 -0
  16. package/docs/assets/diagram/components-checkout-checkout-table-01.zh-TW.jpg +0 -0
  17. package/docs/assets/diagram/components-checkout-checkout-table-01.zh.jpg +0 -0
  18. package/docs/assets/diagram/components-diagram-0.ja.jpg +0 -0
  19. package/docs/assets/diagram/components-diagram-0.zh-TW.jpg +0 -0
  20. package/docs/assets/diagram/components-diagram-0.zh.jpg +0 -0
  21. package/docs/assets/diagram/overview-01.ja.jpg +0 -0
  22. package/docs/assets/diagram/overview-01.jpg +0 -0
  23. package/docs/assets/diagram/overview-01.zh-TW.jpg +0 -0
  24. package/docs/assets/diagram/overview-01.zh.jpg +0 -0
  25. package/docs/assets/diagram/payment-provider-diagram-0.ja.jpg +0 -0
  26. package/docs/assets/diagram/payment-provider-diagram-0.zh-TW.jpg +0 -0
  27. package/docs/assets/diagram/payment-provider-diagram-0.zh.jpg +0 -0
  28. package/docs/assets/diagram/phone-input-diagram-0.ja.jpg +0 -0
  29. package/docs/assets/diagram/phone-input-diagram-0.zh-TW.jpg +0 -0
  30. package/docs/assets/diagram/phone-input-diagram-0.zh.jpg +0 -0
  31. package/docs/assets/diagram/providers-01.ja.jpg +0 -0
  32. package/docs/assets/diagram/providers-01.jpg +0 -0
  33. package/docs/assets/diagram/providers-01.zh-TW.jpg +0 -0
  34. package/docs/assets/diagram/providers-01.zh.jpg +0 -0
  35. package/docs/assets/diagram/resume-subscription-diagram-0.ja.jpg +0 -0
  36. package/docs/assets/diagram/resume-subscription-diagram-0.zh-TW.jpg +0 -0
  37. package/docs/assets/diagram/resume-subscription-diagram-0.zh.jpg +0 -0
  38. package/docs/assets/diagram/use-subscription-diagram-0.ja.jpg +0 -0
  39. package/docs/assets/diagram/use-subscription-diagram-0.zh-TW.jpg +0 -0
  40. package/docs/assets/diagram/use-subscription-diagram-0.zh.jpg +0 -0
  41. package/docs/components-business-auto-topup.ja.md +2 -2
  42. package/docs/components-business-auto-topup.md +1 -1
  43. package/docs/components-business-auto-topup.zh-TW.md +2 -2
  44. package/docs/components-business-auto-topup.zh.md +2 -2
  45. package/docs/components-business-overdue-invoice-payment.ja.md +3 -39
  46. package/docs/components-business-overdue-invoice-payment.md +99 -90
  47. package/docs/components-business-overdue-invoice-payment.zh-TW.md +3 -40
  48. package/docs/components-business-overdue-invoice-payment.zh.md +3 -40
  49. package/docs/components-business-resume-subscription.ja.md +2 -2
  50. package/docs/components-business-resume-subscription.md +1 -1
  51. package/docs/components-business-resume-subscription.zh-TW.md +2 -2
  52. package/docs/components-business-resume-subscription.zh.md +2 -2
  53. package/docs/components-checkout-checkout-donate.ja.md +3 -36
  54. package/docs/components-checkout-checkout-donate.md +135 -128
  55. package/docs/components-checkout-checkout-donate.zh-TW.md +3 -36
  56. package/docs/components-checkout-checkout-donate.zh.md +3 -36
  57. package/docs/components-checkout-checkout-form.md +63 -82
  58. package/docs/components-checkout-checkout-table.ja.md +3 -35
  59. package/docs/components-checkout-checkout-table.md +112 -72
  60. package/docs/components-checkout-checkout-table.zh-TW.md +3 -35
  61. package/docs/components-checkout-checkout-table.zh.md +3 -36
  62. package/docs/components-checkout.md +11 -49
  63. package/docs/components-ui-form-elements-phone-input.ja.md +2 -2
  64. package/docs/components-ui-form-elements-phone-input.md +1 -1
  65. package/docs/components-ui-form-elements-phone-input.zh-TW.md +2 -2
  66. package/docs/components-ui-form-elements-phone-input.zh.md +2 -2
  67. package/docs/components.ja.md +2 -2
  68. package/docs/components.md +1 -1
  69. package/docs/components.zh-TW.md +2 -2
  70. package/docs/components.zh.md +2 -2
  71. package/docs/hooks-use-subscription.ja.md +2 -2
  72. package/docs/hooks-use-subscription.md +1 -1
  73. package/docs/hooks-use-subscription.zh-TW.md +2 -2
  74. package/docs/hooks-use-subscription.zh.md +2 -2
  75. package/docs/overview.ja.md +3 -39
  76. package/docs/overview.md +25 -56
  77. package/docs/overview.zh-TW.md +3 -39
  78. package/docs/overview.zh.md +3 -39
  79. package/docs/providers-payment-provider.ja.md +2 -2
  80. package/docs/providers-payment-provider.md +1 -1
  81. package/docs/providers-payment-provider.zh-TW.md +2 -2
  82. package/docs/providers-payment-provider.zh.md +2 -2
  83. package/docs/providers.ja.md +3 -23
  84. package/docs/providers.md +11 -29
  85. package/docs/providers.zh-TW.md +3 -23
  86. package/docs/providers.zh.md +3 -23
  87. package/es/history/credit/transactions-list.js +31 -49
  88. package/es/locales/en.js +20 -4
  89. package/es/locales/zh.js +20 -4
  90. package/lib/history/credit/transactions-list.js +63 -66
  91. package/lib/locales/en.js +20 -4
  92. package/lib/locales/zh.js +20 -4
  93. package/package.json +3 -3
  94. package/src/history/credit/transactions-list.tsx +54 -64
  95. package/src/locales/en.tsx +20 -4
  96. package/src/locales/zh.tsx +20 -4
@@ -1,91 +1,64 @@
1
1
  # CheckoutForm
2
2
 
3
- The `CheckoutForm` component is the primary entry point for handling payment links and checkout sessions. It acts as a high-level wrapper that fetches all necessary data based on a provided ID and renders the appropriate payment or donation interface. This component is the simplest way to integrate a complete checkout flow into your application.
3
+ The `CheckoutForm` component is the primary entry point for handling payment links and checkout sessions. It serves as a high-level wrapper that automatically fetches the necessary data based on a provided ID and renders the appropriate payment or donation interface. This component provides the most straightforward method for integrating a complete checkout flow into your application.
4
4
 
5
- It's essential to wrap `CheckoutForm` or any of its parent components with the `PaymentProvider` to ensure it has access to the necessary context, such as session information and API configuration. For more details, please refer to the [PaymentProvider documentation](./providers-payment-provider.md).
5
+ For the `CheckoutForm` to function correctly, it must be nested within a `PaymentProvider`. This provider supplies the necessary context, such as session information and API configuration. For detailed setup instructions, please refer to the [PaymentProvider documentation](./providers-payment-provider.md).
6
6
 
7
7
  ## How It Works
8
8
 
9
- The component orchestrates the entire checkout process:
9
+ The component manages the entire checkout process through a clear, sequential flow:
10
10
 
11
- 1. **Initialization**: It's mounted with a `paymentLink` ID (prefixed with `plink_`) or a `checkoutSession` ID (prefixed with `cs_`).
12
- 2. **Data Fetching**: It communicates with the payment backend to retrieve all necessary context, including payment methods, line items, and customer details.
13
- 3. **UI Rendering**: Based on the `formType` prop, it internally renders either the standard `Payment` component or the specialized `DonationForm` component.
14
- 4. **State Management**: It handles the entire lifecycle of the payment, including loading states, completion status, and error handling.
15
-
16
- ```d2 Basic Flow of CheckoutForm icon=lucide:workflow
17
- direction: down
18
- shape: sequence_diagram
19
-
20
- User-Action: {
21
- shape: c4-person
22
- label: "User"
23
- }
24
-
25
- Application: {
26
- label: "Your React Application"
27
-
28
- CheckoutForm-Component: {
29
- label: "CheckoutForm"
30
- }
31
-
32
- Payment-Component: {
33
- label: "Payment Component"
34
- }
35
-
36
- Donation-Component: {
37
- label: "DonationForm Component"
38
- }
39
- }
40
-
41
- Payment-API: {
42
- label: "Payment Backend API"
43
- shape: cylinder
44
- }
45
-
46
- User-Action -> Application.CheckoutForm-Component: "1. Mounts with 'id' prop"
47
- Application.CheckoutForm-Component -> Payment-API: "2. Fetch session data"
48
- Payment-API -> Application.CheckoutForm-Component: "3. Return checkout context"
49
-
50
- alt "if formType is 'payment'" {
51
- Application.CheckoutForm-Component -> Application.Payment-Component: "4. Renders Payment UI"
52
- }
53
-
54
- alt "if formType is 'donation'" {
55
- Application.CheckoutForm-Component -> Application.Donation-Component: "5. Renders Donation UI"
56
- }
57
-
58
- User-Action -> Application.Payment-Component: "6. Completes payment"
59
- User-Action -> Application.Donation-Component: "7. Completes donation"
60
-
61
- ```
11
+ 1. **Initialization**: The component is mounted with an `id` prop, which must be either a `paymentLink` ID (prefixed with `plink_`) or a `checkoutSession` ID (prefixed with `cs_`).
12
+ 2. **Data Fetching**: It sends a request to the payment backend to retrieve the complete checkout context, which includes available payment methods, line items, and customer details.
13
+ 3. **UI Rendering**: Based on the `formType` prop, it internally renders either the standard `Payment` component for purchases or the specialized `DonationForm` for contributions.
14
+ 4. **State Management**: It handles the full lifecycle of the transaction, managing loading states, completion status, and any potential errors.
62
15
 
63
16
  ## Props
64
17
 
65
- The `CheckoutForm` component accepts the following props:
66
-
67
- | Prop | Type | Required | Default | Description |
68
- |---------------|----------------------------------------------------------------------------|----------|---------------|-------------------------------------------------------------------------------------------------------------------------|
69
- | `id` | `string` | Yes | - | The unique identifier for the payment link (`plink_...`) or checkout session (`cs_...`). |
70
- | `mode` | `'standalone'` \| `'inline'` \| `'popup'` \| `'inline-minimal'` \| `'popup-minimal'` | No | `'inline'` | Defines the rendering mode. `'standalone'` for a full-page view, `'inline'` to embed in a container. |
71
- | `formType` | `'payment'` \| `'donation'` | No | `'payment'` | Determines the type of form to render. Use `'donation'` for the specialized donation flow. |
72
- | `onPaid` | `(res: CheckoutContext) => void` | No | - | Callback function executed upon successful payment. Receives the final checkout context as an argument. |
73
- | `onError` | `(err: Error) => void` | No | `console.error` | Callback function executed when an error occurs during the process. |
74
- | `onChange` | `(data: CheckoutFormData) => void` | No | - | Callback function that fires when any form field value changes. |
75
- | `goBack` | `() => void` | No | - | If provided, renders a back button and calls this function when clicked. |
76
- | `extraParams` | `Record<string, any>` | No | `{}` | An object of extra parameters to be passed in the URL when initiating a session from a payment link. |
77
- | `theme` | `'default'` \| `'inherit'` \| `PaymentThemeOptions` | No | `'default'` | Controls the component's theme. `'inherit'` uses the parent theme, or you can pass a custom theme object. |
78
- | `action` | `string` | No | `''` | A string identifier used for customizing UI elements like button text or tracking specific flows. |
79
-
80
- ## Usage
18
+ The `CheckoutForm` component is configured using the following properties.
19
+
20
+ <x-field-group>
21
+ <x-field data-name="id" data-type="string" data-required="true">
22
+ <x-field-desc markdown>The unique identifier for the payment link (`plink_...`) or checkout session (`cs_...`).</x-field-desc>
23
+ </x-field>
24
+ <x-field data-name="mode" data-type="'standalone' | 'inline' | 'popup' | 'inline-minimal' | 'popup-minimal'" data-required="false" data-default="inline">
25
+ <x-field-desc markdown>Defines the rendering mode. `'standalone'` creates a full-page view, while `'inline'` embeds the form within an existing container. The `-minimal` variants hide the order summary.</x-field-desc>
26
+ </x-field>
27
+ <x-field data-name="formType" data-type="'payment' | 'donation'" data-required="false" data-default="payment">
28
+ <x-field-desc markdown>Specifies the type of form to render. Use `'donation'` to activate the specialized donation user interface.</x-field-desc>
29
+ </x-field>
30
+ <x-field data-name="onPaid" data-type="(res: CheckoutContext) => void" data-required="false">
31
+ <x-field-desc markdown>A callback function that is executed upon successful payment completion. It receives the final checkout context as an argument.</x-field-desc>
32
+ </x-field>
33
+ <x-field data-name="onError" data-type="(err: Error) => void" data-required="false" data-default="console.error">
34
+ <x-field-desc markdown>A callback function that is executed if an error occurs during the checkout process.</x-field-desc>
35
+ </x-field>
36
+ <x-field data-name="onChange" data-type="(data: CheckoutFormData) => void" data-required="false">
37
+ <x-field-desc markdown>A callback function that fires whenever a value in the payment form changes.</x-field-desc>
38
+ </x-field>
39
+ <x-field data-name="goBack" data-type="() => void" data-required="false">
40
+ <x-field-desc markdown>If provided, a back button is rendered. This function is called when the button is clicked.</x-field-desc>
41
+ </x-field>
42
+ <x-field data-name="extraParams" data-type="Record<string, any>" data-required="false" data-default="{}">
43
+ <x-field-desc markdown>An object containing extra parameters to be appended to the URL when initiating a checkout session from a payment link.</x-field-desc>
44
+ </x-field>
45
+ <x-field data-name="theme" data-type="'default' | 'inherit' | PaymentThemeOptions" data-required="false" data-default="default">
46
+ <x-field-desc markdown>Controls the component's theme. `'inherit'` uses the parent theme, while `'default'` applies the library's standard theme. A custom theme object can also be provided.</x-field-desc>
47
+ </x-field>
48
+ <x-field data-name="action" data-type="string" data-required="false" data-default="''">
49
+ <x-field-desc markdown>A string identifier used for customizing UI elements, such as button text, or for tracking specific analytics events.</x-field-desc>
50
+ </x-field>
51
+ </x-field-group>
52
+
53
+ ## Usage Examples
81
54
 
82
55
  ### Basic Inline Payment Form
83
56
 
84
- This is the most common use case for embedding a payment form directly within your application's UI. The component handles all the logic internally.
57
+ This is the most common use case, where the payment form is embedded directly into a page of your application. The component handles all data fetching and state management internally.
85
58
 
86
- ```tsx MyStorePage.tsx icon=lucide:shopping-cart
59
+ ```javascript MyStorePage.jsx icon=logos:react
87
60
  import { PaymentProvider, CheckoutForm } from '@blocklet/payment-react';
88
- import { useSessionContext } from './hooks/session-context'; // Your app's session hook
61
+ import { useSessionContext } from './hooks/session-context'; // This is an example hook from your application
89
62
 
90
63
  export default function MyStorePage() {
91
64
  const { session, connectApi } = useSessionContext();
@@ -118,19 +91,28 @@ export default function MyStorePage() {
118
91
 
119
92
  ### Standalone Full-Page Checkout
120
93
 
121
- Use `mode="standalone"` to render a dedicated, full-page checkout experience. This is ideal for scenarios where you redirect the user to a separate page to complete their payment.
94
+ Use `mode="standalone"` to render a dedicated, full-page checkout experience. This mode is ideal for redirecting the user to a separate URL to complete their payment without distractions.
122
95
 
123
- ```tsx CheckoutPage.tsx icon=lucide:layout-template
96
+ ```javascript CheckoutPage.jsx icon=logos:react
124
97
  import { PaymentProvider, CheckoutForm } from '@blocklet/payment-react';
125
98
  import { useSessionContext } from './hooks/session-context';
126
99
 
127
100
  export default function CheckoutPage() {
128
101
  const { session, connectApi } = useSessionContext();
129
- const paymentLinkId = 'plink_xxxxxxxxxxxxxx'; // Can be retrieved from URL params
102
+
103
+ // In a real application, you would get this ID from the URL parameters
104
+ const paymentLinkId = 'plink_xxxxxxxxxxxxxx';
130
105
 
131
106
  return (
132
107
  <PaymentProvider session={session} connectApi={connectApi}>
133
- <CheckoutForm id={paymentLinkId} mode="standalone" />
108
+ <CheckoutForm
109
+ id={paymentLinkId}
110
+ mode="standalone"
111
+ onPaid={() => {
112
+ // Redirect to a success page
113
+ window.location.href = '/payment-success';
114
+ }}
115
+ />
134
116
  </PaymentProvider>
135
117
  );
136
118
  }
@@ -138,9 +120,9 @@ export default function CheckoutPage() {
138
120
 
139
121
  ### Donation Form
140
122
 
141
- By setting `formType="donation"`, the component renders a specialized UI tailored for donation campaigns, including features like amount presets and benefit displays.
123
+ By setting `formType="donation"`, the component renders a specialized UI tailored for donation campaigns. This form includes features such as amount presets and can display information about the benefits of donating.
142
124
 
143
- ```tsx DonationPage.tsx icon=lucide:gift
125
+ ```javascript DonationPage.jsx icon=lucide:gift
144
126
  import { PaymentProvider, CheckoutForm } from '@blocklet/payment-react';
145
127
  import { useSessionContext } from './hooks/session-context';
146
128
 
@@ -149,7 +131,7 @@ export default function DonationPage() {
149
131
 
150
132
  return (
151
133
  <PaymentProvider session={session} connectApi={connectApi}>
152
- <div style={{ padding: '2rem' }}>
134
+ <div style={{ padding: '2rem', textAlign: 'center' }}>
153
135
  <h2>Support Our Cause</h2>
154
136
  <CheckoutForm
155
137
  id="plink_yyyyyyyyyyyyyy" // Replace with your Donation Link ID
@@ -160,5 +142,4 @@ export default function DonationPage() {
160
142
  </PaymentProvider>
161
143
  );
162
144
  }
163
- ```
164
-
145
+ ```
@@ -13,41 +13,9 @@
13
13
  3. **セッションの作成**: ユーザーがプランを選択すると、コンポーネントはバックエンドと通信して安全なチェックアウトセッションを作成します。
14
14
  4. **支払いの処理**: その後、セッション詳細が事前に入力された`CheckoutForm`を表示し、ユーザーが支払い情報を入力して取引を完了できるようにします。
15
15
 
16
- ```d2 CheckoutTable フロー図
17
- direction: down
18
-
19
- ユーザー: {
20
- shape: c4-person
21
- }
22
-
23
- CheckoutTable-Component: {
24
- label: "CheckoutTable コンポーネント"
25
- shape: rectangle
26
-
27
- Pricing-Table-View: {
28
- label: "価格表ビュー"
29
- }
30
-
31
- Checkout-Form-View: {
32
- label: "チェックアウトフォームビュー"
33
- }
34
- }
35
-
36
- Payment-API: {
37
- label: "支払いAPI"
38
- shape: cylinder
39
- }
40
-
41
- ユーザー -> CheckoutTable-Component.Pricing-Table-View: "1. プランを閲覧"
42
- CheckoutTable-Component.Pricing-Table-View -> ユーザー: " "
43
- ユーザー -> CheckoutTable-Component.Pricing-Table-View: "2. プランを選択"
44
- CheckoutTable-Component.Pricing-Table-View -> Payment-API: "3. チェックアウトセッションを作成"
45
- Payment-API -> CheckoutTable-Component.Pricing-Table-View: "4. セッションIDを返す"
46
- CheckoutTable-Component.Pricing-Table-View -> CheckoutTable-Component.Checkout-Form-View: "5. セッションIDで移行"
47
- ユーザー -> CheckoutTable-Component.Checkout-Form-View: "6. 支払い詳細を入力して支払う"
48
- CheckoutTable-Component.Checkout-Form-View -> ユーザー: ""
49
-
50
- ```
16
+ <!-- DIAGRAM_IMAGE_START:flowchart:4:3::1765377358 -->
17
+ ![CheckoutTable](assets/diagram/components-checkout-checkout-table-01.ja.jpg)
18
+ <!-- DIAGRAM_IMAGE_END -->
51
19
 
52
20
  ## Props
53
21
 
@@ -6,67 +6,53 @@ It internally uses the [`PricingTable`](./components-ui-pricing-table.md) compon
6
6
 
7
7
  ## How it Works
8
8
 
9
- The checkout flow managed by `CheckoutTable` is straightforward:
9
+ The checkout flow managed by `CheckoutTable` is straightforward. The following diagram illustrates the sequence of events from displaying plans to finalizing the transaction:
10
+
11
+ <!-- DIAGRAM_IMAGE_START:flowchart:4:3:1765377358 -->
12
+ ![CheckoutTable](assets/diagram/components-checkout-checkout-table-01.jpg)
13
+ <!-- DIAGRAM_IMAGE_END -->
10
14
 
11
15
  1. **Fetch Data**: The component fetches the pricing table configuration from the server using the provided `id`.
12
16
  2. **Display Plans**: It renders the subscription plans in a responsive table, allowing users to switch between billing intervals (e.g., monthly/yearly) and currencies.
13
17
  3. **Create Session**: When a user selects a plan, the component communicates with the backend to create a secure checkout session.
14
18
  4. **Process Payment**: It then displays the `CheckoutForm`, pre-filled with the session details, allowing the user to enter their payment information and finalize the transaction.
15
19
 
16
- ```d2 CheckoutTable Flow Diagram
17
- direction: down
18
-
19
- User: {
20
- shape: c4-person
21
- }
22
-
23
- CheckoutTable-Component: {
24
- label: "CheckoutTable Component"
25
- shape: rectangle
26
-
27
- Pricing-Table-View: {
28
- label: "Pricing Table View"
29
- }
30
-
31
- Checkout-Form-View: {
32
- label: "Checkout Form View"
33
- }
34
- }
35
-
36
- Payment-API: {
37
- label: "Payment API"
38
- shape: cylinder
39
- }
40
-
41
- User -> CheckoutTable-Component.Pricing-Table-View: "1. Views plans"
42
- CheckoutTable-Component.Pricing-Table-View -> User: " "
43
- User -> CheckoutTable-Component.Pricing-Table-View: "2. Selects a plan"
44
- CheckoutTable-Component.Pricing-Table-View -> Payment-API: "3. Create checkout session"
45
- Payment-API -> CheckoutTable-Component.Pricing-Table-View: "4. Return session ID"
46
- CheckoutTable-Component.Pricing-Table-View -> CheckoutTable-Component.Checkout-Form-View: "5. Transition with session ID"
47
- User -> CheckoutTable-Component.Checkout-Form-View: "6. Fills payment details & pays"
48
- CheckoutTable-Component.Checkout-Form-View -> User: ""
49
-
50
- ```
51
-
52
20
  ## Props
53
21
 
54
- | Prop | Type | Required | Default | Description |
55
- |---------------|-----------------------------------|----------|--------------|------------------------------------------------------------------------------------------------------------------------------------------|
56
- | `id` | `string` | Yes | - | The ID of the pricing table to display (must start with `prctbl_`). |
57
- | `mode` | `'standalone'` or `'embedded'` | No | `'embedded'` | The display mode. `'standalone'` redirects to a separate page, while `'embedded'` handles the flow inline within the component. |
58
- | `onPaid` | `(sessionId: string) => void` | No | - | Callback function triggered when the payment is successfully completed. |
59
- | `onError` | `(error: Error) => void` | No | - | Callback function for handling errors during the checkout process. |
60
- | `onChange` | `(data: any) => void` | No | - | Callback for any state change within the checkout form. |
61
- | `extraParams` | `Record<string, any>` | No | `{}` | An object of extra parameters to be sent when creating the checkout session, useful for passing custom data like a user ID. |
62
- | `goBack` | `() => void` | No | - | A function to handle the back action from the payment form, returning the user to the pricing table view. |
63
- | `theme` | `object` or `'inherit'` | No | - | Custom Material-UI theme object to style the component. For more details, see the [Theming guide](./guides-theming.md). |
22
+ The `CheckoutTable` component accepts the following props to customize its behavior and handle events.
23
+
24
+ <x-field-group>
25
+ <x-field data-name="id" data-type="string" data-required="true">
26
+ <x-field-desc markdown>The ID of the pricing table to display. This value must be prefixed with `prctbl_`.</x-field-desc>
27
+ </x-field>
28
+ <x-field data-name="mode" data-type="'standalone' | 'embedded'" data-required="false" data-default="embedded">
29
+ <x-field-desc markdown>The display mode. In `'standalone'` mode, the user is redirected to a separate hosted page upon selecting a plan. In `'embedded'` mode, the entire checkout flow occurs inline within the component.</x-field-desc>
30
+ </x-field>
31
+ <x-field data-name="onPaid" data-type="(sessionId: string) => void" data-required="false">
32
+ <x-field-desc markdown>A callback function that is triggered when a payment is successfully completed. It receives the `sessionId` of the transaction.</x-field-desc>
33
+ </x-field>
34
+ <x-field data-name="onError" data-type="(error: Error) => void" data-required="false">
35
+ <x-field-desc markdown>A callback function for handling any errors that occur during the checkout process.</x-field-desc>
36
+ </x-field>
37
+ <x-field data-name="onChange" data-type="(data: any) => void" data-required="false">
38
+ <x-field-desc markdown>A callback function that is triggered for any state change within the underlying `CheckoutForm` component.</x-field-desc>
39
+ </x-field>
40
+ <x-field data-name="extraParams" data-type="Record<string, any>" data-required="false">
41
+ <x-field-desc markdown>An object containing extra parameters to be sent to the server when creating the checkout session. This is useful for passing custom data, such as a user ID or tracking information.</x-field-desc>
42
+ </x-field>
43
+ <x-field data-name="goBack" data-type="() => void" data-required="false">
44
+ <x-field-desc markdown>A function to handle the back action from the payment form, which returns the user to the pricing table view. The component manages the UI transition; this callback is for synchronizing external application state.</x-field-desc>
45
+ </x-field>
46
+ <x-field data-name="theme" data-type="object | 'inherit'" data-required="false">
47
+ <x-field-desc markdown>A custom Material-UI theme object to style the component, or `'inherit'` to use the ambient theme. For more details, see the [Theming guide](./guides-theming.md).</x-field-desc>
48
+ </x-field>
49
+ </x-field-group>
64
50
 
65
51
  ## Usage
66
52
 
67
53
  To use the `CheckoutTable` component, you must wrap it in a `PaymentProvider`. Pass the pricing table `id` and an `onPaid` callback to handle successful transactions.
68
54
 
69
- ```javascript Basic CheckoutTable Example icon=logos:react
55
+ ```javascript MyCheckoutPage.jsx icon=logos:react
70
56
  import { PaymentProvider, CheckoutTable } from '@blocklet/payment-react';
71
57
  import { useSessionContext } from './path-to-your-session-context'; // Centralize this context as per guidelines
72
58
 
@@ -86,7 +72,7 @@ export default function MyCheckoutPage() {
86
72
  <PaymentProvider session={session} connectApi={connectApi}>
87
73
  <div style={{ height: '700px', width: '100%' }}>
88
74
  <CheckoutTable
89
- id="prctbl_xxxxxxxxxxxxxxxx" // Replace with your actual pricing table ID
75
+ id="prctbl_z2v5NvY3tYjH2zK8yL9xP6" // Replace with your actual pricing table ID
90
76
  onPaid={handlePaymentSuccess}
91
77
  />
92
78
  </div>
@@ -105,44 +91,98 @@ By default, `CheckoutTable` operates in `'embedded'` mode. The component manages
105
91
 
106
92
  By setting `mode='standalone'`, the component's behavior changes. When a user selects a plan, they are redirected to a dedicated, hosted checkout page. This mode is useful for simpler integrations that don't require an embedded payment form.
107
93
 
108
- ```javascript Standalone Mode icon=logos:react
109
- <CheckoutTable
110
- id="prctbl_xxxxxxxxxxxxxxxx"
111
- mode="standalone"
112
- />
94
+ ```javascript StandaloneMode.jsx icon=logos:react
95
+ import { PaymentProvider, CheckoutTable } from '@blocklet/payment-react';
96
+ import { useSessionContext } from './path-to-your-session-context';
97
+
98
+ export default function StandaloneCheckout() {
99
+ const { session, connectApi } = useSessionContext();
100
+
101
+ if (!session) {
102
+ return <div>Loading session...</div>;
103
+ }
104
+
105
+ return (
106
+ <PaymentProvider session={session} connectApi={connectApi}>
107
+ <CheckoutTable
108
+ id="prctbl_z2v5NvY3tYjH2zK8yL9xP6"
109
+ mode="standalone"
110
+ />
111
+ </PaymentProvider>
112
+ );
113
+ }
113
114
  ```
114
115
 
115
116
  ## Advanced Usage
116
117
 
117
118
  ### Handling Back Navigation
118
119
 
119
- The `goBack` prop allows you to define custom logic when the user navigates back from the payment form to the pricing table. The component handles the view transition automatically, but this callback is useful for synchronizing your application's state.
120
+ The `goBack` prop allows you to define custom logic for when the user navigates back from the payment form to the pricing table. The component handles the view transition automatically, but this callback is useful for synchronizing your application's state.
121
+
122
+ ```javascript GoBackExample.jsx icon=logos:react
123
+ import { PaymentProvider, CheckoutTable } from '@blocklet/payment-react';
124
+ import { useSessionContext } from './path-to-your-session-context';
125
+ import { useState } from 'react';
126
+
127
+ export default function CheckoutWithBackNavigation() {
128
+ const { session, connectApi } = useSessionContext();
129
+ const [view, setView] = useState('pricing');
130
+
131
+ const handleGoBack = () => {
132
+ console.log('User returned to the pricing table.');
133
+ setView('pricing');
134
+ };
120
135
 
121
- ```javascript goBack Prop Example icon=logos:react
122
- const handleGoBack = () => {
123
- console.log('User returned to the pricing table.');
124
- // You can add custom logic here, like updating your app's state.
125
- };
136
+ if (!session) {
137
+ return <div>Loading session...</div>;
138
+ }
126
139
 
127
- <CheckoutTable
128
- id="prctbl_xxxxxxxxxxxxxxxx"
129
- onPaid={handlePaymentSuccess}
130
- goBack={handleGoBack}
131
- />
140
+ return (
141
+ <PaymentProvider session={session} connectApi={connectApi}>
142
+ <div style={{ height: '700px', width: '100%' }}>
143
+ <CheckoutTable
144
+ id="prctbl_z2v5NvY3tYjH2zK8yL9xP6"
145
+ onPaid={() => alert('Payment successful!')}
146
+ goBack={handleGoBack}
147
+ onChange={() => setView('payment')}
148
+ />
149
+ </div>
150
+ </PaymentProvider>
151
+ );
152
+ }
132
153
  ```
133
154
 
134
155
  ### Passing Extra Parameters
135
156
 
136
157
  Use the `extraParams` prop to send additional data when creating the checkout session. This data can be associated with the resulting payment and is useful for tracking and reconciliation on your backend.
137
158
 
138
- ```javascript extraParams Example icon=logos:react
139
- <CheckoutTable
140
- id="prctbl_xxxxxxxxxxxxxxxx"
141
- onPaid={handlePaymentSuccess}
142
- extraParams={{ userId: 'user_123', source: 'marketing_campaign' }}
143
- />
159
+ ```javascript ExtraParamsExample.jsx icon=logos:react
160
+ import { PaymentProvider, CheckoutTable } from '@blocklet/payment-react';
161
+ import { useSessionContext } from './path-to-your-session-context';
162
+
163
+ export default function CheckoutWithExtraParams() {
164
+ const { session, connectApi } = useSessionContext();
165
+
166
+ if (!session) {
167
+ return <div>Loading session...</div>;
168
+ }
169
+
170
+ const user = { id: 'user_12345' }; // Example user object
171
+
172
+ return (
173
+ <PaymentProvider session={session} connectApi={connectApi}>
174
+ <div style={{ height: '700px', width: '100%' }}>
175
+ <CheckoutTable
176
+ id="prctbl_z2v5NvY3tYjH2zK8yL9xP6"
177
+ onPaid={() => alert('Payment successful!')}
178
+ extraParams={{ userId: user.id, source: 'marketing_campaign' }}
179
+ />
180
+ </div>
181
+ </PaymentProvider>
182
+ );
183
+ }
144
184
  ```
145
185
 
146
186
  ## Customization
147
187
 
148
- While `CheckoutTable` is a high-level component designed for ease of use, you can achieve more granular control by using its constituent parts. For a fully custom UI, you can use the [`PricingTable`](./components-ui-pricing-table.md) component to display plans and then manually trigger a checkout session that renders in a [`CheckoutForm`](./components-checkout-checkout-form.md).
188
+ While `CheckoutTable` is a high-level component designed for ease of use, you can achieve more granular control by using its constituent parts. For a fully custom UI, you can use the [`PricingTable`](./components-ui-pricing-table.md) component to display plans and then manually trigger a checkout session that renders in a [`CheckoutForm`](./components-checkout-checkout-form.md).
@@ -13,41 +13,9 @@
13
13
  3. **建立會話**:當使用者選擇一個方案時,該元件會與後端通訊以建立一個安全的結帳會話。
14
14
  4. **處理付款**:然後它會顯示 `CheckoutForm`,預先填入會話詳細資訊,讓使用者輸入他們的付款資訊並完成交易。
15
15
 
16
- ```d2 CheckoutTable 流程圖
17
- direction: down
18
-
19
- 使用者: {
20
- shape: c4-person
21
- }
22
-
23
- CheckoutTable-Component: {
24
- label: "CheckoutTable 元件"
25
- shape: rectangle
26
-
27
- Pricing-Table-View: {
28
- label: "價格表視圖"
29
- }
30
-
31
- Checkout-Form-View: {
32
- label: "結帳表單視圖"
33
- }
34
- }
35
-
36
- Payment-API: {
37
- label: "付款 API"
38
- shape: cylinder
39
- }
40
-
41
- 使用者 -> CheckoutTable-Component.Pricing-Table-View: "1. 查看方案"
42
- CheckoutTable-Component.Pricing-Table-View -> 使用者: " "
43
- 使用者 -> CheckoutTable-Component.Pricing-Table-View: "2. 選擇方案"
44
- CheckoutTable-Component.Pricing-Table-View -> Payment-API: "3. 建立結帳會話"
45
- Payment-API -> CheckoutTable-Component.Pricing-Table-View: "4. 返回會話 ID"
46
- CheckoutTable-Component.Pricing-Table-View -> CheckoutTable-Component.Checkout-Form-View: "5. 透過會話 ID 轉換"
47
- 使用者 -> CheckoutTable-Component.Checkout-Form-View: "6. 填寫付款詳細資訊並付款"
48
- CheckoutTable-Component.Checkout-Form-View -> 使用者: ""
49
-
50
- ```
16
+ <!-- DIAGRAM_IMAGE_START:flowchart:4:3::1765377358 -->
17
+ ![CheckoutTable](assets/diagram/components-checkout-checkout-table-01.zh-TW.jpg)
18
+ <!-- DIAGRAM_IMAGE_END -->
51
19
 
52
20
  ## Props
53
21
 
@@ -13,42 +13,9 @@
13
13
  3. **创建会话**:当用户选择一个方案时,该组件会与后端通信以创建一个安全的结账会话。
14
14
  4. **处理支付**:然后它会显示 `CheckoutForm`,预先填充了会话详细信息,允许用户输入他们的支付信息并完成交易。
15
15
 
16
- ```d2 CheckoutTable 流程图
17
- direction: down
18
-
19
- User: {
20
- shape: c4-person
21
- label: "用户"
22
- }
23
-
24
- CheckoutTable-Component: {
25
- label: "CheckoutTable 组件"
26
- shape: rectangle
27
-
28
- Pricing-Table-View: {
29
- label: "价格表视图"
30
- }
31
-
32
- Checkout-Form-View: {
33
- label: "结账表单视图"
34
- }
35
- }
36
-
37
- Payment-API: {
38
- label: "支付 API"
39
- shape: cylinder
40
- }
41
-
42
- User -> CheckoutTable-Component.Pricing-Table-View: "1. 查看方案"
43
- CheckoutTable-Component.Pricing-Table-View -> User: " "
44
- User -> CheckoutTable-Component.Pricing-Table-View: "2. 选择方案"
45
- CheckoutTable-Component.Pricing-Table-View -> Payment-API: "3. 创建结账会话"
46
- Payment-API -> CheckoutTable-Component.Pricing-Table-View: "4. 返回会话 ID"
47
- CheckoutTable-Component.Pricing-Table-View -> CheckoutTable-Component.Checkout-Form-View: "5. 使用会话 ID 进行过渡"
48
- User -> CheckoutTable-Component.Checkout-Form-View: "6. 填写支付详情并支付"
49
- CheckoutTable-Component.Checkout-Form-View -> User: ""
50
-
51
- ```
16
+ <!-- DIAGRAM_IMAGE_START:flowchart:4:3::1765377358 -->
17
+ ![CheckoutTable](assets/diagram/components-checkout-checkout-table-01.zh.jpg)
18
+ <!-- DIAGRAM_IMAGE_END -->
52
19
 
53
20
  ## Props
54
21