@blocklet/payment-react 1.20.5 → 1.20.7

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 +3 -3
  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,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 can operate in two modes: a default dialog mode that presents a pre-built UI for payment, or a custom mode that provides data and a payment handler to build a custom user interface.
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 streamlines the process of collecting late payments by summarizing amounts by currency and initiating a batch payment process through the user's DID Wallet.
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
- ## When to Use
7
+ ## How It Works
8
8
 
9
- Use this component in your application's subscription management or customer billing sections to:
9
+ The component orchestrates the entire overdue payment process, from fetching data to handling the final transaction confirmation.
10
10
 
11
- - Prompt users to pay for a subscription that has fallen into a `past_due` status.
12
- - Allow customers to clear all outstanding invoices across multiple subscriptions in a single operation.
11
+ ```d2 Overdue Payment Flow
12
+ direction: down
13
13
 
14
- ## Component Logic Flow
14
+ User: {
15
+ shape: c4-person
16
+ }
17
+
18
+ Client-App: {
19
+ label: "Client Application"
20
+ shape: rectangle
15
21
 
16
- The component follows a clear sequence to manage overdue payments:
22
+ OverdueInvoicePayment-Component: {
23
+ label: "OverdueInvoicePayment Component"
24
+ shape: rectangle
25
+ }
26
+ }
17
27
 
18
- ```d2
19
- shape: sequence_diagram
28
+ Payment-Backend: {
29
+ label: "Payment Backend"
30
+ shape: cylinder
31
+ }
20
32
 
21
- User: "User"
22
- App: "Your Application"
23
- OIP: "OverdueInvoicePayment"
24
- PaymentProvider: "PaymentProvider"
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: "Views page with overdue invoices"
28
- App -> OIP: "Renders with subscriptionId or customerId"
29
- OIP -> API: "GET /overdue/invoices"
30
- API -> OIP: "Returns summary & invoices list"
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` | Optional. The ID of the subscription to check for overdue invoices. Either `subscriptionId` or `customerId` must be provided. |
53
- | `customerId` | `string` | Optional. The customer's ID (or DID) to check for all overdue invoices across their subscriptions. |
54
- | `mode` | `'default' \| 'custom'` | Optional. The rendering mode. `'default'` displays a pre-built dialog. `'custom'` uses a render prop for a custom UI. Defaults to `'default'`. |
55
- | `onPaid` | `(id, currencyId, type) => void` | Optional. A callback function executed after all overdue invoices are paid. It receives the source ID (`subscriptionId` or `customerId`), the currency ID, and the source type (`'subscription'` or `'customer'`). |
56
- | `dialogProps` | `object` | Optional. Props to pass to the underlying Material-UI `Dialog` component in `default` mode. Can be used to control its `open` state, `title`, and `onClose` behavior. |
57
- | `detailLinkOptions` | `object` | Optional. An object to configure the "view details" link in the default dialog. Shape: `{ enabled?: boolean, onClick?: (e) => void, title?: string }`. |
58
- | `successToast` | `boolean` | Optional. If `true`, a success toast notification is shown upon successful payment. Defaults to `true`. |
59
- | `alertMessage` | `string` | Optional. A custom message to append to the default alert text when checking by `customerId`. |
60
- | `children` | `function` | Optional. A render prop function used only when `mode="custom"`. It receives `handlePay` and `data` as arguments. |
61
- | `authToken` | `string` | Optional. An authentication token for API requests, useful for cross-origin scenarios where session cookies are not available. |
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
- ## Usage
68
+ ### `children` Render Prop
64
69
 
65
- > All examples assume you have set up `PaymentProvider` and a `useSessionContext` hook to provide session data. The `useSessionContext` hook is a local utility to access your application's session context. For a complete guide on this setup, please refer to the [PaymentProvider documentation](./providers-payment-provider.md).
70
+ When using `mode="custom"`, the `children` function receives two arguments:
66
71
 
67
- ### Default Mode Usage
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
- In its default mode, the component renders a dialog that summarizes the overdue payments and prompts the user to pay. This is the quickest way to implement overdue payment handling.
80
+ ## Usage Examples
70
81
 
71
- #### Handling a Single Subscription's Overdue Invoices
82
+ All examples assume you have `PaymentProvider` set up in your application.
72
83
 
73
- Provide the `subscriptionId` to target a specific subscription. A dialog will appear if there are any overdue invoices.
84
+ ### 1. Default Mode for a Subscription
74
85
 
75
- ```tsx
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
- function SubscriptionDetailsPage({ subscriptionId }) {
82
- const { session, connect: connectApi } = useSessionContext();
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
- const handlePaymentSuccess = () => {
85
- console.log('All overdue invoices for the subscription have been paid.');
86
- // You can refresh the subscription status here
87
- };
92
+ function SubscriptionPage({ subscriptionId }) {
93
+ const { session, connect } = useSessionContext();
88
94
 
89
- if (!session || !connectApi) {
90
- return <div>Loading session...</div>;
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={connectApi}>
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
- #### Handling All of a Customer's Overdue Invoices
113
+ ### 2. Default Mode for a Customer
105
114
 
106
- Provide the `customerId` (which can be the user's DID) to consolidate all overdue invoices from all of their subscriptions into a single payment flow.
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 { PaymentProvider, OverdueInvoicePayment } from '@blocklet/payment-react';
110
- // This is a local utility to get session info from your app's context.
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: connectApi } = useSessionContext();
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={connectApi}>
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("All of the customer's overdue invoices are paid.");
127
- // Refresh customer data or redirect
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 Usage
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
- #### Building a Custom UI
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
- Here is an example of creating a custom card to display overdue payment information and trigger payments.
149
-
150
- ```tsx
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: connectApi } = useSessionContext();
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={connectApi}>
154
+ <PaymentProvider session={session} connect={connect}>
170
155
  <OverdueInvoicePayment
171
156
  subscriptionId={subscriptionId}
172
157
  mode="custom"
173
- onPaid={() => console.log('Paid!')}>
174
- {(handlePay, { summary, invoices, subscription }) => {
175
- if (!invoices || invoices.length === 0) {
176
- return <Typography>No overdue payments. All good!</Typography>;
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} sx={{ mt: 2 }}>
189
- {Object.values(summary).map((info) => (
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={info.amount} decimal={info.currency.decimal} symbol={info.currency.symbol} />
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
- Pay Now
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.