@blocklet/payment-react 1.20.5 → 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 +3 -3
- 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,205 +1,186 @@
|
|
|
1
1
|
# OverdueInvoicePayment
|
|
2
2
|
|
|
3
|
-
The `OverdueInvoicePayment` component is designed to handle the payment of overdue invoices for a specific customer or subscription. It
|
|
3
|
+
The `OverdueInvoicePayment` component is a specialized tool designed to handle the payment of overdue invoices for a specific customer or subscription. It simplifies the process by automatically fetching overdue invoices and presenting users with a clear interface to settle their outstanding payments.
|
|
4
4
|
|
|
5
|
-
This component
|
|
5
|
+
This component can operate in two modes: a default mode that displays a pre-built dialog for quick integration, and a custom mode that provides the flexibility to build a unique user interface using a render prop.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## How It Works
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
The component orchestrates the entire overdue payment process, from fetching data to handling the final transaction confirmation.
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
```d2 Overdue Payment Flow
|
|
12
|
+
direction: down
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
User: {
|
|
15
|
+
shape: c4-person
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
Client-App: {
|
|
19
|
+
label: "Client Application"
|
|
20
|
+
shape: rectangle
|
|
15
21
|
|
|
16
|
-
|
|
22
|
+
OverdueInvoicePayment-Component: {
|
|
23
|
+
label: "OverdueInvoicePayment Component"
|
|
24
|
+
shape: rectangle
|
|
25
|
+
}
|
|
26
|
+
}
|
|
17
27
|
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
Payment-Backend: {
|
|
29
|
+
label: "Payment Backend"
|
|
30
|
+
shape: cylinder
|
|
31
|
+
}
|
|
20
32
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
API: "Payment Service API"
|
|
33
|
+
DID-Wallet: {
|
|
34
|
+
label: "DID Wallet"
|
|
35
|
+
icon: "https://www.arcblock.io/image-bin/uploads/37198ddc4a0b9e91e5c1c821ab895a34.svg"
|
|
36
|
+
}
|
|
26
37
|
|
|
27
|
-
User -> App: "
|
|
28
|
-
App ->
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
User -> Client-App.OverdueInvoicePayment-Component: "1. Renders the component"
|
|
39
|
+
Client-App.OverdueInvoicePayment-Component -> Payment-Backend: "2. Fetch overdue invoices"
|
|
40
|
+
Payment-Backend -> Client-App.OverdueInvoicePayment-Component: "3. Return invoice summary"
|
|
41
|
+
Client-App.OverdueInvoicePayment-Component -> User: "4. Display payment dialog"
|
|
42
|
+
User -> Client-App.OverdueInvoicePayment-Component: "5. Clicks 'Pay Now'"
|
|
43
|
+
Client-App.OverdueInvoicePayment-Component -> DID-Wallet: "6. Opens connect session (collect-batch)"
|
|
44
|
+
User -> DID-Wallet: "7. Approves payment"
|
|
45
|
+
DID-Wallet -> Client-App.OverdueInvoicePayment-Component: "8. Sends success callback"
|
|
46
|
+
Payment-Backend -> Client-App.OverdueInvoicePayment-Component: "9. WebSocket event (invoice.paid)"
|
|
47
|
+
Client-App.OverdueInvoicePayment-Component -> User: "10. Update UI (e.g., close dialog)"
|
|
31
48
|
|
|
32
|
-
alt "Invoices exist"
|
|
33
|
-
OIP -> App: "Renders payment UI (dialog/custom)"
|
|
34
|
-
User -> OIP: "Clicks 'Pay Now'"
|
|
35
|
-
OIP -> PaymentProvider: "Calls connect.open()"
|
|
36
|
-
PaymentProvider -> User: "Shows DID Wallet connect modal"
|
|
37
|
-
User -> PaymentProvider: "Scans & confirms payment"
|
|
38
|
-
PaymentProvider -> API: "Processes batch payment"
|
|
39
|
-
API -> PaymentProvider: "Payment successful"
|
|
40
|
-
PaymentProvider -> OIP: "Triggers onSuccess"
|
|
41
|
-
OIP -> OIP: "Refreshes invoice data"
|
|
42
|
-
OIP -> App: "Calls onPaid() & closes UI"
|
|
43
|
-
else "No overdue invoices"
|
|
44
|
-
OIP -> App: "Displays success/empty message"
|
|
45
|
-
end
|
|
46
49
|
```
|
|
47
50
|
|
|
48
51
|
## Props
|
|
49
52
|
|
|
53
|
+
The `OverdueInvoicePayment` component accepts the following props to customize its behavior:
|
|
54
|
+
|
|
50
55
|
| Prop | Type | Description |
|
|
51
|
-
|
|
52
|
-
| `subscriptionId` | `string` |
|
|
53
|
-
| `customerId` | `string` |
|
|
54
|
-
| `mode` | `'default' \| 'custom'` |
|
|
55
|
-
| `onPaid` | `(id, currencyId, type) => void` |
|
|
56
|
-
| `dialogProps` | `object` | Optional
|
|
57
|
-
| `detailLinkOptions` | `object` | Optional
|
|
58
|
-
| `successToast` | `boolean` |
|
|
59
|
-
| `alertMessage` | `string` |
|
|
60
|
-
| `children` | `
|
|
61
|
-
| `authToken` | `string` |
|
|
56
|
+
|---|---|---|
|
|
57
|
+
| `subscriptionId` | `string` | The ID of the subscription to check for overdue invoices. Either `subscriptionId` or `customerId` must be provided. |
|
|
58
|
+
| `customerId` | `string` | The ID or DID of the customer. Use this to handle all overdue invoices for a customer. |
|
|
59
|
+
| `mode` | `'default'` \| `'custom'` | The rendering mode. `'default'` shows a pre-built dialog. `'custom'` uses the `children` render prop for a custom UI. Defaults to `'default'`. |
|
|
60
|
+
| `onPaid` | `(id, currencyId, type) => void` | An optional callback function that is triggered after payment is successfully completed. `id` will be the `subscriptionId` or `customerId`, `type` will be `'subscription'` or `'customer'`. |
|
|
61
|
+
| `dialogProps` | `object` | Optional props to pass to the underlying Material-UI `Dialog` component in `default` mode. e.g., `{ open: true, title: 'Custom Title', onClose: handleClose }`. |
|
|
62
|
+
| `detailLinkOptions` | `object` | Optional settings for the "View Details" link. Can be used to disable the link, change its text, or provide a custom `onClick` handler. Format: `{ enabled?: boolean, onClick?: function, title?: string }`. |
|
|
63
|
+
| `successToast` | `boolean` | If `true`, a success toast notification is shown upon successful payment. Defaults to `true`. |
|
|
64
|
+
| `alertMessage` | `string` | An optional message to append to the default title text when in customer mode. |
|
|
65
|
+
| `children` | `(handlePay, data) => React.ReactNode` | A render prop function used only when `mode` is `'custom'`. It receives a `handlePay` function and a `data` object. |
|
|
66
|
+
| `authToken` | `string` | An optional authentication token for API requests, useful for server-to-server or cross-origin scenarios. |
|
|
62
67
|
|
|
63
|
-
|
|
68
|
+
### `children` Render Prop
|
|
64
69
|
|
|
65
|
-
|
|
70
|
+
When using `mode="custom"`, the `children` function receives two arguments:
|
|
66
71
|
|
|
67
|
-
|
|
72
|
+
1. **`handlePay(item: SummaryItem)`**: A function to initiate the payment process for a specific currency group. The `item` object comes from the `data.summary` object.
|
|
73
|
+
2. **`data`**: An object containing the fetched payment information:
|
|
74
|
+
* `subscription?: Subscription`: The subscription details, if `subscriptionId` was provided.
|
|
75
|
+
* `summary: { [key: string]: SummaryItem }`: An object where each key is a currency ID and the value contains the total amount, currency details, and payment method.
|
|
76
|
+
* `invoices: Invoice[]`: An array of all overdue invoice objects.
|
|
77
|
+
* `subscriptionCount?: number`: The number of subscriptions with overdue invoices (for customer mode).
|
|
78
|
+
* `detailUrl: string`: The URL to view detailed invoice information.
|
|
68
79
|
|
|
69
|
-
|
|
80
|
+
## Usage Examples
|
|
70
81
|
|
|
71
|
-
|
|
82
|
+
All examples assume you have `PaymentProvider` set up in your application.
|
|
72
83
|
|
|
73
|
-
|
|
84
|
+
### 1. Default Mode for a Subscription
|
|
74
85
|
|
|
75
|
-
|
|
76
|
-
import { PaymentProvider, OverdueInvoicePayment } from '@blocklet/payment-react';
|
|
77
|
-
// This is a local utility to get session info from your app's context.
|
|
78
|
-
// See the PaymentProvider docs for setup details.
|
|
79
|
-
import { useSessionContext } from 'src/hooks/session';
|
|
86
|
+
This is the simplest way to handle overdue payments for a specific subscription. The component will automatically render a dialog if any overdue invoices are found.
|
|
80
87
|
|
|
81
|
-
|
|
82
|
-
|
|
88
|
+
```tsx SubscriptionOverdue.tsx icon=logos:react
|
|
89
|
+
import { OverdueInvoicePayment, PaymentProvider } from '@blocklet/payment-react';
|
|
90
|
+
import { useSessionContext } from './hooks/session'; // Your custom session hook
|
|
83
91
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// You can refresh the subscription status here
|
|
87
|
-
};
|
|
92
|
+
function SubscriptionPage({ subscriptionId }) {
|
|
93
|
+
const { session, connect } = useSessionContext();
|
|
88
94
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
const handlePaymentSuccess = (id, currencyId, type) => {
|
|
96
|
+
console.log(`Payment successful for ${type} ${id} with currency ${currencyId}`);
|
|
97
|
+
// You can refetch subscription data here to update its status
|
|
98
|
+
};
|
|
92
99
|
|
|
93
100
|
return (
|
|
94
|
-
<PaymentProvider session={session} connect={
|
|
101
|
+
<PaymentProvider session={session} connect={connect}>
|
|
102
|
+
{/* This component will be null if there are no overdue invoices */}
|
|
95
103
|
<OverdueInvoicePayment
|
|
96
104
|
subscriptionId={subscriptionId}
|
|
97
105
|
onPaid={handlePaymentSuccess}
|
|
98
106
|
/>
|
|
107
|
+
{/* Other subscription details can be rendered here */}
|
|
99
108
|
</PaymentProvider>
|
|
100
109
|
);
|
|
101
110
|
}
|
|
102
111
|
```
|
|
103
112
|
|
|
104
|
-
|
|
113
|
+
### 2. Default Mode for a Customer
|
|
105
114
|
|
|
106
|
-
|
|
115
|
+
Use this to create a centralized place for a customer to pay all their overdue invoices across multiple subscriptions.
|
|
107
116
|
|
|
108
|
-
```tsx
|
|
109
|
-
import {
|
|
110
|
-
|
|
111
|
-
// See the PaymentProvider docs for setup details.
|
|
112
|
-
import { useSessionContext } from 'src/hooks/session';
|
|
117
|
+
```tsx CustomerDashboard.tsx icon=logos:react
|
|
118
|
+
import { OverdueInvoicePayment, PaymentProvider } from '@blocklet/payment-react';
|
|
119
|
+
import { useSessionContext } from './hooks/session'; // Your custom session hook
|
|
113
120
|
|
|
114
121
|
function CustomerDashboard() {
|
|
115
|
-
const { session, connect
|
|
116
|
-
|
|
117
|
-
if (!session?.user?.did || !connectApi) {
|
|
118
|
-
return <div>Loading session...</div>;
|
|
119
|
-
}
|
|
122
|
+
const { session, connect } = useSessionContext();
|
|
120
123
|
|
|
121
124
|
return (
|
|
122
|
-
<PaymentProvider session={session} connect={
|
|
125
|
+
<PaymentProvider session={session} connect={connect}>
|
|
126
|
+
<h2>Payment Center</h2>
|
|
127
|
+
<p>Please settle any outstanding payments to ensure uninterrupted service.</p>
|
|
123
128
|
<OverdueInvoicePayment
|
|
124
129
|
customerId={session.user.did}
|
|
125
130
|
onPaid={() => {
|
|
126
|
-
console.log(
|
|
127
|
-
// Refresh customer
|
|
128
|
-
}}
|
|
129
|
-
dialogProps={{
|
|
130
|
-
title: 'Outstanding Payments',
|
|
131
|
+
console.log('All customer overdue invoices paid for a currency!');
|
|
132
|
+
// Refresh customer account status
|
|
131
133
|
}}
|
|
132
134
|
/>
|
|
135
|
+
{/* The rest of the customer dashboard */}
|
|
133
136
|
</PaymentProvider>
|
|
134
137
|
);
|
|
135
138
|
}
|
|
136
139
|
```
|
|
137
140
|
|
|
138
|
-
### Custom Mode
|
|
139
|
-
|
|
140
|
-
For full control over the user interface, set `mode="custom"`. This allows you to build a completely custom component for handling overdue payments using the `children` render prop.
|
|
141
|
-
|
|
142
|
-
The render prop receives two arguments:
|
|
143
|
-
1. `handlePay`: A function to trigger the payment process. It takes a `SummaryItem` object as an argument.
|
|
144
|
-
2. `data`: An object containing all the necessary information about the overdue invoices.
|
|
141
|
+
### 3. Custom UI Mode
|
|
145
142
|
|
|
146
|
-
|
|
143
|
+
For full control over the user experience, use `mode="custom"`. This allows you to integrate the payment functionality directly into your existing UI instead of using a dialog.
|
|
147
144
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
import {
|
|
152
|
-
PaymentProvider,
|
|
153
|
-
OverdueInvoicePayment,
|
|
154
|
-
Amount,
|
|
155
|
-
} from '@blocklet/payment-react';
|
|
145
|
+
```tsx CustomOverdueUI.tsx icon=logos:react
|
|
146
|
+
import { OverdueInvoicePayment, PaymentProvider, Amount } from '@blocklet/payment-react';
|
|
147
|
+
import { useSessionContext } from './hooks/session'; // Your custom session hook
|
|
156
148
|
import { Card, CardContent, Typography, Button, Stack } from '@mui/material';
|
|
157
|
-
// This is a local utility to get session info from your app's context.
|
|
158
|
-
// See the PaymentProvider docs for setup details.
|
|
159
|
-
import { useSessionContext } from 'src/hooks/session';
|
|
160
149
|
|
|
161
150
|
function CustomOverdueUI({ subscriptionId }) {
|
|
162
|
-
const { session, connect
|
|
163
|
-
|
|
164
|
-
if (!session || !connectApi) {
|
|
165
|
-
return <div>Loading session...</div>;
|
|
166
|
-
}
|
|
151
|
+
const { session, connect } = useSessionContext();
|
|
167
152
|
|
|
168
153
|
return (
|
|
169
|
-
<PaymentProvider session={session} connect={
|
|
154
|
+
<PaymentProvider session={session} connect={connect}>
|
|
170
155
|
<OverdueInvoicePayment
|
|
171
156
|
subscriptionId={subscriptionId}
|
|
172
157
|
mode="custom"
|
|
173
|
-
onPaid={() => console.log('
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
158
|
+
onPaid={() => console.log('Custom UI payment successful!')}
|
|
159
|
+
>
|
|
160
|
+
{(handlePay, { summary, invoices }) => {
|
|
161
|
+
const summaryList = Object.values(summary);
|
|
162
|
+
if (invoices.length === 0) {
|
|
163
|
+
return <Typography>No overdue payments. All clear!</Typography>;
|
|
177
164
|
}
|
|
178
165
|
|
|
179
166
|
return (
|
|
180
167
|
<Card variant="outlined">
|
|
181
168
|
<CardContent>
|
|
182
|
-
<Typography variant="h6" gutterBottom>
|
|
183
|
-
Action Required for {subscription?.description}
|
|
184
|
-
</Typography>
|
|
185
|
-
<Typography color="error" gutterBottom>
|
|
169
|
+
<Typography variant="h6" color="error" gutterBottom>
|
|
186
170
|
You have {invoices.length} overdue invoice(s).
|
|
187
171
|
</Typography>
|
|
188
|
-
<Stack spacing={2}
|
|
189
|
-
{
|
|
190
|
-
<Stack
|
|
191
|
-
key={info.currency.id}
|
|
192
|
-
direction="row"
|
|
193
|
-
justifyContent="space-between"
|
|
194
|
-
alignItems="center">
|
|
172
|
+
<Stack spacing={2} mt={2}>
|
|
173
|
+
{summaryList.map((item) => (
|
|
174
|
+
<Stack key={item.currency.id} direction="row" justifyContent="space-between" alignItems="center">
|
|
195
175
|
<Typography>
|
|
196
|
-
Total Due: <Amount amount={
|
|
176
|
+
Total Due: <Amount amount={item.amount} decimal={item.currency.decimal} symbol={item.currency.symbol} />
|
|
197
177
|
</Typography>
|
|
198
178
|
<Button
|
|
199
|
-
onClick={() => handlePay(info)}
|
|
200
179
|
variant="contained"
|
|
201
|
-
color="primary"
|
|
202
|
-
|
|
180
|
+
color="primary"
|
|
181
|
+
onClick={() => handlePay(item)}
|
|
182
|
+
>
|
|
183
|
+
Pay with {item.currency.symbol}
|
|
203
184
|
</Button>
|
|
204
185
|
</Stack>
|
|
205
186
|
))}
|
|
@@ -213,19 +194,3 @@ function CustomOverdueUI({ subscriptionId }) {
|
|
|
213
194
|
);
|
|
214
195
|
}
|
|
215
196
|
```
|
|
216
|
-
|
|
217
|
-
#### Custom Mode `data` Object
|
|
218
|
-
|
|
219
|
-
The `data` object passed to the `children` render prop contains the following fields:
|
|
220
|
-
|
|
221
|
-
| Field | Type | Description |
|
|
222
|
-
| --- | --- | --- |
|
|
223
|
-
| `subscription` | `Subscription` | The full subscription object, if `subscriptionId` was provided. |
|
|
224
|
-
| `summary` | `{ [key: string]: SummaryItem }` | An object summarizing the total amount due, grouped by currency ID. Each `SummaryItem` contains `amount`, `currency`, and `method`. |
|
|
225
|
-
| `invoices` | `Invoice[]` | An array of the raw overdue invoice objects. |
|
|
226
|
-
| `subscriptionCount` | `number` | The number of subscriptions with overdue payments, if `customerId` was provided. |
|
|
227
|
-
| `detailUrl` | `string` | A pre-generated URL to the detailed invoice or subscription page. |
|
|
228
|
-
|
|
229
|
-
### Note on Payment Methods
|
|
230
|
-
|
|
231
|
-
The batch payment flow initiated by this component currently supports wallet-based payments (like ArcBlock, Ethereum). It does not support batch payments via Stripe. If an overdue invoice's payment method is Stripe, the component will guide the user to a page where they can pay manually.
|