@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,176 +1,189 @@
|
|
|
1
1
|
# ResumeSubscription
|
|
2
2
|
|
|
3
|
-
The `ResumeSubscription` component provides a
|
|
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
|
|
5
|
+
This component must be used within a `PaymentProvider` to access the necessary context for handling wallet interactions.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Workflow
|
|
8
8
|
|
|
9
|
-
The
|
|
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
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
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 ->
|
|
24
|
-
|
|
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
|
-
|
|
27
|
-
|
|
23
|
+
ResumeSubscription.t1 -> User: "4. Show confirmation dialog"
|
|
24
|
+
User -> ResumeSubscription.t1: "5. Confirm"
|
|
28
25
|
|
|
29
|
-
alt "
|
|
30
|
-
|
|
31
|
-
|
|
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 "
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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` |
|
|
51
|
-
| `onResumed` | `(
|
|
52
|
-
| `dialogProps` | `object` |
|
|
53
|
-
| `successToast` | `boolean` |
|
|
54
|
-
| `authToken` | `string` |
|
|
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
|
|
58
|
+
This is the simplest way to use the component. It will render an open dialog by default.
|
|
63
59
|
|
|
64
|
-
```tsx
|
|
65
|
-
import
|
|
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
|
-
|
|
69
|
-
//
|
|
70
|
-
|
|
63
|
+
function ResumePage({ subscriptionId }) {
|
|
64
|
+
// This component must be rendered within a PaymentProvider
|
|
65
|
+
return <ResumeSubscription subscriptionId={subscriptionId} />;
|
|
66
|
+
}
|
|
67
|
+
```
|
|
71
68
|
|
|
72
|
-
|
|
73
|
-
// session and connect are derived from your application's auth service.
|
|
74
|
-
const { session, connect } = useSessionContext();
|
|
69
|
+
### Handling the Result
|
|
75
70
|
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
<
|
|
87
|
+
<div>
|
|
88
|
+
{/* Display subscription details based on the `subscription` state */}
|
|
82
89
|
<ResumeSubscription
|
|
83
|
-
subscriptionId={
|
|
84
|
-
onResumed={
|
|
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
|
-
</
|
|
93
|
+
</div>
|
|
91
94
|
);
|
|
92
95
|
}
|
|
93
96
|
```
|
|
94
97
|
|
|
95
98
|
### Controlling the Dialog
|
|
96
99
|
|
|
97
|
-
|
|
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
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
import { useSessionContext } from '../hooks/use-session-context';
|
|
107
|
+
function SubscriptionActions({ subscriptionId }) {
|
|
108
|
+
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
107
109
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
122
|
-
<Button onClick={() =>
|
|
117
|
+
<>
|
|
118
|
+
<Button variant="contained" onClick={() => setIsModalOpen(true)}>
|
|
123
119
|
Resume Subscription
|
|
124
120
|
</Button>
|
|
125
121
|
|
|
126
|
-
{
|
|
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:
|
|
136
|
-
onClose: handleCloseDialog,
|
|
127
|
+
open: isModalOpen,
|
|
137
128
|
title: 'Confirm Subscription Renewal',
|
|
129
|
+
onClose: () => setIsModalOpen(false),
|
|
138
130
|
}}
|
|
139
131
|
/>
|
|
140
132
|
)}
|
|
141
|
-
|
|
133
|
+
</>
|
|
142
134
|
);
|
|
143
135
|
}
|
|
144
136
|
```
|
|
145
137
|
|
|
146
|
-
|
|
138
|
+
## Full Integration Example
|
|
147
139
|
|
|
148
|
-
|
|
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
|
-
|
|
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
|
-
|
|
162
|
-
|
|
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
|
-
<
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
8
|
-
|
|
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:
|
|
38
|
-
|
|
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:
|
|
41
|
-
A set of components for managing automatic credit top-ups
|
|
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
|
-
|
|
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.
|