@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,95 +1,55 @@
1
1
  # CheckoutDonate
2
2
 
3
- The `CheckoutDonate` component provides a flexible and easy-to-integrate solution for adding donation functionality to your application. It supports various display modes, from a simple button that opens a checkout dialog to a fully custom UI that you control.
3
+ This document provides a detailed guide to implementing the `CheckoutDonate` component, a flexible solution for adding donation functionality to your application. By following these steps, you will learn how to configure the component, set up the required providers, and utilize its various display modes to create a seamless donation experience.
4
4
 
5
- This component must be wrapped within both a `PaymentProvider` and a `DonateProvider` to function correctly. The `DonateProvider` manages the settings and state for donation instances within a specific scope of your application.
5
+ The `CheckoutDonate` component is designed to be highly customizable, supporting everything from a simple donation button to a fully bespoke user interface. It must be wrapped within both a `PaymentProvider` and a `DonateProvider` to manage state and connect to the payment backend.
6
6
 
7
- ## How It Works
8
-
9
- The donation flow is orchestrated by a combination of `DonateProvider` and `CheckoutDonate`. Here's a high-level overview:
10
-
11
- ```d2 How It Works icon=graph-ql:diagram
12
- direction: down
13
-
14
- user: {
15
- shape: c4-person
16
- }
17
-
18
- app: {
19
- label: "Your React App"
20
-
21
- checkout-donate: {
22
- label: "CheckoutDonate"
23
- }
24
-
25
- checkout-form: {
26
- label: "CheckoutForm (in Dialog)"
27
- }
28
- }
29
-
30
- payment-api: {
31
- label: "Payment Backend API"
32
- shape: cylinder
33
- }
7
+ ## Provider Setup
34
8
 
35
- # Initial Load
36
- app.checkout-donate -> payment-api: "Fetches settings & supporters"
37
-
38
- # Donation Flow
39
- user -> app.checkout-donate: "1. Clicks Donate"
40
- app.checkout-donate -> app.checkout-form: "2. Opens Dialog with CheckoutForm"
41
- app.checkout-form -> payment-api: "3. Processes Payment"
42
- payment-api -> app.checkout-form: "4. Returns Success"
43
- app.checkout-form -> app.checkout-donate: "5. Triggers onPaid callback"
44
- app.checkout-donate -> payment-api: "6. Refetches supporters list"
45
- payment-api -> app.checkout-donate: "7. Returns updated supporters"
46
- ```
9
+ Correctly setting up the `PaymentProvider` and `DonateProvider` is a prerequisite for using `CheckoutDonate`. The `PaymentProvider` handles the connection to the payment service, while the `DonateProvider` manages the configuration and state for donation instances within a specific part of your application.
47
10
 
48
- 1. **Initialization**: `DonateProvider` fetches and caches donation settings (like preset amounts, button text) from the backend, identified by a unique `mountLocation`.
49
- 2. **Rendering**: `CheckoutDonate` renders a button or custom UI based on the retrieved settings and its props.
50
- 3. **Interaction**: When a user initiates a donation, `CheckoutDonate` opens a dialog containing a `CheckoutForm` pre-configured for the donation.
51
- 4. **Payment**: The user completes the payment through the `CheckoutForm`.
52
- 5. **Confirmation**: After a successful payment, the `onPaid` callback is triggered, and the component automatically refreshes the list of supporters.
11
+ The following diagram illustrates how these providers wrap the `CheckoutDonate` component and interact with the payment backend and your application's session context.
53
12
 
54
- ## Provider Setup
13
+ <!-- DIAGRAM_IMAGE_START:flowchart:4:3:1765377352 -->
14
+ ![CheckoutDonate](assets/diagram/components-checkout-checkout-donate-01.jpg)
15
+ <!-- DIAGRAM_IMAGE_END -->
55
16
 
56
- Before using `CheckoutDonate`, you must wrap your component tree with `PaymentProvider` and `DonateProvider`.
17
+ The example below demonstrates the required provider structure. The `DonateProvider` is configured with a unique `mountLocation` to distinguish this donation context from others in your application.
57
18
 
58
- ```tsx Provider Setup Example icon=logos:react
19
+ ```javascript ProviderSetup.jsx icon=logos:react
59
20
  import {
60
21
  PaymentProvider,
61
22
  DonateProvider,
62
23
  CheckoutDonate,
63
24
  } from '@blocklet/payment-react';
64
- import { useSessionContext } from '../hooks/session-context'; // Your session context hook
25
+ import { useSessionContext } from '../hooks/session-context'; // This is your app's session context hook
65
26
 
66
- function DonationPage() {
67
- const { session, connect } = useSessionContext();
27
+ function DonationSection() {
28
+ const { session, connectApi } = useSessionContext();
68
29
 
69
- // Ensure session is loaded before rendering providers
70
30
  if (!session) {
71
- return <div>Loading...</div>;
31
+ return <div>Loading session...</div>;
72
32
  }
73
33
 
74
34
  return (
75
- <PaymentProvider session={session} connect={connect}>
35
+ <PaymentProvider session={session} connectApi={connectApi}>
76
36
  <DonateProvider
77
- mountLocation="unique-page-identifier" // A unique key for this donation context
78
- description="Donation for my awesome blog post"
37
+ mountLocation="blog-post-donations"
38
+ description="Handles all donations for blog posts"
79
39
  defaultSettings={{
80
40
  btnText: 'Support Me',
41
+ historyType: 'avatar',
81
42
  }}>
82
- {/* Your CheckoutDonate component goes here */}
83
- <CheckoutDonate
43
+ <CheckoutDonate
84
44
  settings={{
85
- target: "post-123",
86
- title: "Support the Author",
87
- description: "If you find this article helpful, feel free to buy me a coffee",
88
- reference: "https://your-site.com/posts/123",
45
+ target: 'post-123',
46
+ title: 'Support the Author',
47
+ description: 'If you found this article helpful, consider a small donation.',
48
+ reference: 'https://example.com/posts/123',
89
49
  beneficiaries: [
90
50
  {
91
- address: "z2qa...",
92
- share: "100",
51
+ address: 'z2qa...gCLd', // Author's DID address
52
+ share: '100',
93
53
  },
94
54
  ],
95
55
  }}
@@ -100,44 +60,87 @@ function DonationPage() {
100
60
  }
101
61
  ```
102
62
 
103
- For more details, see the [`DonateProvider`](./providers-donate-provider.md) documentation.
63
+ For a more in-depth explanation of its props and functionality, please refer to the [DonateProvider documentation](./providers-donate-provider.md).
104
64
 
105
65
  ## Component Props
106
66
 
107
- ### `DonateProps`
108
-
109
- | Prop | Type | Description |
110
- | --- | --- | --- |
111
- | `settings` | `CheckoutDonateSettings` | **Required.** Configuration for this specific donation instance. |
112
- | `onPaid` | `(session) => void` | Optional. Callback function executed after a successful payment. |
113
- | `onError` | `(error) => void` | Optional. Callback function executed if an error occurs. |
114
- | `mode` | `'default' \| 'inline' \| 'custom'` | Optional. The rendering mode. Defaults to `'default'`. |
115
- | `livemode` | `boolean` | Optional. Overrides the `livemode` from `PaymentProvider`. |
116
- | `timeout` | `number` | Optional. Milliseconds to wait before closing the dialog after payment. Defaults to `5000`. |
117
- | `theme` | `'default' \| 'inherit' \| object` | Optional. Theme customization options. See the [Theming](./guides-theming.md) guide. |
118
- | `children` | `(openDialog, donateTotalAmount, supporters, loading, donateSettings) => React.ReactNode` | Optional. A render prop function used only when `mode="custom"`. |
67
+ The `CheckoutDonate` component accepts several props to control its behavior and appearance.
68
+
69
+ <x-field-group>
70
+ <x-field data-name="settings" data-type="CheckoutDonateSettings" data-required="true">
71
+ <x-field-desc markdown>Configuration object for this specific donation instance. See the `CheckoutDonateSettings` section below for details.</x-field-desc>
72
+ </x-field>
73
+ <x-field data-name="onPaid" data-type="(session: TCheckoutSessionExpanded) => void" data-required="false">
74
+ <x-field-desc markdown>Callback function executed after a successful donation. It receives the checkout session details as an argument.</x-field-desc>
75
+ </x-field>
76
+ <x-field data-name="onError" data-type="(error: Error) => void" data-required="false">
77
+ <x-field-desc markdown>Callback function executed if an error occurs during the payment process.</x-field-desc>
78
+ </x-field>
79
+ <x-field data-name="mode" data-type="'default' | 'inline' | 'custom'" data-default="default" data-required="false">
80
+ <x-field-desc markdown>Specifies the rendering mode. `'default'` shows a button and supporter list. `'inline'` shows a button that opens a popover. `'custom'` uses a render prop for a completely custom UI.</x-field-desc>
81
+ </x-field>
82
+ <x-field data-name="inlineOptions" data-type="object" data-required="false">
83
+ <x-field-desc markdown>Configuration options specific to the `'inline'` mode.</x-field-desc>
84
+ <x-field data-name="button" data-type="ButtonType" data-required="false">
85
+ <x-field-desc markdown>Custom properties for the inline button, such as `text` and `icon`.</x-field-desc>
86
+ </x-field>
87
+ </x-field>
88
+ <x-field data-name="livemode" data-type="boolean" data-required="false">
89
+ <x-field-desc markdown>Overrides the `livemode` setting from `PaymentProvider`. Set to `true` for live transactions or `false` for test transactions.</x-field-desc>
90
+ </x-field>
91
+ <x-field data-name="timeout" data-type="number" data-default="5000" data-required="false">
92
+ <x-field-desc markdown>The delay in milliseconds before the donation dialog closes automatically after a successful payment.</x-field-desc>
93
+ </x-field>
94
+ <x-field data-name="theme" data-type="'default' | 'inherit' | PaymentThemeOptions" data-default="default" data-required="false">
95
+ <x-field-desc markdown>Controls the component's styling. See the [Theming guide](./guides-theming.md) for more information.</x-field-desc>
96
+ </x-field>
97
+ <x-field data-name="children" data-type="function" data-required="false">
98
+ <x-field-desc markdown>A render prop function used only when `mode` is set to `'custom'`. See the Custom UI Mode example for the function signature.</x-field-desc>
99
+ </x-field>
100
+ </x-field-group>
119
101
 
120
102
  ### `CheckoutDonateSettings`
121
103
 
122
- This object is passed to the `settings` prop and defines the core details of the donation.
123
-
124
- | Property | Type | Description |
125
- | --- | --- | --- |
126
- | `target` | `string` | **Required.** A unique identifier for the donation target (e.g., a post ID, a project name). |
127
- | `title` | `string` | **Required.** The title displayed at the top of the donation dialog. |
128
- | `description` | `string` | **Required.** A short description displayed in the donation dialog. |
129
- | `reference` | `string` | **Required.** A URL related to the donation, used for reference. |
130
- | `beneficiaries` | `PaymentBeneficiary[]` | **Required.** An array of objects defining who receives the funds. Each object needs an `address` (recipient's DID) and `share` (percentage). |
131
- | `amount` | `object` | Optional. Configures donation amounts, including `presets` (e.g., `['1', '5', '10']`), a default `preset`, `minimum`, `maximum`, and whether `custom` amounts are allowed. |
132
- | `appearance` | `object` | Optional. Customizes the look and feel, including `button` (text, icon, variant) and `history` display (`'avatar'` or `'table'`). |
104
+ This object is passed to the `settings` prop and defines the core details of the donation target.
105
+
106
+ <x-field-group>
107
+ <x-field data-name="target" data-type="string" data-required="true">
108
+ <x-field-desc markdown>A unique identifier for the donation target, such as a post ID or project name. This is used to group donations.</x-field-desc>
109
+ </x-field>
110
+ <x-field data-name="title" data-type="string" data-required="true">
111
+ <x-field-desc markdown>The title displayed at the top of the donation dialog.</x-field-desc>
112
+ </x-field>
113
+ <x-field data-name="description" data-type="string" data-required="true">
114
+ <x-field-desc markdown>A brief description of the donation's purpose, shown in the dialog.</x-field-desc>
115
+ </x-field>
116
+ <x-field data-name="reference" data-type="string" data-required="true">
117
+ <x-field-desc markdown>A URL related to the donation target, used for record-keeping and context.</x-field-desc>
118
+ </x-field>
119
+ <x-field data-name="beneficiaries" data-type="PaymentBeneficiary[]" data-required="true">
120
+ <x-field-desc markdown>An array of objects defining the fund recipients. Each object must include an `address` (recipient's DID) and a `share` (percentage).</x-field-desc>
121
+ </x-field>
122
+ <x-field data-name="amount" data-type="object" data-required="false">
123
+ <x-field-desc markdown>Configures the donation amounts. If not provided, it falls back to settings from `DonateProvider` or a system default.</x-field-desc>
124
+ <x-field data-name="presets" data-type="string[]" data-required="false" data-desc="An array of suggested donation amounts (e.g., ['1', '5', '10'])."></x-field>
125
+ <x-field data-name="preset" data-type="string" data-required="false" data-desc="The default selected amount from the presets."></x-field>
126
+ <x-field data-name="minimum" data-type="string" data-required="false" data-desc="The minimum allowed donation amount."></x-field>
127
+ <x-field data-name="maximum" data-type="string" data-required="false" data-desc="The maximum allowed donation amount."></x-field>
128
+ <x-field data-name="custom" data-type="boolean" data-required="false" data-desc="Determines if users can enter a custom donation amount."></x-field>
129
+ </x-field>
130
+ <x-field data-name="appearance" data-type="object" data-required="false">
131
+ <x-field-desc markdown>Customizes the component's visual elements.</x-field-desc>
132
+ <x-field data-name="button" data-type="object" data-required="false" data-desc="Customizes the donation button's `text`, `icon`, `size`, `color`, and `variant`."></x-field>
133
+ <x-field data-name="history" data-type="object" data-required="false" data-desc="Configures the appearance of the supporter history list. Set `variant` to 'avatar' or 'table'."></x-field>
134
+ </x-field>
135
+ </x-field-group>
133
136
 
134
137
  ## Usage Examples
135
138
 
136
139
  ### Default Mode
137
140
 
138
- This is the simplest way to use `CheckoutDonate`. It renders a button that opens a donation dialog, along with a summary of recent supporters.
141
+ The default mode is the most straightforward implementation. It renders a donation button and a list of recent supporters. Clicking the button opens a dialog where the user can complete the donation.
139
142
 
140
- ```tsx Default Donation Button icon=logos:react
143
+ ```javascript DefaultMode.jsx icon=logos:react
141
144
  import {
142
145
  PaymentProvider,
143
146
  DonateProvider,
@@ -146,17 +149,17 @@ import {
146
149
  import { useSessionContext } from '../hooks/session-context';
147
150
 
148
151
  function App() {
149
- const { session, connect } = useSessionContext();
152
+ const { session, connectApi } = useSessionContext();
150
153
 
151
154
  if (!session) {
152
155
  return <div>Loading session...</div>;
153
156
  }
154
157
 
155
158
  return (
156
- <PaymentProvider session={session} connect={connect}>
159
+ <PaymentProvider session={session} connectApi={connectApi}>
157
160
  <DonateProvider
158
- mountLocation="blog-post-123"
159
- description="Donations for Blog Post 123"
161
+ mountLocation="blog-post-donations"
162
+ description="Donations for the main blog"
160
163
  defaultSettings={{
161
164
  btnText: 'Buy me a coffee',
162
165
  historyType: 'avatar',
@@ -175,7 +178,7 @@ function App() {
175
178
  ],
176
179
  }}
177
180
  onPaid={() => {
178
- console.log('Donation successful!');
181
+ alert('Thank you for your donation!');
179
182
  }}
180
183
  />
181
184
  </DonateProvider>
@@ -186,62 +189,64 @@ function App() {
186
189
 
187
190
  ### Custom UI Mode
188
191
 
189
- For full control over the user interface, use `mode="custom"` and provide a render prop as the `children`. This function gives you access to the donation state, including the total amount raised and a list of supporters, allowing you to build a completely custom display.
192
+ For complete control over the layout and presentation, use `mode="custom"`. This mode utilizes a render prop passed as the component's `children`. The function provides access to the donation state and methods, allowing you to build a unique user experience.
190
193
 
191
- ```tsx Custom Donation UI icon=logos:react
194
+ ```javascript CustomMode.jsx icon=logos:react
192
195
  import {
193
196
  PaymentProvider,
194
197
  DonateProvider,
195
198
  CheckoutDonate,
196
199
  } from '@blocklet/payment-react';
197
200
  import { useSessionContext } from '../hooks/session-context';
198
- import { CircularProgress, Button } from '@mui/material';
201
+ import { CircularProgress, Button, Avatar, Box, Typography } from '@mui/material';
199
202
 
200
203
  function CustomDonationDisplay() {
201
- const { session, connect } = useSessionContext();
204
+ const { session, connectApi } = useSessionContext();
202
205
 
203
206
  if (!session) {
204
207
  return <div>Loading session...</div>;
205
208
  }
206
209
 
207
210
  const donateSettings = {
208
- target: 'post-123',
209
- title: 'Support the Author',
210
- description: 'If you found this article helpful, consider a small donation.',
211
- reference: 'https://example.com/posts/123',
211
+ target: 'project-alpha',
212
+ title: 'Support Project Alpha',
213
+ description: 'Help us build the next generation of tools.',
214
+ reference: 'https://example.com/projects/alpha',
212
215
  beneficiaries: [
213
216
  {
214
- address: 'z2qa...gCLd', // Author's DID address
217
+ address: 'z2qa...gCLd',
215
218
  share: '100',
216
219
  },
217
220
  ],
218
221
  };
219
222
 
220
223
  return (
221
- <PaymentProvider session={session} connect={connect}>
224
+ <PaymentProvider session={session} connectApi={connectApi}>
222
225
  <DonateProvider
223
- mountLocation="blog-post-123"
224
- description="Donations for Blog Post 123">
226
+ mountLocation="project-alpha-donations"
227
+ description="Donations for Project Alpha">
225
228
  <CheckoutDonate mode="custom" settings={donateSettings}>
226
229
  {(openDonate, totalAmount, supporters, loading, settings) => (
227
- <div style={{ border: '1px solid #ccc', padding: '16px', borderRadius: '8px' }}>
228
- <h2>Our Supporters</h2>
229
- <p>Total Donations: <strong>{totalAmount}</strong></p>
230
- <Button variant="contained" onClick={openDonate}>
230
+ <Box sx={{ border: '1px solid #e0e0e0', padding: '24px', borderRadius: '8px', textAlign: 'center' }}>
231
+ <Typography variant="h5">Our Supporters</Typography>
232
+ <Typography variant="body1" color="text.secondary" sx={{ mb: 2 }}>
233
+ Total Donated: <strong>{totalAmount}</strong>
234
+ </Typography>
235
+ <Button variant="contained" size="large" onClick={openDonate}>
231
236
  {settings?.appearance?.button?.text || 'Donate Now'}
232
237
  </Button>
233
- {loading ? (
234
- <CircularProgress style={{ marginTop: '16px' }} />
235
- ) : (
236
- <ul style={{ listStyle: 'none', padding: 0, marginTop: '16px' }}>
237
- {(supporters.supporters || []).map((supporter) => (
238
- <li key={supporter.id}>
239
- <span>{supporter.customer?.name}</span>
240
- </li>
238
+ {loading && <CircularProgress sx={{ display: 'block', margin: '16px auto' }} />}
239
+ {!loading && (supporters.supporters || []).length > 0 && (
240
+ <Box sx={{ mt: 3 }}>
241
+ {(supporters.supporters || []).slice(0, 5).map((supporter) => (
242
+ <Box key={supporter.id} sx={{ display: 'flex', alignItems: 'center', mb: 1 }}>
243
+ <Avatar src={supporter.customer?.avatar} sx={{ width: 24, height: 24, mr: 1 }} />
244
+ <Typography variant="body2">{supporter.customer?.name}</Typography>
245
+ </Box>
241
246
  ))}
242
- </ul>
247
+ </Box>
243
248
  )}
244
- </div>
249
+ </Box>
245
250
  )}
246
251
  </CheckoutDonate>
247
252
  </DonateProvider>
@@ -250,10 +255,12 @@ function CustomDonationDisplay() {
250
255
  }
251
256
  ```
252
257
 
253
- The `children` function receives the following arguments:
258
+ #### Custom Render Prop Arguments
259
+
260
+ The `children` function provides the following arguments:
254
261
 
255
- - `openDonate`: A function to manually trigger the donation dialog.
256
- - `totalAmount`: A formatted string of the total amount donated (e.g., `"125.00 T"`).
257
- - `supporters`: A `DonateHistory` object containing the `supporters` array and currency info.
258
- - `loading`: A boolean indicating if the supporter data is being fetched.
259
- - `settings`: The resolved donation settings, merged from `DonateProvider` and props.
262
+ - `openDonate()`: A function to programmatically open the donation dialog.
263
+ - `donateTotalAmount`: A formatted string representing the total amount donated (e.g., `"125.00 T"`).
264
+ - `supporters`: A `DonateHistory` object containing the `supporters` array, total amount, currency, and method details.
265
+ - `loading`: A boolean that is `true` while supporter data is being fetched.
266
+ - `donateSettings`: The final, resolved donation settings, merged from `DonateProvider` and the component's `settings` prop.
@@ -8,42 +8,9 @@
8
8
 
9
9
  捐贈流程由 `DonateProvider` 和 `CheckoutDonate` 共同協調。以下是高層次的概述:
10
10
 
11
- ```d2 How It Works icon=graph-ql:diagram
12
- direction: down
13
-
14
- user: {
15
- shape: c4-person
16
- }
17
-
18
- app: {
19
- label: "您的 React 應用程式"
20
-
21
- checkout-donate: {
22
- label: "CheckoutDonate"
23
- }
24
-
25
- checkout-form: {
26
- label: "CheckoutForm (在對話方塊中)"
27
- }
28
- }
29
-
30
- payment-api: {
31
- label: "支付後端 API"
32
- shape: cylinder
33
- }
34
-
35
- # 初始載入
36
- app.checkout-donate -> payment-api: "獲取設定和支持者"
37
-
38
- # 捐贈流程
39
- user -> app.checkout-donate: "1. 點擊捐贈"
40
- app.checkout-donate -> app.checkout-form: "2. 開啟帶有 CheckoutForm 的對話方塊"
41
- app.checkout-form -> payment-api: "3. 處理支付"
42
- payment-api -> app.checkout-form: "4. 回傳成功"
43
- app.checkout-form -> app.checkout-donate: "5. 觸發 onPaid 回呼"
44
- app.checkout-donate -> payment-api: "6. 重新獲取支持者列表"
45
- payment-api -> app.checkout-donate: "7. 回傳更新後的支持者"
46
- ```
11
+ <!-- DIAGRAM_IMAGE_START:flowchart:4:3::1765377352 -->
12
+ ![CheckoutDonate](assets/diagram/components-checkout-checkout-donate-01.zh-TW.jpg)
13
+ <!-- DIAGRAM_IMAGE_END -->
47
14
 
48
15
  1. **初始化**:`DonateProvider` 從後端獲取並快取捐贈設定(如預設金額、按鈕文字),並透過唯一的 `mountLocation` 進行識別。
49
16
  2. **渲染**:`CheckoutDonate` 根據檢索到的設定及其 props 渲染按鈕或自訂 UI。
@@ -8,42 +8,9 @@
8
8
 
9
9
  捐赠流程由 `DonateProvider` 和 `CheckoutDonate` 共同协调。以下是其高级概述:
10
10
 
11
- ```d2 工作原理 icon=graph-ql:diagram
12
- direction: down
13
-
14
- user: {
15
- shape: c4-person
16
- }
17
-
18
- app: {
19
- label: "您的 React 应用"
20
-
21
- checkout-donate: {
22
- label: "CheckoutDonate"
23
- }
24
-
25
- checkout-form: {
26
- label: "CheckoutForm(在对话框中)"
27
- }
28
- }
29
-
30
- payment-api: {
31
- label: "支付后端 API"
32
- shape: cylinder
33
- }
34
-
35
- # 初始加载
36
- app.checkout-donate -> payment-api: "获取设置和支持者"
37
-
38
- # 捐赠流程
39
- user -> app.checkout-donate: "1. 点击捐赠"
40
- app.checkout-donate -> app.checkout-form: "2. 打开带有 CheckoutForm 的对话框"
41
- app.checkout-form -> payment-api: "3. 处理支付"
42
- payment-api -> app.checkout-form: "4. 返回成功"
43
- app.checkout-form -> app.checkout-donate: "5. 触发 onPaid 回调"
44
- app.checkout-donate -> payment-api: "6. 重新获取支持者列表"
45
- payment-api -> app.checkout-donate: "7. 返回更新后的支持者"
46
- ```
11
+ <!-- DIAGRAM_IMAGE_START:flowchart:4:3::1765377352 -->
12
+ ![CheckoutDonate](assets/diagram/components-checkout-checkout-donate-01.zh.jpg)
13
+ <!-- DIAGRAM_IMAGE_END -->
47
14
 
48
15
  1. **初始化**:`DonateProvider` 从后端获取并缓存捐赠设置(如预设金额、按钮文本),这些设置由唯一的 `mountLocation` 标识。
49
16
  2. **渲染**:`CheckoutDonate` 根据检索到的设置及其 props 渲染一个按钮或自定义 UI。