@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.
- package/.aigne/doc-smith/config.yaml +2 -2
- package/.aigne/doc-smith/upload-cache.yaml +381 -0
- package/docs/components-business-auto-topup.md +128 -179
- package/docs/components-business-overdue-invoice-payment.md +108 -143
- package/docs/components-business-resume-subscription.md +117 -104
- package/docs/components-business.md +12 -36
- package/docs/components-checkout-checkout-donate.md +209 -149
- package/docs/components-checkout-checkout-form.md +115 -136
- package/docs/components-checkout-checkout-table.md +92 -172
- package/docs/components-checkout.md +43 -109
- package/docs/components-history-credit-grants-list.md +45 -70
- package/docs/components-history-credit-transactions-list.md +57 -67
- package/docs/components-history-invoice-list.md +58 -52
- package/docs/components-history-payment-list.md +19 -40
- package/docs/components-history.md +42 -67
- package/docs/components-ui-form-elements-address-form.md +37 -65
- package/docs/components-ui-form-elements-country-select.md +80 -59
- package/docs/components-ui-form-elements-currency-selector.md +57 -73
- package/docs/components-ui-form-elements-phone-input.md +90 -112
- package/docs/components-ui-form-elements.md +46 -80
- package/docs/components-ui-payment-summary.md +71 -119
- package/docs/components-ui-pricing-table.md +117 -204
- package/docs/components-ui.md +59 -32
- package/docs/components.md +89 -62
- package/docs/getting-started.md +36 -63
- package/docs/guides-theming.md +122 -84
- package/docs/guides-utilities.md +107 -145
- package/docs/guides.md +7 -84
- package/docs/hooks-use-mobile.md +50 -36
- package/docs/hooks-use-subscription.md +72 -89
- package/docs/hooks.md +12 -82
- package/docs/overview.md +45 -52
- package/docs/providers-donate-provider.md +73 -95
- package/docs/providers-payment-provider.md +115 -169
- package/docs/providers.md +27 -86
- package/es/locales/en.js +7 -0
- package/es/locales/zh.js +8 -1
- package/es/payment/index.js +3 -0
- package/es/payment/progress-item.d.ts +12 -0
- package/es/payment/progress-item.js +78 -0
- package/es/payment/success.d.ts +4 -1
- package/es/payment/success.js +55 -3
- package/lib/locales/en.js +7 -0
- package/lib/locales/zh.js +8 -1
- package/lib/payment/index.js +3 -0
- package/lib/payment/progress-item.d.ts +12 -0
- package/lib/payment/progress-item.js +107 -0
- package/lib/payment/success.d.ts +4 -1
- package/lib/payment/success.js +59 -3
- package/package.json +7 -7
- package/src/locales/en.tsx +7 -0
- package/src/locales/zh.tsx +8 -1
- package/src/payment/index.tsx +6 -0
- package/src/payment/progress-item.tsx +107 -0
- package/src/payment/success.tsx +88 -3
|
@@ -1,75 +1,98 @@
|
|
|
1
1
|
# CheckoutDonate
|
|
2
2
|
|
|
3
|
-
The `CheckoutDonate` component provides a flexible
|
|
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
|
-
|
|
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
|
-
##
|
|
7
|
+
## How It Works
|
|
8
8
|
|
|
9
|
-
|
|
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
|
-
|
|
11
|
+
```d2 How It Works icon=graph-ql:diagram
|
|
12
|
+
direction: down
|
|
22
13
|
|
|
23
|
-
|
|
14
|
+
user: {
|
|
15
|
+
shape: c4-person
|
|
16
|
+
}
|
|
24
17
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
import { useSessionContext } from '../contexts/session'; // Adjust path as needed
|
|
66
|
+
function DonationPage() {
|
|
67
|
+
const { session, connect } = useSessionContext();
|
|
49
68
|
|
|
50
|
-
|
|
51
|
-
|
|
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={
|
|
55
|
-
<DonateProvider
|
|
56
|
-
mountLocation="unique-page-identifier"
|
|
57
|
-
description="
|
|
58
|
-
|
|
59
|
-
|
|
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",
|
|
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: "
|
|
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
|
-
|
|
103
|
+
For more details, see the [`DonateProvider`](./providers-donate-provider.md) documentation.
|
|
81
104
|
|
|
82
|
-
|
|
105
|
+
## Component Props
|
|
83
106
|
|
|
84
|
-
###
|
|
107
|
+
### `DonateProps`
|
|
85
108
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
###
|
|
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
|
-
|
|
122
|
+
This object is passed to the `settings` prop and defines the core details of the donation.
|
|
133
123
|
|
|
134
|
-
|
|
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
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
187
|
+
### Custom UI Mode
|
|
147
188
|
|
|
148
|
-
|
|
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
|
-
|
|
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
|
-
<
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
</
|
|
188
|
-
|
|
189
|
-
</
|
|
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
|
-
|
|
253
|
+
The `children` function receives the following arguments:
|
|
198
254
|
|
|
199
|
-
|
|
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.
|