@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.
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,176 +1,189 @@
1
1
  # ResumeSubscription
2
2
 
3
- The `ResumeSubscription` component provides a user interface for resuming a canceled subscription. It handles the necessary logic, including prompting the user to re-stake funds if required, and appears as a modal dialog by default.
3
+ The `ResumeSubscription` component provides a straightforward UI for users to resume a canceled subscription. It renders a dialog that guides the user through the confirmation process and automatically handles complex scenarios like re-staking if the subscription requires it.
4
4
 
5
- This component must be used within a [`PaymentProvider`](./providers-payment-provider.md) to access the required payment context.
5
+ This component must be used within a `PaymentProvider` to access the necessary context for handling wallet interactions.
6
6
 
7
- ## How It Works
7
+ ## Workflow
8
8
 
9
- The component streamlines the subscription recovery process. When rendered, it first checks if the subscription requires a new stake to be resumed. Based on this information, it presents one of two flows:
10
-
11
- 1. **Direct Resume**: If no new stake is needed, the user can confirm to directly reactivate the subscription.
12
- 2. **Resume with Re-Stake**: If a stake is required, the component will initiate a wallet connection flow, asking the user to approve the staking transaction to resume their subscription.
9
+ The following diagram illustrates the process flow when a user resumes a subscription, including the conditional logic for re-staking.
13
10
 
14
11
  ```d2
15
12
  shape: sequence_diagram
16
13
 
17
- User
18
- "React App"
19
- "ResumeSubscription"
20
- "Payment API"
21
- "DID Wallet"
14
+ User: { shape: c4-person }
15
+ ResumeSubscription: { label: "ResumeSubscription Component" }
16
+ PaymentAPI: { label: "Payment API" }
17
+ DIDWallet: { label: "DID Wallet" }
22
18
 
23
- User -> "React App": "Clicks 'Resume Subscription'"
24
- "React App" -> "ResumeSubscription": "Renders with subscriptionId"
19
+ User -> ResumeSubscription: "1. Triggers resume"
20
+ ResumeSubscription -> PaymentAPI: "2. GET /recover-info"
21
+ PaymentAPI -> ResumeSubscription: "3. Return status\n(e.g., needStake: true)"
25
22
 
26
- "ResumeSubscription" -> "Payment API": "GET /recover-info"
27
- "Payment API" --> "ResumeSubscription": "{ needStake }"
23
+ ResumeSubscription.t1 -> User: "4. Show confirmation dialog"
24
+ User -> ResumeSubscription.t1: "5. Confirm"
28
25
 
29
- alt "Direct Resume (needStake is false)" {
30
- "ResumeSubscription" -> "Payment API": "PUT /recover"
31
- "Payment API" --> "ResumeSubscription": "{ subscription }"
26
+ alt "Re-Staking Required" {
27
+ ResumeSubscription.t1 -> DIDWallet: "6a. Open re-stake session"
28
+ User -> DIDWallet: "7a. Approve"
29
+ DIDWallet -> ResumeSubscription.t1: "8a. Success callback"
32
30
  }
33
31
 
34
- alt "Re-Stake Required (needStake is true)" {
35
- "ResumeSubscription" -> "DID Wallet": "Opens connect for 're-stake'"
36
- User -> "DID Wallet": "Approves transaction"
37
- "DID Wallet" --> "ResumeSubscription": "onSuccess()"
32
+ alt "No Staking Required" {
33
+ ResumeSubscription.t1 -> PaymentAPI: "6b. PUT /recover"
34
+ PaymentAPI -> ResumeSubscription.t1: "7b. Success"
38
35
  }
39
36
 
40
- "ResumeSubscription" -> "Payment API": "GET /subscriptions/:id (on success)"
41
- "Payment API" --> "ResumeSubscription": "Updated subscription data"
42
- "ResumeSubscription" -> "React App": "onResumed(subscription)"
43
- "React App" -> User: "UI is updated"
37
+ ResumeSubscription.t1 -> PaymentAPI: "9. Fetch updated subscription"
38
+ PaymentAPI -> ResumeSubscription.t1: "10. Return subscription"
39
+ ResumeSubscription.t1 -> User: "11. Call onResumed() & close dialog"
40
+
44
41
  ```
45
42
 
43
+
46
44
  ## Props
47
45
 
48
- | Prop | Type | Description |
49
- | :--------------- | :------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
50
- | `subscriptionId` | `string` | **Required.** The ID of the subscription to be resumed. |
51
- | `onResumed` | `(sub: Subscription \| TSubscriptionExpanded) => void` | Optional. A callback function that is executed after the subscription has been successfully resumed. It receives the updated subscription object as an argument. |
52
- | `dialogProps` | `object` | Optional. Props to customize the underlying Material-UI Dialog component. Default: `{ open: true }`. Key properties include:<br />- `open`: `boolean`, controls visibility.<br />- `onClose`: `() => void`, a callback for when the dialog is closed.<br />- `title`: `string`, overrides the default dialog title. |
53
- | `successToast` | `boolean` | Optional. If `true`, a success toast notification is shown upon successful resumption. Defaults to `true`. |
54
- | `authToken` | `string` | Optional. An authentication token to be included in API requests. This is useful for cross-origin requests or when the application manages authentication separately. |
46
+ | Prop | Type | Required | Description |
47
+ | ---------------- | -------------------------------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
48
+ | `subscriptionId` | `string` | Yes | The unique identifier of the subscription to be resumed. |
49
+ | `onResumed` | `(subscription: Subscription) => void` | No | A callback function that is triggered after the subscription is successfully resumed. It receives the updated subscription object as an argument. |
50
+ | `dialogProps` | `object` | No | Props to customize the underlying Material-UI Dialog. You can control its state (`open`, `onClose`) and appearance (`title`). |
51
+ | `successToast` | `boolean` | No | If `true`, a success notification toast is displayed upon successful resumption. Defaults to `true`. |
52
+ | `authToken` | `string` | No | An optional authentication token for API requests. This is useful for cross-origin or server-to-server integration scenarios. |
55
53
 
56
54
  ## Usage Examples
57
55
 
58
- <div class="lead">All examples require the component to be wrapped in a `PaymentProvider`. The `session` and `connect` props are obtained using a custom `useSessionContext` hook, which represents your application's authentication state. For detailed setup instructions, please refer to the <a href="/providers/payment-provider">PaymentProvider documentation</a>.</div>
59
-
60
56
  ### Basic Usage
61
57
 
62
- This example shows the simplest way to use `ResumeSubscription`. The dialog will be open by default, and a success toast will appear upon completion.
58
+ This is the simplest way to use the component. It will render an open dialog by default.
63
59
 
64
- ```tsx
65
- import React from 'react';
66
- import { PaymentProvider, ResumeSubscription } from '@blocklet/payment-react';
60
+ ```tsx Basic ResumeSubscription Example icon=logos:react
61
+ import { ResumeSubscription } from '@blocklet/payment-react';
67
62
 
68
- // Placeholder for your application's session context hook.
69
- // See the PaymentProvider documentation for setup details.
70
- import { useSessionContext } from '../hooks/use-session-context';
63
+ function ResumePage({ subscriptionId }) {
64
+ // This component must be rendered within a PaymentProvider
65
+ return <ResumeSubscription subscriptionId={subscriptionId} />;
66
+ }
67
+ ```
71
68
 
72
- function SubscriptionManagementPage({ subscriptionId, refetchSubscription }) {
73
- // session and connect are derived from your application's auth service.
74
- const { session, connect } = useSessionContext();
69
+ ### Handling the Result
75
70
 
76
- if (!session) {
77
- return <div>Loading session...</div>;
78
- }
71
+ Use the `onResumed` callback to receive the updated subscription data and refresh your application's state.
72
+
73
+ ```tsx Handling the onResumed Callback icon=logos:react
74
+ import { ResumeSubscription } from '@blocklet/payment-react';
75
+ import { useState } from 'react';
76
+
77
+ function SubscriptionDetails({ initialSubscription }) {
78
+ const [subscription, setSubscription] = useState(initialSubscription);
79
+
80
+ const handleSubscriptionResumed = (updatedSubscription) => {
81
+ console.log('Subscription has been successfully resumed:', updatedSubscription);
82
+ setSubscription(updatedSubscription);
83
+ // You can also show a confirmation message or redirect the user.
84
+ };
79
85
 
80
86
  return (
81
- <PaymentProvider session={session} connect={connect}>
87
+ <div>
88
+ {/* Display subscription details based on the `subscription` state */}
82
89
  <ResumeSubscription
83
- subscriptionId={subscriptionId}
84
- onResumed={(subscription) => {
85
- console.log('Subscription resumed:', subscription);
86
- // Update your application's state here.
87
- refetchSubscription();
88
- }}
90
+ subscriptionId={subscription.id}
91
+ onResumed={handleSubscriptionResumed}
89
92
  />
90
- </PaymentProvider>
93
+ </div>
91
94
  );
92
95
  }
93
96
  ```
94
97
 
95
98
  ### Controlling the Dialog
96
99
 
97
- You can manage the dialog's visibility from a parent component by passing its state down through `dialogProps`.
100
+ For a more practical integration, control the dialog's visibility from a parent component. This allows you to open it in response to a user action, like clicking a button.
98
101
 
99
- ```tsx
100
- import React, { useState } from 'react';
102
+ ```tsx Triggering ResumeSubscription with a Button icon=logos:react
103
+ import { ResumeSubscription } from '@blocklet/payment-react';
104
+ import { useState } from 'react';
101
105
  import { Button } from '@mui/material';
102
- import { PaymentProvider, ResumeSubscription } from '@blocklet/payment-react';
103
106
 
104
- // Placeholder for your application's session context hook.
105
- // See the PaymentProvider documentation for setup details.
106
- import { useSessionContext } from '../hooks/use-session-context';
107
+ function SubscriptionActions({ subscriptionId }) {
108
+ const [isModalOpen, setIsModalOpen] = useState(false);
107
109
 
108
- function SubscriptionDetails({ subscriptionId, refetchSubscription }) {
109
- const [isResumeDialogOpen, setResumeDialogOpen] = useState(false);
110
- const { session, connect } = useSessionContext();
111
-
112
- const handleCloseDialog = () => {
113
- setResumeDialogOpen(false);
110
+ const handleResumed = () => {
111
+ setIsModalOpen(false);
112
+ // Refetch subscription data to update UI
113
+ alert('Subscription resumed!');
114
114
  };
115
115
 
116
- if (!session) {
117
- return <div>Loading session...</div>;
118
- }
119
-
120
116
  return (
121
- <PaymentProvider session={session} connect={connect}>
122
- <Button onClick={() => setResumeDialogOpen(true)}>
117
+ <>
118
+ <Button variant="contained" onClick={() => setIsModalOpen(true)}>
123
119
  Resume Subscription
124
120
  </Button>
125
121
 
126
- {isResumeDialogOpen && (
122
+ {isModalOpen && (
127
123
  <ResumeSubscription
128
124
  subscriptionId={subscriptionId}
129
- onResumed={() => {
130
- console.log('Subscription has been resumed.');
131
- handleCloseDialog();
132
- refetchSubscription(); // Refresh subscription data in parent component.
133
- }}
125
+ onResumed={handleResumed}
134
126
  dialogProps={{
135
- open: isResumeDialogOpen,
136
- onClose: handleCloseDialog,
127
+ open: isModalOpen,
137
128
  title: 'Confirm Subscription Renewal',
129
+ onClose: () => setIsModalOpen(false),
138
130
  }}
139
131
  />
140
132
  )}
141
- </PaymentProvider>
133
+ </>
142
134
  );
143
135
  }
144
136
  ```
145
137
 
146
- ### Usage with an Authentication Token
138
+ ## Full Integration Example
147
139
 
148
- If your API requests require an authentication token, provide it using the `authToken` prop. This is useful for secure communication between different services or Blocklets.
140
+ Here is a complete example showing how to integrate `ResumeSubscription` within the required `PaymentProvider`.
149
141
 
150
- ```tsx
151
- import React from 'react';
142
+ ```tsx Complete Integration Example icon=logos:react
152
143
  import { PaymentProvider, ResumeSubscription } from '@blocklet/payment-react';
144
+ import { useSessionContext } from 'path/to/your/session/context'; // Your app's session context
145
+ import { useState } from 'react';
146
+ import { Button, Card, CardContent, Typography } from '@mui/material';
153
147
 
154
- // Placeholder for your application's session context hook.
155
- // See the PaymentProvider documentation for setup details.
156
- import { useSessionContext } from '../hooks/use-session-context';
157
-
158
- function SecureSubscriptionResume({ subscriptionId, token }) {
148
+ function SubscriptionManagementPage({ subscription }) {
159
149
  const { session, connect } = useSessionContext();
150
+ const [isResumeOpen, setIsResumeOpen] = useState(false);
160
151
 
161
- if (!session) {
162
- return <div>Loading session...</div>;
163
- }
152
+ const handleResumed = (updatedSubscription) => {
153
+ console.log('Subscription updated:', updatedSubscription);
154
+ setIsResumeOpen(false);
155
+ // Ideally, you would trigger a data refetch here to update the entire page.
156
+ };
164
157
 
165
158
  return (
166
159
  <PaymentProvider session={session} connect={connect}>
167
- <ResumeSubscription
168
- subscriptionId={subscriptionId}
169
- authToken={token}
170
- onResumed={(subscription) => {
171
- console.log('Subscription resumed securely:', subscription.id);
172
- }}
173
- />
160
+ <Card>
161
+ <CardContent>
162
+ <Typography variant="h5">Manage Your Subscription</Typography>
163
+ <Typography color="text.secondary">Status: {subscription.status}</Typography>
164
+
165
+ {subscription.status === 'canceled' && (
166
+ <Button
167
+ variant="contained"
168
+ color="primary"
169
+ sx={{ mt: 2 }}
170
+ onClick={() => setIsResumeOpen(true)}>
171
+ Resume Subscription
172
+ </Button>
173
+ )}
174
+ </CardContent>
175
+ </Card>
176
+
177
+ {isResumeOpen && (
178
+ <ResumeSubscription
179
+ subscriptionId={subscription.id}
180
+ onResumed={handleResumed}
181
+ dialogProps={{
182
+ open: isResumeOpen,
183
+ onClose: () => setIsResumeOpen(false),
184
+ }}
185
+ />
186
+ )}
174
187
  </PaymentProvider>
175
188
  );
176
189
  }
@@ -1,45 +1,21 @@
1
1
  # Business Logic Components
2
2
 
3
- Business logic components are specialized React components designed to handle complex, high-level user flows related to subscription and invoice management. These components encapsulate API calls, state management, and user interactions for common scenarios, allowing you to integrate sophisticated features with minimal effort.
3
+ Business Logic Components are specialized React components designed to handle complex, stateful operations related to subscription and invoice management. These components encapsulate entire user flows, such as paying overdue invoices or resuming a canceled subscription, making it easy to integrate advanced functionalities into your application with minimal setup.
4
4
 
5
- These components are ready to be integrated into your application to address specific business needs, such as recovering revenue from failed payments or improving user retention.
5
+ They are built on top of the core library features and often interact with the Payment Service API to perform actions and reflect state changes.
6
6
 
7
- ```d2
8
- direction: down
9
-
10
- "User Application": {
11
- shape: cloud
12
- }
13
-
14
- "Business Logic Components": {
15
- shape: package
16
- "OverdueInvoicePayment"
17
- "ResumeSubscription"
18
- "Auto-Topup Components"
19
- }
20
-
21
- "Payment Service API": {
22
- shape: database
23
- }
24
-
25
- "User Application" -> "Business Logic Components": "Integrates"
26
- "Business Logic Components.OverdueInvoicePayment" -> "Payment Service API": "Pays for overdue invoices"
27
- "Business Logic Components.ResumeSubscription" -> "Payment Service API": "Reactivates subscription"
28
- "Business Logic Components.Auto-Topup Components" -> "Payment Service API": "Configures auto-recharge"
29
- ```
30
-
31
- This section provides an overview of the available business logic components. For detailed API references and usage examples, select a component below.
32
-
33
- <x-cards data-columns="3">
34
- <x-card data-title="OverdueInvoicePayment" data-icon="lucide:alert-circle" data-href="/components/business/overdue-invoice-payment">
35
- A component that provides a complete UI flow for handling overdue invoices for a subscription or an entire customer account.
7
+ <x-cards data-columns="2">
8
+ <x-card data-title="OverdueInvoicePayment" data-icon="lucide:file-warning" data-href="/components/business/overdue-invoice-payment">
9
+ A component to handle the payment of overdue invoices for a specific customer or subscription, presenting a dialog with payment options.
36
10
  </x-card>
37
- <x-card data-title="ResumeSubscription" data-icon="lucide:refresh-cw" data-href="/components/business/resume-subscription">
38
- A component that facilitates resuming a previously canceled subscription, including handling complex scenarios like re-staking.
11
+ <x-card data-title="ResumeSubscription" data-icon="lucide:play-circle" data-href="/components/business/resume-subscription">
12
+ Allows a user to resume a canceled subscription. It handles the necessary API calls and re-staking logic if required.
39
13
  </x-card>
40
- <x-card data-title="Auto-Topup Components" data-icon="lucide:battery-charging" data-href="/components/business/auto-topup">
41
- A set of components for managing automatic credit top-ups when a user's balance falls below a configured threshold.
14
+ <x-card data-title="Auto-Topup Components" data-icon="lucide:zap" data-href="/components/business/auto-topup">
15
+ A set of components for managing and configuring automatic credit top-ups, including a display card and a configuration modal.
42
16
  </x-card>
43
17
  </x-cards>
44
18
 
45
- After handling these business-specific tasks, you may want to display the results to the user. Proceed to the [History Components](./components-history.md) section to learn how to display lists of invoices, payments, and credit transactions.
19
+ ### Next Steps
20
+
21
+ After integrating these business logic components, you might want to display historical data to your users. Proceed to the [History Components](./components-history.md) section to learn how to list invoices, payments, and credit transactions.