@blocklet/payment-react 1.20.16 → 1.20.18
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 +7 -1
- package/.aigne/doc-smith/upload-cache.yaml +441 -0
- package/docs/components-business-auto-topup.ja.md +187 -0
- package/docs/components-business-auto-topup.zh-TW.md +187 -0
- package/docs/components-business-auto-topup.zh.md +187 -0
- package/docs/components-business-overdue-invoice-payment.ja.md +196 -0
- package/docs/components-business-overdue-invoice-payment.zh-TW.md +197 -0
- package/docs/components-business-overdue-invoice-payment.zh.md +197 -0
- package/docs/components-business-resume-subscription.ja.md +190 -0
- package/docs/components-business-resume-subscription.zh-TW.md +190 -0
- package/docs/components-business-resume-subscription.zh.md +190 -0
- package/docs/components-business.ja.md +21 -0
- package/docs/components-business.zh-TW.md +21 -0
- package/docs/components-business.zh.md +21 -0
- package/docs/components-checkout-checkout-donate.ja.md +259 -0
- package/docs/components-checkout-checkout-donate.zh-TW.md +259 -0
- package/docs/components-checkout-checkout-donate.zh.md +259 -0
- package/docs/components-checkout-checkout-form.ja.md +163 -0
- package/docs/components-checkout-checkout-form.zh-TW.md +163 -0
- package/docs/components-checkout-checkout-form.zh.md +163 -0
- package/docs/components-checkout-checkout-table.ja.md +148 -0
- package/docs/components-checkout-checkout-table.zh-TW.md +148 -0
- package/docs/components-checkout-checkout-table.zh.md +149 -0
- package/docs/components-checkout.ja.md +65 -0
- package/docs/components-checkout.zh-TW.md +65 -0
- package/docs/components-checkout.zh.md +65 -0
- package/docs/components-history-credit-grants-list.ja.md +73 -0
- package/docs/components-history-credit-grants-list.zh-TW.md +73 -0
- package/docs/components-history-credit-grants-list.zh.md +73 -0
- package/docs/components-history-credit-transactions-list.ja.md +106 -0
- package/docs/components-history-credit-transactions-list.zh-TW.md +106 -0
- package/docs/components-history-credit-transactions-list.zh.md +106 -0
- package/docs/components-history-invoice-list.ja.md +110 -0
- package/docs/components-history-invoice-list.zh-TW.md +110 -0
- package/docs/components-history-invoice-list.zh.md +110 -0
- package/docs/components-history-payment-list.ja.md +44 -0
- package/docs/components-history-payment-list.zh-TW.md +44 -0
- package/docs/components-history-payment-list.zh.md +44 -0
- package/docs/components-history.ja.md +67 -0
- package/docs/components-history.zh-TW.md +67 -0
- package/docs/components-history.zh.md +67 -0
- package/docs/components-ui-form-elements-address-form.ja.md +121 -0
- package/docs/components-ui-form-elements-address-form.zh-TW.md +121 -0
- package/docs/components-ui-form-elements-address-form.zh.md +121 -0
- package/docs/components-ui-form-elements-country-select.ja.md +126 -0
- package/docs/components-ui-form-elements-country-select.zh-TW.md +126 -0
- package/docs/components-ui-form-elements-country-select.zh.md +126 -0
- package/docs/components-ui-form-elements-currency-selector.ja.md +108 -0
- package/docs/components-ui-form-elements-currency-selector.zh-TW.md +108 -0
- package/docs/components-ui-form-elements-currency-selector.zh.md +108 -0
- package/docs/components-ui-form-elements-phone-input.ja.md +138 -0
- package/docs/components-ui-form-elements-phone-input.zh-TW.md +138 -0
- package/docs/components-ui-form-elements-phone-input.zh.md +139 -0
- package/docs/components-ui-form-elements.ja.md +91 -0
- package/docs/components-ui-form-elements.zh-TW.md +91 -0
- package/docs/components-ui-form-elements.zh.md +91 -0
- package/docs/components-ui-payment-summary.ja.md +109 -0
- package/docs/components-ui-payment-summary.zh-TW.md +109 -0
- package/docs/components-ui-payment-summary.zh.md +109 -0
- package/docs/components-ui-pricing-table.ja.md +140 -0
- package/docs/components-ui-pricing-table.zh-TW.md +140 -0
- package/docs/components-ui-pricing-table.zh.md +140 -0
- package/docs/components-ui.ja.md +71 -0
- package/docs/components-ui.zh-TW.md +71 -0
- package/docs/components-ui.zh.md +71 -0
- package/docs/components.ja.md +122 -0
- package/docs/components.zh-TW.md +122 -0
- package/docs/components.zh.md +122 -0
- package/docs/getting-started.ja.md +84 -0
- package/docs/getting-started.zh-TW.md +84 -0
- package/docs/getting-started.zh.md +84 -0
- package/docs/guides-theming.ja.md +213 -0
- package/docs/guides-theming.zh-TW.md +213 -0
- package/docs/guides-theming.zh.md +213 -0
- package/docs/guides-utilities.ja.md +197 -0
- package/docs/guides-utilities.zh-TW.md +197 -0
- package/docs/guides-utilities.zh.md +197 -0
- package/docs/guides.ja.md +18 -0
- package/docs/guides.zh-TW.md +18 -0
- package/docs/guides.zh.md +18 -0
- package/docs/hooks-use-mobile.ja.md +84 -0
- package/docs/hooks-use-mobile.zh-TW.md +84 -0
- package/docs/hooks-use-mobile.zh.md +84 -0
- package/docs/hooks-use-subscription.ja.md +111 -0
- package/docs/hooks-use-subscription.zh-TW.md +111 -0
- package/docs/hooks-use-subscription.zh.md +110 -0
- package/docs/hooks.ja.md +14 -0
- package/docs/hooks.zh-TW.md +14 -0
- package/docs/hooks.zh.md +14 -0
- package/docs/overview.ja.md +80 -0
- package/docs/overview.zh-TW.md +80 -0
- package/docs/overview.zh.md +80 -0
- package/docs/providers-donate-provider.ja.md +153 -0
- package/docs/providers-donate-provider.zh-TW.md +153 -0
- package/docs/providers-donate-provider.zh.md +153 -0
- package/docs/providers-payment-provider.ja.md +191 -0
- package/docs/providers-payment-provider.zh-TW.md +191 -0
- package/docs/providers-payment-provider.zh.md +191 -0
- package/docs/providers.ja.md +42 -0
- package/docs/providers.zh-TW.md +42 -0
- package/docs/providers.zh.md +42 -0
- package/package.json +3 -3
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# ResumeSubscription
|
|
2
|
+
|
|
3
|
+
`ResumeSubscription` 元件為使用者提供了一個簡單明瞭的使用者介面,以便恢復已取消的訂閱。它會渲染一個對話方塊,引導使用者完成確認過程,並在訂閱需要時自動處理重新質押等複雜情境。
|
|
4
|
+
|
|
5
|
+
此元件必須在 `PaymentProvider` 中使用,才能存取處理錢包互動所需的必要上下文。
|
|
6
|
+
|
|
7
|
+
## 工作流程
|
|
8
|
+
|
|
9
|
+
下圖說明了使用者恢復訂閱時的流程,包括重新質押的條件邏輯。
|
|
10
|
+
|
|
11
|
+
```d2
|
|
12
|
+
shape: sequence_diagram
|
|
13
|
+
|
|
14
|
+
User: { shape: c4-person }
|
|
15
|
+
ResumeSubscription: { label: "ResumeSubscription 元件" }
|
|
16
|
+
PaymentAPI: { label: "Payment API" }
|
|
17
|
+
DIDWallet: { label: "DID 錢包" }
|
|
18
|
+
|
|
19
|
+
User -> ResumeSubscription: "1. 觸發恢復"
|
|
20
|
+
ResumeSubscription -> PaymentAPI: "2. GET /recover-info"
|
|
21
|
+
PaymentAPI -> ResumeSubscription: "3. 返回狀態\n(例如:needStake: true)"
|
|
22
|
+
|
|
23
|
+
ResumeSubscription.t1 -> User: "4. 顯示確認對話方塊"
|
|
24
|
+
User -> ResumeSubscription.t1: "5. 確認"
|
|
25
|
+
|
|
26
|
+
alt "需要重新質押" {
|
|
27
|
+
ResumeSubscription.t1 -> DIDWallet: "6a. 開啟重新質押會話"
|
|
28
|
+
User -> DIDWallet: "7a. 批准"
|
|
29
|
+
DIDWallet -> ResumeSubscription.t1: "8a. 成功回呼"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
alt "無需質押" {
|
|
33
|
+
ResumeSubscription.t1 -> PaymentAPI: "6b. PUT /recover"
|
|
34
|
+
PaymentAPI -> ResumeSubscription.t1: "7b. 成功"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
ResumeSubscription.t1 -> PaymentAPI: "9. 取得更新後的訂閱"
|
|
38
|
+
PaymentAPI -> ResumeSubscription.t1: "10. 返回訂閱"
|
|
39
|
+
ResumeSubscription.t1 -> User: "11. 呼叫 onResumed() 並關閉對話方塊"
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## Props
|
|
45
|
+
|
|
46
|
+
| Prop | Type | Required | Description |
|
|
47
|
+
| ---------------- | -------------------------------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
48
|
+
| `subscriptionId` | `string` | 是 | 要恢復的訂閱的唯一識別碼。 |
|
|
49
|
+
| `onResumed` | `(subscription: Subscription) => void` | 否 | 訂閱成功恢復後觸發的回呼函式。它會收到更新後的訂閱物件作為參數。 |
|
|
50
|
+
| `dialogProps` | `object` | 否 | 用於自訂底層 Material-UI Dialog 的 props。您可以控制其狀態(`open`、`onClose`)和外觀(`title`)。 |
|
|
51
|
+
| `successToast` | `boolean` | 否 | 如果為 `true`,成功恢復後會顯示成功通知吐司。預設為 `true`。 |
|
|
52
|
+
| `authToken` | `string` | 否 | 用於 API 請求的可選身份驗證權杖。這對於跨來源或伺服器到伺服器的整合場景很有用。 |
|
|
53
|
+
|
|
54
|
+
## 使用範例
|
|
55
|
+
|
|
56
|
+
### 基本用法
|
|
57
|
+
|
|
58
|
+
這是使用該元件最簡單的方法。預設情況下,它會渲染一個開啟的對話方塊。
|
|
59
|
+
|
|
60
|
+
```tsx Basic ResumeSubscription Example icon=logos:react
|
|
61
|
+
import { ResumeSubscription } from '@blocklet/payment-react';
|
|
62
|
+
|
|
63
|
+
function ResumePage({ subscriptionId }) {
|
|
64
|
+
// 此元件必須在 PaymentProvider 內渲染
|
|
65
|
+
return <ResumeSubscription subscriptionId={subscriptionId} />;
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 處理結果
|
|
70
|
+
|
|
71
|
+
使用 `onResumed` 回呼來接收更新後的訂閱資料並刷新您的應用程式狀態。
|
|
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('訂閱已成功恢復:', updatedSubscription);
|
|
82
|
+
setSubscription(updatedSubscription);
|
|
83
|
+
// 您也可以顯示確認訊息或將使用者重新導向。
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<div>
|
|
88
|
+
{/* 根據 `subscription` 狀態顯示訂閱詳情 */}
|
|
89
|
+
<ResumeSubscription
|
|
90
|
+
subscriptionId={subscription.id}
|
|
91
|
+
onResumed={handleSubscriptionResumed}
|
|
92
|
+
/>
|
|
93
|
+
</div>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 控制對話方塊
|
|
99
|
+
|
|
100
|
+
為了更實用的整合,請從父元件控制對話方塊的可見性。這讓您可以響應使用者操作(例如點擊按鈕)來開啟它。
|
|
101
|
+
|
|
102
|
+
```tsx Triggering ResumeSubscription with a Button icon=logos:react
|
|
103
|
+
import { ResumeSubscription } from '@blocklet/payment-react';
|
|
104
|
+
import { useState } from 'react';
|
|
105
|
+
import { Button } from '@mui/material';
|
|
106
|
+
|
|
107
|
+
function SubscriptionActions({ subscriptionId }) {
|
|
108
|
+
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
109
|
+
|
|
110
|
+
const handleResumed = () => {
|
|
111
|
+
setIsModalOpen(false);
|
|
112
|
+
// 重新取得訂閱資料以更新 UI
|
|
113
|
+
alert('訂閱已恢復!');
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<>
|
|
118
|
+
<Button variant="contained" onClick={() => setIsModalOpen(true)}>
|
|
119
|
+
恢復訂閱
|
|
120
|
+
</Button>
|
|
121
|
+
|
|
122
|
+
{isModalOpen && (
|
|
123
|
+
<ResumeSubscription
|
|
124
|
+
subscriptionId={subscriptionId}
|
|
125
|
+
onResumed={handleResumed}
|
|
126
|
+
dialogProps={{
|
|
127
|
+
open: isModalOpen,
|
|
128
|
+
title: '確認續訂',
|
|
129
|
+
onClose: () => setIsModalOpen(false),
|
|
130
|
+
}}
|
|
131
|
+
/>
|
|
132
|
+
)}
|
|
133
|
+
</>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## 完整整合範例
|
|
139
|
+
|
|
140
|
+
這是一個完整的範例,展示如何在必要的 `PaymentProvider` 中整合 `ResumeSubscription`。
|
|
141
|
+
|
|
142
|
+
```tsx Complete Integration Example icon=logos:react
|
|
143
|
+
import { PaymentProvider, ResumeSubscription } from '@blocklet/payment-react';
|
|
144
|
+
import { useSessionContext } from 'path/to/your/session/context'; // 您的應用程式的 session context
|
|
145
|
+
import { useState } from 'react';
|
|
146
|
+
import { Button, Card, CardContent, Typography } from '@mui/material';
|
|
147
|
+
|
|
148
|
+
function SubscriptionManagementPage({ subscription }) {
|
|
149
|
+
const { session, connect } = useSessionContext();
|
|
150
|
+
const [isResumeOpen, setIsResumeOpen] = useState(false);
|
|
151
|
+
|
|
152
|
+
const handleResumed = (updatedSubscription) => {
|
|
153
|
+
console.log('訂閱已更新:', updatedSubscription);
|
|
154
|
+
setIsResumeOpen(false);
|
|
155
|
+
// 理想情況下,您會在此處觸發資料重新取得來更新整個頁面。
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<PaymentProvider session={session} connect={connect}>
|
|
160
|
+
<Card>
|
|
161
|
+
<CardContent>
|
|
162
|
+
<Typography variant="h5">管理您的訂閱</Typography>
|
|
163
|
+
<Typography color="text.secondary">狀態:{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
|
+
恢復訂閱
|
|
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
|
+
)}
|
|
187
|
+
</PaymentProvider>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
```
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# ResumeSubscription
|
|
2
|
+
|
|
3
|
+
`ResumeSubscription` 组件为用户提供了一个简单的 UI,用于恢复已取消的订阅。它会渲染一个对话框,引导用户完成确认过程,并自动处理需要重新质押等复杂场景。
|
|
4
|
+
|
|
5
|
+
该组件必须在 `PaymentProvider` 内部使用,以访问处理钱包交互所需的上下文。
|
|
6
|
+
|
|
7
|
+
## 工作流程
|
|
8
|
+
|
|
9
|
+
下图说明了用户恢复订阅时的流程,包括重新质押的条件逻辑。
|
|
10
|
+
|
|
11
|
+
```d2
|
|
12
|
+
shape: sequence_diagram
|
|
13
|
+
|
|
14
|
+
User: { shape: c4-person }
|
|
15
|
+
ResumeSubscription: { label: "ResumeSubscription 组件" }
|
|
16
|
+
PaymentAPI: { label: "Payment API" }
|
|
17
|
+
DIDWallet: { label: "DID Wallet" }
|
|
18
|
+
|
|
19
|
+
User -> ResumeSubscription: "1. 触发恢复"
|
|
20
|
+
ResumeSubscription -> PaymentAPI: "2. GET /recover-info"
|
|
21
|
+
PaymentAPI -> ResumeSubscription: "3. 返回状态\n(例如,needStake: true)"
|
|
22
|
+
|
|
23
|
+
ResumeSubscription.t1 -> User: "4. 显示确认对话框"
|
|
24
|
+
User -> ResumeSubscription.t1: "5. 确认"
|
|
25
|
+
|
|
26
|
+
alt "需要重新质押" {
|
|
27
|
+
ResumeSubscription.t1 -> DIDWallet: "6a. 打开重新质押会话"
|
|
28
|
+
User -> DIDWallet: "7a. 批准"
|
|
29
|
+
DIDWallet -> ResumeSubscription.t1: "8a. 成功回调"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
alt "无需质押" {
|
|
33
|
+
ResumeSubscription.t1 -> PaymentAPI: "6b. PUT /recover"
|
|
34
|
+
PaymentAPI -> ResumeSubscription.t1: "7b. 成功"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
ResumeSubscription.t1 -> PaymentAPI: "9. 获取更新后的订阅"
|
|
38
|
+
PaymentAPI -> ResumeSubscription.t1: "10. 返回订阅"
|
|
39
|
+
ResumeSubscription.t1 -> User: "11. 调用 onResumed() 并关闭对话框"
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## Props
|
|
45
|
+
|
|
46
|
+
| Prop | Type | Required | Description |
|
|
47
|
+
| ---------------- | -------------------------------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
48
|
+
| `subscriptionId` | `string` | Yes | 要恢复的订阅的唯一标识符。 |
|
|
49
|
+
| `onResumed` | `(subscription: Subscription) => void` | No | 订阅成功恢复后触发的回调函数。它会接收更新后的订阅对象作为参数。 |
|
|
50
|
+
| `dialogProps` | `object` | No | 用于自定义底层 Material-UI Dialog 的 Props。您可以控制其状态(`open`、`onClose`)和外观(`title`)。 |
|
|
51
|
+
| `successToast` | `boolean` | No | 如果为 `true`,则在成功恢复时显示成功通知 toast。默认为 `true`。 |
|
|
52
|
+
| `authToken` | `string` | No | 用于 API 请求的可选身份验证令牌。这对于跨域或服务器到服务器的集成场景很有用。 |
|
|
53
|
+
|
|
54
|
+
## 使用示例
|
|
55
|
+
|
|
56
|
+
### 基本用法
|
|
57
|
+
|
|
58
|
+
这是使用该组件最简单的方式。默认情况下,它将渲染一个打开的对话框。
|
|
59
|
+
|
|
60
|
+
```tsx Basic ResumeSubscription Example icon=logos:react
|
|
61
|
+
import { ResumeSubscription } from '@blocklet/payment-react';
|
|
62
|
+
|
|
63
|
+
function ResumePage({ subscriptionId }) {
|
|
64
|
+
// 该组件必须在 PaymentProvider 内部渲染
|
|
65
|
+
return <ResumeSubscription subscriptionId={subscriptionId} />;
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 处理结果
|
|
70
|
+
|
|
71
|
+
使用 `onResumed` 回调接收更新后的订阅数据并刷新您的应用程序状态。
|
|
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('订阅已成功恢复:', updatedSubscription);
|
|
82
|
+
setSubscription(updatedSubscription);
|
|
83
|
+
// 您还可以显示确认消息或重定向用户。
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<div>
|
|
88
|
+
{/* 根据 `subscription` 状态显示订阅详情 */}
|
|
89
|
+
<ResumeSubscription
|
|
90
|
+
subscriptionId={subscription.id}
|
|
91
|
+
onResumed={handleSubscriptionResumed}
|
|
92
|
+
/>
|
|
93
|
+
</div>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 控制对话框
|
|
99
|
+
|
|
100
|
+
为了更实用的集成,可以从父组件控制对话框的可见性。这允许您响应用户操作(如点击按钮)来打开它。
|
|
101
|
+
|
|
102
|
+
```tsx Triggering ResumeSubscription with a Button icon=logos:react
|
|
103
|
+
import { ResumeSubscription } from '@blocklet/payment-react';
|
|
104
|
+
import { useState } from 'react';
|
|
105
|
+
import { Button } from '@mui/material';
|
|
106
|
+
|
|
107
|
+
function SubscriptionActions({ subscriptionId }) {
|
|
108
|
+
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
109
|
+
|
|
110
|
+
const handleResumed = () => {
|
|
111
|
+
setIsModalOpen(false);
|
|
112
|
+
// 重新获取订阅数据以更新 UI
|
|
113
|
+
alert('订阅已恢复!');
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<>
|
|
118
|
+
<Button variant="contained" onClick={() => setIsModalOpen(true)}>
|
|
119
|
+
恢复订阅
|
|
120
|
+
</Button>
|
|
121
|
+
|
|
122
|
+
{isModalOpen && (
|
|
123
|
+
<ResumeSubscription
|
|
124
|
+
subscriptionId={subscriptionId}
|
|
125
|
+
onResumed={handleResumed}
|
|
126
|
+
dialogProps={{
|
|
127
|
+
open: isModalOpen,
|
|
128
|
+
title: '确认续订',
|
|
129
|
+
onClose: () => setIsModalOpen(false),
|
|
130
|
+
}}
|
|
131
|
+
/>
|
|
132
|
+
)}
|
|
133
|
+
</>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## 完整集成示例
|
|
139
|
+
|
|
140
|
+
这是一个完整的示例,展示了如何在所需的 `PaymentProvider` 中集成 `ResumeSubscription`。
|
|
141
|
+
|
|
142
|
+
```tsx Complete Integration Example icon=logos:react
|
|
143
|
+
import { PaymentProvider, ResumeSubscription } from '@blocklet/payment-react';
|
|
144
|
+
import { useSessionContext } from 'path/to/your/session/context'; // 您的应用的会话上下文
|
|
145
|
+
import { useState } from 'react';
|
|
146
|
+
import { Button, Card, CardContent, Typography } from '@mui/material';
|
|
147
|
+
|
|
148
|
+
function SubscriptionManagementPage({ subscription }) {
|
|
149
|
+
const { session, connect } = useSessionContext();
|
|
150
|
+
const [isResumeOpen, setIsResumeOpen] = useState(false);
|
|
151
|
+
|
|
152
|
+
const handleResumed = (updatedSubscription) => {
|
|
153
|
+
console.log('订阅已更新:', updatedSubscription);
|
|
154
|
+
setIsResumeOpen(false);
|
|
155
|
+
// 理想情况下,您应在此处触发数据重新获取以更新整个页面。
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<PaymentProvider session={session} connect={connect}>
|
|
160
|
+
<Card>
|
|
161
|
+
<CardContent>
|
|
162
|
+
<Typography variant="h5">管理您的订阅</Typography>
|
|
163
|
+
<Typography color="text.secondary">状态: {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
|
+
恢复订阅
|
|
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
|
+
)}
|
|
187
|
+
</PaymentProvider>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# ビジネスロジックコンポーネント
|
|
2
|
+
|
|
3
|
+
ビジネスロジックコンポーネントは、サブスクリプションと請求書管理に関連する複雑でステートフルな操作を処理するために設計された、特殊なReactコンポーネントです。これらのコンポーネントは、延滞請求書の支払いやキャンセルされたサブスクリプションの再開など、ユーザーフロー全体をカプセル化し、最小限のセットアップで高度な機能をアプリケーションに簡単に統合できるようにします。
|
|
4
|
+
|
|
5
|
+
これらはコアライブラリの機能を基盤に構築されており、多くの場合、支払いサービスAPIと対話してアクションを実行し、状態の変更を反映します。
|
|
6
|
+
|
|
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
|
+
特定の顧客またはサブスクリプションの延滞請求書の支払いを処理するコンポーネントで、支払いオプション付きのダイアログを表示します。
|
|
10
|
+
</x-card>
|
|
11
|
+
<x-card data-title="ResumeSubscription" data-icon="lucide:play-circle" data-href="/components/business/resume-subscription">
|
|
12
|
+
ユーザーがキャンセルされたサブスクリプションを再開できるようにします。必要に応じて、必要なAPI呼び出しと再ステーキングロジックを処理します。
|
|
13
|
+
</x-card>
|
|
14
|
+
<x-card data-title="Auto-Topup Components" data-icon="lucide:zap" data-href="/components/business/auto-topup">
|
|
15
|
+
表示カードや設定モーダルを含む、自動クレジットトップアップを管理および設定するための一連のコンポーネントです。
|
|
16
|
+
</x-card>
|
|
17
|
+
</x-cards>
|
|
18
|
+
|
|
19
|
+
### 次のステップ
|
|
20
|
+
|
|
21
|
+
これらのビジネスロジックコンポーネントを統合した後、ユーザーに履歴データを表示したい場合があるでしょう。[履歴コンポーネント](./components-history.md)セクションに進み、請求書、支払い、およびクレジットトランザクションを一覧表示する方法を学びましょう。
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# 業務邏輯元件
|
|
2
|
+
|
|
3
|
+
業務邏輯元件是專為處理訂閱和發票管理相關的複雜、具狀態性操作而設計的特殊 React 元件。這些元件封裝了完整的用戶流程,例如支付逾期發票或恢復已取消的訂閱,讓您能以最少的設定輕鬆地將進階功能整合至您的應用程式中。
|
|
4
|
+
|
|
5
|
+
它們建立在核心函式庫功能的基礎上,並經常與支付服務 API 互動以執行操作並反映狀態變更。
|
|
6
|
+
|
|
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
|
+
一個用於處理特定客戶或訂閱的逾期發票支付的元件,會呈現一個帶有付款選項的對話方塊。
|
|
10
|
+
</x-card>
|
|
11
|
+
<x-card data-title="ResumeSubscription" data-icon="lucide:play-circle" data-href="/components/business/resume-subscription">
|
|
12
|
+
允許用戶恢復已取消的訂閱。它會處理必要的 API 呼叫,並在需要時處理重新質押的邏輯。
|
|
13
|
+
</x-card>
|
|
14
|
+
<x-card data-title="Auto-Topup Components" data-icon="lucide:zap" data-href="/components/business/auto-topup">
|
|
15
|
+
一組用於管理和設定自動點數儲值的元件,包含一個顯示卡片和一個設定彈出視窗。
|
|
16
|
+
</x-card>
|
|
17
|
+
</x-cards>
|
|
18
|
+
|
|
19
|
+
### 後續步驟
|
|
20
|
+
|
|
21
|
+
整合這些業務邏輯元件後,您可能會想向用戶顯示歷史資料。請前往 [歷史元件](./components-history.md) 章節,以了解如何列出發票、付款和點數交易。
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# 业务逻辑组件
|
|
2
|
+
|
|
3
|
+
业务逻辑组件是专门设计的 React 组件,用于处理与订阅和发票管理相关的复杂、有状态的操作。这些组件封装了完整的用户流程,例如支付逾期发票或恢复已取消的订阅,让您可以通过最少的设置轻松地将高级功能集成到您的应用程序中。
|
|
4
|
+
|
|
5
|
+
它们基于核心库功能构建,并经常与支付服务 API 交互以执行操作并反映状态变化。
|
|
6
|
+
|
|
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
|
+
一个用于处理特定客户或订阅的逾期发票支付的组件,会呈现一个带有支付选项的对话框。
|
|
10
|
+
</x-card>
|
|
11
|
+
<x-card data-title="ResumeSubscription" data-icon="lucide:play-circle" data-href="/components/business/resume-subscription">
|
|
12
|
+
允许用户恢复已取消的订阅。如果需要,它会处理必要的 API 调用和重新质押逻辑。
|
|
13
|
+
</x-card>
|
|
14
|
+
<x-card data-title="自动充值组件" data-icon="lucide:zap" data-href="/components/business/auto-topup">
|
|
15
|
+
一组用于管理和配置自动信用额度充值的组件,包括一个显示卡和一个配置模态框。
|
|
16
|
+
</x-card>
|
|
17
|
+
</x-cards>
|
|
18
|
+
|
|
19
|
+
### 后续步骤
|
|
20
|
+
|
|
21
|
+
集成这些业务逻辑组件后,您可能希望向用户显示历史数据。请继续阅读 [历史组件](./components-history.md) 部分,以了解如何列出发票、付款和信用交易。
|