@blocklet/payment-react 1.20.4 → 1.20.6

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 (55) hide show
  1. package/.aigne/doc-smith/config.yaml +2 -2
  2. package/.aigne/doc-smith/upload-cache.yaml +381 -0
  3. package/docs/components-business-auto-topup.md +128 -179
  4. package/docs/components-business-overdue-invoice-payment.md +108 -143
  5. package/docs/components-business-resume-subscription.md +117 -104
  6. package/docs/components-business.md +12 -36
  7. package/docs/components-checkout-checkout-donate.md +209 -149
  8. package/docs/components-checkout-checkout-form.md +115 -136
  9. package/docs/components-checkout-checkout-table.md +92 -172
  10. package/docs/components-checkout.md +43 -109
  11. package/docs/components-history-credit-grants-list.md +45 -70
  12. package/docs/components-history-credit-transactions-list.md +57 -67
  13. package/docs/components-history-invoice-list.md +58 -52
  14. package/docs/components-history-payment-list.md +19 -40
  15. package/docs/components-history.md +42 -67
  16. package/docs/components-ui-form-elements-address-form.md +37 -65
  17. package/docs/components-ui-form-elements-country-select.md +80 -59
  18. package/docs/components-ui-form-elements-currency-selector.md +57 -73
  19. package/docs/components-ui-form-elements-phone-input.md +90 -112
  20. package/docs/components-ui-form-elements.md +46 -80
  21. package/docs/components-ui-payment-summary.md +71 -119
  22. package/docs/components-ui-pricing-table.md +117 -204
  23. package/docs/components-ui.md +59 -32
  24. package/docs/components.md +89 -62
  25. package/docs/getting-started.md +36 -63
  26. package/docs/guides-theming.md +122 -84
  27. package/docs/guides-utilities.md +107 -145
  28. package/docs/guides.md +7 -84
  29. package/docs/hooks-use-mobile.md +50 -36
  30. package/docs/hooks-use-subscription.md +72 -89
  31. package/docs/hooks.md +12 -82
  32. package/docs/overview.md +45 -52
  33. package/docs/providers-donate-provider.md +73 -95
  34. package/docs/providers-payment-provider.md +115 -169
  35. package/docs/providers.md +27 -86
  36. package/es/locales/en.js +7 -0
  37. package/es/locales/zh.js +8 -1
  38. package/es/payment/index.js +3 -0
  39. package/es/payment/progress-item.d.ts +12 -0
  40. package/es/payment/progress-item.js +78 -0
  41. package/es/payment/success.d.ts +4 -1
  42. package/es/payment/success.js +55 -3
  43. package/lib/locales/en.js +7 -0
  44. package/lib/locales/zh.js +8 -1
  45. package/lib/payment/index.js +3 -0
  46. package/lib/payment/progress-item.d.ts +12 -0
  47. package/lib/payment/progress-item.js +107 -0
  48. package/lib/payment/success.d.ts +4 -1
  49. package/lib/payment/success.js +59 -3
  50. package/package.json +7 -7
  51. package/src/locales/en.tsx +7 -0
  52. package/src/locales/zh.tsx +8 -1
  53. package/src/payment/index.tsx +6 -0
  54. package/src/payment/progress-item.tsx +107 -0
  55. package/src/payment/success.tsx +88 -3
@@ -1,75 +1,98 @@
1
1
  # CheckoutDonate
2
2
 
3
- The `CheckoutDonate` component provides a flexible way to implement donation functionality in your application. It supports several display modes, from a simple pre-built button to a fully custom UI, and handles the entire donation flow, including displaying supporter history.
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.
4
4
 
5
- To function correctly, `CheckoutDonate` must be wrapped within both a [`PaymentProvider`](./providers-payment-provider.md) and a [`DonateProvider`](./providers-donate-provider.md).
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.
6
6
 
7
- ## Props
7
+ ## How It Works
8
8
 
9
- | Prop | Type | Description |
10
- |---|---|---|
11
- | `settings` | `CheckoutDonateSettings` | **Required.** An object containing the configuration for the donation instance, such as target, title, and beneficiaries. |
12
- | `onPaid` | `(session: TCheckoutSessionExpanded) => void` | Optional. A callback function that is executed after a donation is successfully paid. |
13
- | `onError` | `(error: any) => void` | Optional. A callback function that is executed if an error occurs during the payment process. |
14
- | `livemode` | `boolean` | Optional. Toggles between live and test payment modes. If not set, it inherits the value from `PaymentProvider`. |
15
- | `timeout` | `number` | Optional. The time in milliseconds to wait before closing the checkout dialog after a successful payment. Defaults to `5000`. |
16
- | `mode` | `'default' \| 'inline' \| 'custom'` | Optional. Determines the rendering mode of the component. Defaults to `'default'`. |
17
- | `inlineOptions` | `{ button?: ButtonType }` | Optional. Customization options for the button when `mode` is set to `'inline'`. |
18
- | `theme` | `'default' \| 'inherit' \| PaymentThemeOptions` | Optional. Controls the component's theme. See the [Theming guide](./guides-theming.md) for more details. Defaults to `'default'`. |
19
- | `children` | `(openDialog, donateTotalAmount, supporters, loading, donateSettings) => React.ReactNode` | Optional. A render prop function used when `mode` is `'custom'`. See the Custom Mode section for details. |
9
+ The donation flow is orchestrated by a combination of `DonateProvider` and `CheckoutDonate`. Here's a high-level overview:
20
10
 
21
- ### `CheckoutDonateSettings`
11
+ ```d2 How It Works icon=graph-ql:diagram
12
+ direction: down
22
13
 
23
- This object configures the donation's behavior and appearance.
14
+ user: {
15
+ shape: c4-person
16
+ }
24
17
 
25
- | Property | Type | Description |
26
- |---|---|---|
27
- | `target` | `string` | **Required.** A unique identifier for the donation instance (e.g., a post ID like `"post-123"`). |
28
- | `title` | `string` | **Required.** The title displayed in the donation modal. |
29
- | `description` | `string` | **Required.** A description shown in the donation modal. |
30
- | `reference` | `string` | **Required.** A reference link for the donation, such as the URL of the page where the donation is being made. |
31
- | `beneficiaries` | `PaymentBeneficiary[]` | **Required.** An array of objects defining who receives the donation and their respective shares. |
32
- | `amount` | `object` | Optional. Configures donation amounts, including presets, min/max values, and whether custom amounts are allowed. Inherits from `DonateProvider` if not set. |
33
- | `appearance` | `object` | Optional. Customizes the look and feel of the donation button and supporter history display (`'avatar'` or `'table'`). Inherits from `DonateProvider` if not set. |
34
-
35
- ## Basic Usage
36
-
37
- Here is a basic example of how to set up `CheckoutDonate`. This will render a default donation button and a list of supporters.
38
-
39
- ```tsx
40
- import {
41
- PaymentProvider,
42
- DonateProvider,
43
- CheckoutDonate
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
+ }
34
+
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
+ ```
47
+
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.
53
+
54
+ ## Provider Setup
55
+
56
+ Before using `CheckoutDonate`, you must wrap your component tree with `PaymentProvider` and `DonateProvider`.
57
+
58
+ ```tsx Provider Setup Example icon=logos:react
59
+ import {
60
+ PaymentProvider,
61
+ DonateProvider,
62
+ CheckoutDonate,
44
63
  } from '@blocklet/payment-react';
64
+ import { useSessionContext } from '../hooks/session-context'; // Your session context hook
45
65
 
46
- // This is a placeholder for your application's session management.
47
- // See the documentation for PaymentProvider for details on how to set up this context.
48
- import { useSessionContext } from '../contexts/session'; // Adjust path as needed
66
+ function DonationPage() {
67
+ const { session, connect } = useSessionContext();
49
68
 
50
- function DonationSection() {
51
- const { session, connectApi } = useSessionContext();
69
+ // Ensure session is loaded before rendering providers
70
+ if (!session) {
71
+ return <div>Loading...</div>;
72
+ }
52
73
 
53
74
  return (
54
- <PaymentProvider session={session} connect={connectApi}>
55
- <DonateProvider
56
- mountLocation="unique-page-identifier"
57
- description="Donations for this page"
58
- >
59
- <CheckoutDonate
75
+ <PaymentProvider session={session} connect={connect}>
76
+ <DonateProvider
77
+ mountLocation="unique-page-identifier" // A unique key for this donation context
78
+ description="Donation for my awesome blog post"
79
+ defaultSettings={{
80
+ btnText: 'Support Me',
81
+ }}>
82
+ {/* Your CheckoutDonate component goes here */}
83
+ <CheckoutDonate
60
84
  settings={{
61
- target: "post-123", // Unique ID for this donation target
85
+ target: "post-123",
62
86
  title: "Support the Author",
63
- description: "If you find this article helpful, feel free to buy me a coffee.",
87
+ description: "If you find this article helpful, feel free to buy me a coffee",
64
88
  reference: "https://your-site.com/posts/123",
65
89
  beneficiaries: [
66
90
  {
67
- address: "did:abt:z123...", // Beneficiary's DID address
91
+ address: "z2qa...",
68
92
  share: "100",
69
93
  },
70
94
  ],
71
95
  }}
72
- onPaid={(session) => console.log('Donation successful:', session.id)}
73
96
  />
74
97
  </DonateProvider>
75
98
  </PaymentProvider>
@@ -77,123 +100,160 @@ function DonationSection() {
77
100
  }
78
101
  ```
79
102
 
80
- ## Usage Modes
103
+ For more details, see the [`DonateProvider`](./providers-donate-provider.md) documentation.
81
104
 
82
- The `CheckoutDonate` component can be rendered in three different modes, controlled by the `mode` prop.
105
+ ## Component Props
83
106
 
84
- ### Default Mode
107
+ ### `DonateProps`
85
108
 
86
- When `mode` is `'default'` (or omitted), the component renders a donation button. Below the button, it displays a history of supporters, which can be configured to show as avatars or a table via `settings.appearance.history.variant`.
87
-
88
- ```tsx
89
- <CheckoutDonate
90
- settings={{
91
- target: "post-456",
92
- title: "Support Our Project",
93
- description: "Every little bit helps!",
94
- reference: "https://your-site.com/projects/our-project",
95
- beneficiaries: [{ address: "did:abt:z456...", share: "100" }],
96
- appearance: {
97
- button: {
98
- text: 'Buy me a coffee ☕',
99
- variant: 'contained',
100
- },
101
- history: {
102
- variant: 'table', // or 'avatar'
103
- },
104
- },
105
- }}
106
- />
107
- ```
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"`. |
108
119
 
109
- ### Inline Mode
110
-
111
- Setting `mode="inline"` renders a button that opens a popover when hovered over. The popover contains the donation button and a summary of supporters. This is useful for more compact UIs.
112
-
113
- ```tsx
114
- <CheckoutDonate
115
- mode="inline"
116
- settings={{
117
- target: "post-789",
118
- title: "Tip Jar",
119
- description: "Thanks for your support!",
120
- reference: "https://your-site.com/posts/789",
121
- beneficiaries: [{ address: "did:abt:z789...", share: "100" }],
122
- }}
123
- inlineOptions={{
124
- button: {
125
- text: 'Tip',
126
- variant: 'outlined',
127
- }
128
- }}
129
- />
130
- ```
120
+ ### `CheckoutDonateSettings`
131
121
 
132
- ### Custom Mode
122
+ This object is passed to the `settings` prop and defines the core details of the donation.
133
123
 
134
- For complete control over the UI, use `mode="custom"`. This mode uses a render prop passed as the `children` of the component. The function provides you with the state and actions needed to build your own interface.
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'`). |
135
133
 
136
- The `children` function receives the following arguments:
134
+ ## Usage Examples
135
+
136
+ ### Default Mode
137
+
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.
137
139
 
138
- | Argument | Type | Description |
139
- |---|---|---|
140
- | `openDialog` | `() => void` | A function to call to open the donation payment modal. |
141
- | `donateTotalAmount` | `string` | A formatted string representing the total amount donated (e.g., `"125.50 USDT"`). |
142
- | `supporters` | `DonateHistory` | An object containing supporter data, including the list of supporters, currency, and payment method details. |
143
- | `loading` | `boolean` | A boolean indicating if the supporter data is currently being fetched. |
144
- | `donateSettings` | `DonationSettings` | The processed donation settings object, including defaults inherited from `DonateProvider`. |
140
+ ```tsx Default Donation Button icon=logos:react
141
+ import {
142
+ PaymentProvider,
143
+ DonateProvider,
144
+ CheckoutDonate,
145
+ } from '@blocklet/payment-react';
146
+ import { useSessionContext } from '../hooks/session-context';
147
+
148
+ function App() {
149
+ const { session, connect } = useSessionContext();
150
+
151
+ if (!session) {
152
+ return <div>Loading session...</div>;
153
+ }
154
+
155
+ return (
156
+ <PaymentProvider session={session} connect={connect}>
157
+ <DonateProvider
158
+ mountLocation="blog-post-123"
159
+ description="Donations for Blog Post 123"
160
+ defaultSettings={{
161
+ btnText: 'Buy me a coffee',
162
+ historyType: 'avatar',
163
+ }}>
164
+ <CheckoutDonate
165
+ settings={{
166
+ target: 'post-123',
167
+ title: 'Support the Author',
168
+ description: 'If you found this article helpful, consider a small donation.',
169
+ reference: 'https://example.com/posts/123',
170
+ beneficiaries: [
171
+ {
172
+ address: 'z2qa...gCLd', // Author's DID address
173
+ share: '100',
174
+ },
175
+ ],
176
+ }}
177
+ onPaid={() => {
178
+ console.log('Donation successful!');
179
+ }}
180
+ />
181
+ </DonateProvider>
182
+ </PaymentProvider>
183
+ );
184
+ }
185
+ ```
145
186
 
146
- Here is an example of a custom donation UI:
187
+ ### Custom UI Mode
147
188
 
148
- ```tsx
149
- import { CheckoutDonate, formatAmount } from '@blocklet/payment-react';
150
- import { Button, CircularProgress, Typography, List, ListItem, ListItemText } from '@mui/material';
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.
151
190
 
152
- // Assuming PaymentProvider and DonateProvider are set up in a parent component.
191
+ ```tsx Custom Donation UI icon=logos:react
192
+ import {
193
+ PaymentProvider,
194
+ DonateProvider,
195
+ CheckoutDonate,
196
+ } from '@blocklet/payment-react';
197
+ import { useSessionContext } from '../hooks/session-context';
198
+ import { CircularProgress, Button } from '@mui/material';
153
199
 
154
200
  function CustomDonationDisplay() {
201
+ const { session, connect } = useSessionContext();
202
+
203
+ if (!session) {
204
+ return <div>Loading session...</div>;
205
+ }
206
+
207
+ 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',
212
+ beneficiaries: [
213
+ {
214
+ address: 'z2qa...gCLd', // Author's DID address
215
+ share: '100',
216
+ },
217
+ ],
218
+ };
219
+
155
220
  return (
156
- <CheckoutDonate
157
- mode="custom"
158
- settings={{
159
- target: "post-123",
160
- title: "Support the Author",
161
- description: "Your support is appreciated!",
162
- reference: "https://your-site.com/posts/123",
163
- beneficiaries: [{ address: "did:abt:z123...", share: "100" }],
164
- }}
165
- >
166
- {(openDonate, totalAmount, supporters, loading) => (
167
- <div>
168
- <Typography variant="h5">Our Supporters</Typography>
169
- <Button variant="contained" onClick={openDonate} sx={{ my: 2 }}>Support Us</Button>
170
- {loading ? (
171
- <CircularProgress />
172
- ) : (
173
- <div>
174
- <Typography variant="subtitle1">Total Donations: {totalAmount}</Typography>
175
- <List>
176
- {supporters.supporters && supporters.supporters.map(supporter => (
177
- <ListItem key={supporter.id}>
178
- <ListItemText
179
- primary={supporter.customer?.name}
180
- secondary={`${formatAmount(supporter.amount_total, supporters.currency?.decimal)} ${supporters.currency?.symbol}`}
181
- />
182
- </ListItem>
183
- ))}
184
- </List>
221
+ <PaymentProvider session={session} connect={connect}>
222
+ <DonateProvider
223
+ mountLocation="blog-post-123"
224
+ description="Donations for Blog Post 123">
225
+ <CheckoutDonate mode="custom" settings={donateSettings}>
226
+ {(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}>
231
+ {settings?.appearance?.button?.text || 'Donate Now'}
232
+ </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>
241
+ ))}
242
+ </ul>
243
+ )}
185
244
  </div>
186
245
  )}
187
- </div>
188
- )}
189
- </CheckoutDonate>
246
+ </CheckoutDonate>
247
+ </DonateProvider>
248
+ </PaymentProvider>
190
249
  );
191
250
  }
192
251
  ```
193
- This custom setup gives you full control over the presentation of donation information.
194
-
195
- ## Admin Features
196
252
 
197
- If the current user session has an `owner` or `admin` role, a settings icon will appear in the title of the donation dialog. Clicking this icon opens the donation configuration interface, allowing administrators to modify donation settings directly from the UI.
253
+ The `children` function receives the following arguments:
198
254
 
199
- This feature requires that the `DonateProvider` is properly configured and that the underlying Payment Kit blocklet supports this functionality.
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.