@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,113 +1,175 @@
|
|
|
1
1
|
# Auto-Topup Components
|
|
2
2
|
|
|
3
|
-
The auto-topup feature
|
|
3
|
+
The auto-topup feature ensures uninterrupted service by automatically recharging a user's credit balance when it falls below a specified threshold. This is managed through two primary components: `AutoTopup`, which displays the current configuration, and `AutoTopupModal`, which provides the interface for setting it up.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Auto-Topup Workflow
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
The diagram below illustrates the typical user flow for configuring the auto-topup feature. The user interacts with the `AutoTopup` display component, which launches the `AutoTopupModal` for making changes. The modal then communicates with the backend API to save the configuration.
|
|
8
|
+
|
|
9
|
+
```d2
|
|
10
|
+
direction: down
|
|
11
|
+
|
|
12
|
+
User: {
|
|
13
|
+
shape: c4-person
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
Application-UI: {
|
|
17
|
+
label: "Application UI"
|
|
18
|
+
shape: rectangle
|
|
19
|
+
|
|
20
|
+
AutoTopup-Card: {
|
|
21
|
+
label: "AutoTopup Component"
|
|
22
|
+
shape: rectangle
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
AutoTopup-Modal: {
|
|
26
|
+
label: "AutoTopupModal"
|
|
27
|
+
shape: rectangle
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
Payment-API: {
|
|
32
|
+
label: "Payment API"
|
|
33
|
+
shape: cylinder
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
User -> Application-UI.AutoTopup-Card: "1. Views auto-topup status"
|
|
37
|
+
Application-UI.AutoTopup-Card -> Application-UI.AutoTopup-Modal: "2. Clicks 'Configure' to open modal"
|
|
38
|
+
User -> Application-UI.AutoTopup-Modal: "3. Adjusts settings & saves"
|
|
39
|
+
Application-UI.AutoTopup-Modal -> Payment-API: "4. Submit configuration"
|
|
40
|
+
Payment-API -> Payment-API: "5. Save configuration"
|
|
41
|
+
Payment-API -> Application-UI.AutoTopup-Modal: "6. Return success"
|
|
42
|
+
Application-UI.AutoTopup-Modal -> Application-UI.AutoTopup-Card: "7. Calls onSuccess, UI updates"
|
|
43
|
+
|
|
44
|
+
```
|
|
8
45
|
|
|
9
46
|
## AutoTopup
|
|
10
47
|
|
|
11
|
-
The `AutoTopup` component is
|
|
48
|
+
The `AutoTopup` component is a display card that shows the current auto-recharge status for a specific currency and provides an entry point for configuration. It supports multiple rendering modes for flexibility.
|
|
49
|
+
|
|
50
|
+
### Props
|
|
51
|
+
|
|
52
|
+
| Prop | Type | Description |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| `currencyId` | `string` | **Required.** The ID of the credit currency to manage. |
|
|
55
|
+
| `onConfigChange` | `(config: AutoRechargeConfig) => void` | Optional. Callback function triggered when the configuration is successfully updated. |
|
|
56
|
+
| `mode` | `'default' \| 'simple' \| 'custom'` | Optional. The rendering mode. Defaults to `'default'`.<br/>- `default`: A fully expanded card showing all details.<br/>- `simple`: A compact, collapsed view with a button to expand details.<br/>- `custom`: Renders a custom UI using the `children` render prop. |
|
|
57
|
+
| `sx` | `SxProps` | Optional. Custom MUI styles to apply to the component. |
|
|
58
|
+
| `children` | `(openModal, config, paymentData, loading) => React.ReactNode` | Optional. A render prop function used only when `mode` is `'custom'`. It receives the tools needed to build a custom interface. |
|
|
12
59
|
|
|
13
60
|
### Usage
|
|
14
61
|
|
|
15
|
-
|
|
62
|
+
#### Simple Mode
|
|
16
63
|
|
|
17
|
-
|
|
18
|
-
- **simple**: Renders a collapsed card that can be expanded by the user to view details.
|
|
19
|
-
- **custom**: Provides a render prop for complete control over the UI, allowing you to build a custom display.
|
|
64
|
+
This is the most common use case, providing a compact display that users can expand for more details.
|
|
20
65
|
|
|
21
|
-
```tsx
|
|
22
|
-
import {
|
|
23
|
-
import { useSessionContext } from '../hooks/session'; // Your custom session hook
|
|
66
|
+
```tsx CreditManagement.tsx icon=logos:react
|
|
67
|
+
import { PaymentProvider, AutoTopup } from '@blocklet/payment-react';
|
|
24
68
|
|
|
25
|
-
function
|
|
26
|
-
const
|
|
69
|
+
function CreditManagement({ session, currencyId }) {
|
|
70
|
+
const handleConfigChange = (config) => {
|
|
71
|
+
console.log('Auto-topup config updated:', config);
|
|
72
|
+
// You might want to refresh the user's balance here
|
|
73
|
+
};
|
|
27
74
|
|
|
28
75
|
return (
|
|
29
|
-
<PaymentProvider session={session}
|
|
30
|
-
{/* Default mode - fully expanded */}
|
|
31
|
-
<AutoTopup
|
|
32
|
-
currencyId={currencyId}
|
|
33
|
-
onConfigChange={(config) => {
|
|
34
|
-
console.log('Auto-topup config updated:', config);
|
|
35
|
-
}}
|
|
36
|
-
/>
|
|
37
|
-
|
|
38
|
-
{/* Simple mode - collapsed by default */}
|
|
76
|
+
<PaymentProvider session={session}>
|
|
39
77
|
<AutoTopup
|
|
40
78
|
currencyId={currencyId}
|
|
41
79
|
mode="simple"
|
|
42
|
-
onConfigChange={
|
|
43
|
-
|
|
44
|
-
}}
|
|
80
|
+
onConfigChange={handleConfigChange}
|
|
81
|
+
sx={{ mt: 2 }}
|
|
45
82
|
/>
|
|
83
|
+
</PaymentProvider>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
```
|
|
46
87
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
88
|
+
#### Custom Mode
|
|
89
|
+
|
|
90
|
+
For full control over the UI, use `custom` mode with a render prop. This allows you to integrate the auto-topup status and configuration trigger into your existing layout seamlessly.
|
|
91
|
+
|
|
92
|
+
```tsx CustomAutoTopupDisplay.tsx icon=logos:react
|
|
93
|
+
import { PaymentProvider, AutoTopup } from '@blocklet/payment-react';
|
|
94
|
+
import { Button, Card, CardContent, Typography } from '@mui/material';
|
|
95
|
+
|
|
96
|
+
function CustomAutoTopupDisplay({ session, currencyId }) {
|
|
97
|
+
return (
|
|
98
|
+
<PaymentProvider session={session}>
|
|
99
|
+
<AutoTopup currencyId={currencyId} mode="custom">
|
|
100
|
+
{(openModal, config, paymentData, loading) => {
|
|
101
|
+
if (loading) return <div>Loading configuration...</div>;
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<Card variant="outlined">
|
|
105
|
+
<CardContent>
|
|
106
|
+
<Typography variant="h6">Smart Auto-Recharge</Typography>
|
|
107
|
+
{config?.enabled ? (
|
|
108
|
+
<Typography color="success.main">
|
|
109
|
+
Status: Active
|
|
110
|
+
</Typography>
|
|
111
|
+
) : (
|
|
112
|
+
<Typography color="text.secondary">
|
|
113
|
+
Status: Inactive
|
|
114
|
+
</Typography>
|
|
115
|
+
)}
|
|
116
|
+
<Button onClick={openModal} variant="contained" sx={{ mt: 2 }}>
|
|
117
|
+
{config?.enabled ? 'Modify Settings' : 'Setup Now'}
|
|
118
|
+
</Button>
|
|
119
|
+
</CardContent>
|
|
120
|
+
</Card>
|
|
121
|
+
);
|
|
122
|
+
}}
|
|
64
123
|
</AutoTopup>
|
|
65
124
|
</PaymentProvider>
|
|
66
125
|
);
|
|
67
126
|
}
|
|
68
127
|
```
|
|
69
128
|
|
|
129
|
+
## AutoTopupModal
|
|
130
|
+
|
|
131
|
+
The `AutoTopupModal` is a dialog component that allows users to enable, disable, and configure all aspects of the auto-topup feature, including the trigger threshold, purchase amount, and payment method.
|
|
132
|
+
|
|
70
133
|
### Props
|
|
71
134
|
|
|
72
135
|
| Prop | Type | Description |
|
|
73
136
|
| --- | --- | --- |
|
|
74
|
-
| `
|
|
75
|
-
| `
|
|
76
|
-
| `
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
The `AutoTopupModal` is a dialog component that allows users to enable, disable, and configure their auto-recharge settings. While it is integrated within the `AutoTopup` component, it can be used as a standalone component if you need to trigger the configuration from a custom UI element.
|
|
137
|
+
| `open` | `boolean` | **Required.** Controls whether the modal is visible. |
|
|
138
|
+
| `onClose` | `() => void` | **Required.** Callback function to close the modal. |
|
|
139
|
+
| `currencyId` | `string` | **Required.** The ID of the credit currency being configured. |
|
|
140
|
+
| `customerId` | `string` | Optional. The customer's DID. Defaults to the user from the `PaymentProvider` session. |
|
|
141
|
+
| `onSuccess` | `(config: AutoRechargeConfig) => void` | Optional. Callback triggered after the configuration is successfully saved. |
|
|
142
|
+
| `onError` | `(error: any) => void` | Optional. Callback triggered if an error occurs during submission. |
|
|
143
|
+
| `defaultEnabled` | `boolean` | Optional. If `true`, the 'Enable Auto-Topup' switch will be on by default when the modal opens for a new configuration. |
|
|
83
144
|
|
|
84
145
|
### Usage
|
|
85
146
|
|
|
86
|
-
|
|
147
|
+
Here is a complete example of how to manage the `AutoTopupModal`'s state and handle its callbacks.
|
|
87
148
|
|
|
88
|
-
```tsx
|
|
89
|
-
import {
|
|
149
|
+
```tsx AutoRechargeSettings.tsx icon=logos:react
|
|
150
|
+
import { PaymentProvider, AutoTopupModal } from '@blocklet/payment-react';
|
|
90
151
|
import { useState } from 'react';
|
|
91
|
-
import {
|
|
152
|
+
import { Button } from '@mui/material';
|
|
92
153
|
|
|
93
|
-
function AutoRechargeSettings({ currencyId }) {
|
|
94
|
-
const { session, connectApi } = useSessionContext();
|
|
154
|
+
function AutoRechargeSettings({ session, currencyId }) {
|
|
95
155
|
const [isModalOpen, setModalOpen] = useState(false);
|
|
96
156
|
|
|
97
157
|
const handleSuccess = (config) => {
|
|
98
|
-
console.log('
|
|
158
|
+
console.log('Configuration saved successfully:', config);
|
|
99
159
|
setModalOpen(false);
|
|
160
|
+
// Optionally, show a success toast or refresh data
|
|
100
161
|
};
|
|
101
162
|
|
|
102
163
|
const handleError = (error) => {
|
|
103
|
-
console.error('
|
|
164
|
+
console.error('Failed to save configuration:', error);
|
|
165
|
+
// Optionally, show an error message to the user
|
|
104
166
|
};
|
|
105
167
|
|
|
106
168
|
return (
|
|
107
|
-
<PaymentProvider session={session}
|
|
108
|
-
<
|
|
109
|
-
|
|
110
|
-
</
|
|
169
|
+
<PaymentProvider session={session}>
|
|
170
|
+
<Button variant="contained" onClick={() => setModalOpen(true)}>
|
|
171
|
+
Configure Auto-Recharge
|
|
172
|
+
</Button>
|
|
111
173
|
|
|
112
174
|
<AutoTopupModal
|
|
113
175
|
open={isModalOpen}
|
|
@@ -115,124 +177,11 @@ function AutoRechargeSettings({ currencyId }) {
|
|
|
115
177
|
currencyId={currencyId}
|
|
116
178
|
onSuccess={handleSuccess}
|
|
117
179
|
onError={handleError}
|
|
118
|
-
defaultEnabled={true}
|
|
180
|
+
defaultEnabled={true}
|
|
119
181
|
/>
|
|
120
182
|
</PaymentProvider>
|
|
121
183
|
);
|
|
122
184
|
}
|
|
123
185
|
```
|
|
124
186
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
| Prop | Type | Description |
|
|
128
|
-
| --- | --- | --- |
|
|
129
|
-
| `open` | `boolean` | **Required.** Controls whether the modal is visible. |
|
|
130
|
-
| `onClose` | `() => void` | **Required.** A callback function to close the modal. |
|
|
131
|
-
| `currencyId` | `string` | **Required.** The ID of the credit currency to configure. |
|
|
132
|
-
| `customerId` | `string` | Optional. The customer ID. Defaults to the user from the current session. |
|
|
133
|
-
| `onSuccess` | `(config: AutoRechargeConfig) => void` | Optional. A callback function executed on successful configuration. |
|
|
134
|
-
| `onError` | `(error: any) => void` | Optional. A callback function executed if an error occurs. |
|
|
135
|
-
| `defaultEnabled` | `boolean` | Optional. Sets the initial state of the 'enable' switch in the modal. Useful for quick-setup flows. |
|
|
136
|
-
|
|
137
|
-
### Configuration Flow
|
|
138
|
-
|
|
139
|
-
The following diagram illustrates the process of configuring auto-topup, including the authorization step required for payment methods.
|
|
140
|
-
|
|
141
|
-
```d2
|
|
142
|
-
shape: sequence_diagram
|
|
143
|
-
|
|
144
|
-
User: "User"
|
|
145
|
-
AutoTopupCard: "AutoTopup Component"
|
|
146
|
-
AutoTopupModal: "Configuration Modal"
|
|
147
|
-
BackendAPI: "Backend API"
|
|
148
|
-
|
|
149
|
-
User -> AutoTopupCard: "Clicks 'Configure' or 'Setup'"
|
|
150
|
-
AutoTopupCard -> AutoTopupModal: "Opens modal"
|
|
151
|
-
User -> AutoTopupModal: "Fills in threshold, amount, etc."
|
|
152
|
-
User -> AutoTopupModal: "Clicks 'Save'"
|
|
153
|
-
AutoTopupModal -> BackendAPI: "POST /api/auto-recharge-configs/submit"
|
|
154
|
-
|
|
155
|
-
auth: {
|
|
156
|
-
label: "Authorization Required"
|
|
157
|
-
BackendAPI -> AutoTopupModal: "Returns auth data (e.g., Stripe client_secret)"
|
|
158
|
-
AutoTopupModal -> User: "Renders payment form (e.g., StripeForm)"
|
|
159
|
-
User -> AutoTopupModal: "Completes payment authorization"
|
|
160
|
-
AutoTopupModal -> BackendAPI: "Confirms authorization"
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
BackendAPI -> AutoTopupModal: "Returns success response with new config"
|
|
164
|
-
AutoTopupModal -> AutoTopupCard: "Fires onSuccess callback"
|
|
165
|
-
AutoTopupModal -> User: "Closes modal"
|
|
166
|
-
AutoTopupCard -> BackendAPI: "Refreshes configuration data"
|
|
167
|
-
AutoTopupCard -> User: "Displays updated status"
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
## Complete Integration Example
|
|
171
|
-
|
|
172
|
-
Here is a complete example of a credit management dashboard that integrates the `AutoTopup` component to manage multiple credit currencies. This demonstrates the recommended approach of letting `AutoTopup` handle the modal's presentation.
|
|
173
|
-
|
|
174
|
-
```tsx
|
|
175
|
-
import {
|
|
176
|
-
PaymentProvider,
|
|
177
|
-
AutoTopup,
|
|
178
|
-
CustomerInvoiceList,
|
|
179
|
-
Amount
|
|
180
|
-
} from '@blocklet/payment-react';
|
|
181
|
-
import { useState, useEffect } from 'react';
|
|
182
|
-
import { Grid, Card, CardContent, Typography } from '@mui/material';
|
|
183
|
-
import { useSessionContext } from '../hooks/session'; // Your custom session hook
|
|
184
|
-
|
|
185
|
-
function CreditDashboard() {
|
|
186
|
-
const { session, connectApi } = useSessionContext();
|
|
187
|
-
const [creditCurrencies, setCreditCurrencies] = useState([]);
|
|
188
|
-
|
|
189
|
-
useEffect(() => {
|
|
190
|
-
// In a real app, you would fetch the user's available credit currencies
|
|
191
|
-
const fetchCurrencies = async () => {
|
|
192
|
-
const currencies = await fetchCreditCurrencies(); // Your API call
|
|
193
|
-
setCreditCurrencies(currencies);
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
if (session.user) {
|
|
197
|
-
fetchCurrencies();
|
|
198
|
-
}
|
|
199
|
-
}, [session.user]);
|
|
200
|
-
|
|
201
|
-
const handleAutoTopupChange = (currencyId, config) => {
|
|
202
|
-
console.log(`Auto-topup updated for ${currencyId}:`, config);
|
|
203
|
-
// You might want to refetch currency data here
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
return (
|
|
207
|
-
<PaymentProvider session={session} connect={connectApi}>
|
|
208
|
-
<Grid container spacing={3}>
|
|
209
|
-
{creditCurrencies.map((currency) => (
|
|
210
|
-
<Grid item xs={12} md={6} key={currency.id}>
|
|
211
|
-
<Card>
|
|
212
|
-
<CardContent>
|
|
213
|
-
<Typography variant="h6">{currency.name} Balance</Typography>
|
|
214
|
-
<Typography variant="h4" color="primary">
|
|
215
|
-
<Amount
|
|
216
|
-
amount={currency.balance}
|
|
217
|
-
decimal={currency.decimal}
|
|
218
|
-
symbol={currency.symbol}
|
|
219
|
-
/>
|
|
220
|
-
</Typography>
|
|
221
|
-
|
|
222
|
-
<AutoTopup
|
|
223
|
-
currencyId={currency.id}
|
|
224
|
-
mode="simple"
|
|
225
|
-
onConfigChange={(config) => handleAutoTopupChange(currency.id, config)}
|
|
226
|
-
sx={{ mt: 2 }}
|
|
227
|
-
/>
|
|
228
|
-
</CardContent>
|
|
229
|
-
</Card>
|
|
230
|
-
</Grid>
|
|
231
|
-
))}
|
|
232
|
-
</Grid>
|
|
233
|
-
</PaymentProvider>
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
This setup provides a robust and user-friendly interface for managing credit balances and auto-recharge settings within your application.
|
|
187
|
+
This setup provides a robust way to manage auto-recharge functionality, giving users control while ensuring a smooth experience for maintaining their service credits.
|