@blocklet/payment-react 1.23.0 → 1.23.1
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/translation-cache.yaml +2 -2
- package/.aigne/doc-smith/upload-cache.yaml +342 -0
- package/docs/assets/diagram/auto-topup-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/auto-topup-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/auto-topup-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/components-business-overdue-invoice-payment-01.ja.jpg +0 -0
- package/docs/assets/diagram/components-business-overdue-invoice-payment-01.jpg +0 -0
- package/docs/assets/diagram/components-business-overdue-invoice-payment-01.zh-TW.jpg +0 -0
- package/docs/assets/diagram/components-business-overdue-invoice-payment-01.zh.jpg +0 -0
- package/docs/assets/diagram/components-checkout-checkout-donate-01.ja.jpg +0 -0
- package/docs/assets/diagram/components-checkout-checkout-donate-01.jpg +0 -0
- package/docs/assets/diagram/components-checkout-checkout-donate-01.zh-TW.jpg +0 -0
- package/docs/assets/diagram/components-checkout-checkout-donate-01.zh.jpg +0 -0
- package/docs/assets/diagram/components-checkout-checkout-table-01.ja.jpg +0 -0
- package/docs/assets/diagram/components-checkout-checkout-table-01.jpg +0 -0
- package/docs/assets/diagram/components-checkout-checkout-table-01.zh-TW.jpg +0 -0
- package/docs/assets/diagram/components-checkout-checkout-table-01.zh.jpg +0 -0
- package/docs/assets/diagram/components-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/components-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/components-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/overview-01.ja.jpg +0 -0
- package/docs/assets/diagram/overview-01.jpg +0 -0
- package/docs/assets/diagram/overview-01.zh-TW.jpg +0 -0
- package/docs/assets/diagram/overview-01.zh.jpg +0 -0
- package/docs/assets/diagram/payment-provider-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/payment-provider-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/payment-provider-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/phone-input-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/phone-input-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/phone-input-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/providers-01.ja.jpg +0 -0
- package/docs/assets/diagram/providers-01.jpg +0 -0
- package/docs/assets/diagram/providers-01.zh-TW.jpg +0 -0
- package/docs/assets/diagram/providers-01.zh.jpg +0 -0
- package/docs/assets/diagram/resume-subscription-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/resume-subscription-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/resume-subscription-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/use-subscription-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/use-subscription-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/use-subscription-diagram-0.zh.jpg +0 -0
- package/docs/components-business-auto-topup.ja.md +2 -2
- package/docs/components-business-auto-topup.md +1 -1
- package/docs/components-business-auto-topup.zh-TW.md +2 -2
- package/docs/components-business-auto-topup.zh.md +2 -2
- package/docs/components-business-overdue-invoice-payment.ja.md +3 -39
- package/docs/components-business-overdue-invoice-payment.md +99 -90
- package/docs/components-business-overdue-invoice-payment.zh-TW.md +3 -40
- package/docs/components-business-overdue-invoice-payment.zh.md +3 -40
- package/docs/components-business-resume-subscription.ja.md +2 -2
- package/docs/components-business-resume-subscription.md +1 -1
- package/docs/components-business-resume-subscription.zh-TW.md +2 -2
- package/docs/components-business-resume-subscription.zh.md +2 -2
- package/docs/components-checkout-checkout-donate.ja.md +3 -36
- package/docs/components-checkout-checkout-donate.md +135 -128
- package/docs/components-checkout-checkout-donate.zh-TW.md +3 -36
- package/docs/components-checkout-checkout-donate.zh.md +3 -36
- package/docs/components-checkout-checkout-form.md +63 -82
- package/docs/components-checkout-checkout-table.ja.md +3 -35
- package/docs/components-checkout-checkout-table.md +112 -72
- package/docs/components-checkout-checkout-table.zh-TW.md +3 -35
- package/docs/components-checkout-checkout-table.zh.md +3 -36
- package/docs/components-checkout.md +11 -49
- package/docs/components-ui-form-elements-phone-input.ja.md +2 -2
- package/docs/components-ui-form-elements-phone-input.md +1 -1
- package/docs/components-ui-form-elements-phone-input.zh-TW.md +2 -2
- package/docs/components-ui-form-elements-phone-input.zh.md +2 -2
- package/docs/components.ja.md +2 -2
- package/docs/components.md +1 -1
- package/docs/components.zh-TW.md +2 -2
- package/docs/components.zh.md +2 -2
- package/docs/hooks-use-subscription.ja.md +2 -2
- package/docs/hooks-use-subscription.md +1 -1
- package/docs/hooks-use-subscription.zh-TW.md +2 -2
- package/docs/hooks-use-subscription.zh.md +2 -2
- package/docs/overview.ja.md +3 -39
- package/docs/overview.md +25 -56
- package/docs/overview.zh-TW.md +3 -39
- package/docs/overview.zh.md +3 -39
- package/docs/providers-payment-provider.ja.md +2 -2
- package/docs/providers-payment-provider.md +1 -1
- package/docs/providers-payment-provider.zh-TW.md +2 -2
- package/docs/providers-payment-provider.zh.md +2 -2
- package/docs/providers.ja.md +3 -23
- package/docs/providers.md +11 -29
- package/docs/providers.zh-TW.md +3 -23
- package/docs/providers.zh.md +3 -23
- package/es/history/credit/transactions-list.js +31 -49
- package/es/locales/en.js +16 -0
- package/es/locales/zh.js +16 -0
- package/lib/history/credit/transactions-list.js +63 -66
- package/lib/locales/en.js +16 -0
- package/lib/locales/zh.js +16 -0
- package/package.json +3 -3
- package/src/history/credit/transactions-list.tsx +54 -64
- package/src/locales/en.tsx +16 -0
- package/src/locales/zh.tsx +16 -0
|
@@ -1,95 +1,55 @@
|
|
|
1
1
|
# CheckoutDonate
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This document provides a detailed guide to implementing the `CheckoutDonate` component, a flexible solution for adding donation functionality to your application. By following these steps, you will learn how to configure the component, set up the required providers, and utilize its various display modes to create a seamless donation experience.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The `CheckoutDonate` component is designed to be highly customizable, supporting everything from a simple donation button to a fully bespoke user interface. It must be wrapped within both a `PaymentProvider` and a `DonateProvider` to manage state and connect to the payment backend.
|
|
6
6
|
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
The donation flow is orchestrated by a combination of `DonateProvider` and `CheckoutDonate`. Here's a high-level overview:
|
|
10
|
-
|
|
11
|
-
```d2 How It Works icon=graph-ql:diagram
|
|
12
|
-
direction: down
|
|
13
|
-
|
|
14
|
-
user: {
|
|
15
|
-
shape: c4-person
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
app: {
|
|
19
|
-
label: "Your React App"
|
|
20
|
-
|
|
21
|
-
checkout-donate: {
|
|
22
|
-
label: "CheckoutDonate"
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
checkout-form: {
|
|
26
|
-
label: "CheckoutForm (in Dialog)"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
payment-api: {
|
|
31
|
-
label: "Payment Backend API"
|
|
32
|
-
shape: cylinder
|
|
33
|
-
}
|
|
7
|
+
## Provider Setup
|
|
34
8
|
|
|
35
|
-
|
|
36
|
-
app.checkout-donate -> payment-api: "Fetches settings & supporters"
|
|
37
|
-
|
|
38
|
-
# Donation Flow
|
|
39
|
-
user -> app.checkout-donate: "1. Clicks Donate"
|
|
40
|
-
app.checkout-donate -> app.checkout-form: "2. Opens Dialog with CheckoutForm"
|
|
41
|
-
app.checkout-form -> payment-api: "3. Processes Payment"
|
|
42
|
-
payment-api -> app.checkout-form: "4. Returns Success"
|
|
43
|
-
app.checkout-form -> app.checkout-donate: "5. Triggers onPaid callback"
|
|
44
|
-
app.checkout-donate -> payment-api: "6. Refetches supporters list"
|
|
45
|
-
payment-api -> app.checkout-donate: "7. Returns updated supporters"
|
|
46
|
-
```
|
|
9
|
+
Correctly setting up the `PaymentProvider` and `DonateProvider` is a prerequisite for using `CheckoutDonate`. The `PaymentProvider` handles the connection to the payment service, while the `DonateProvider` manages the configuration and state for donation instances within a specific part of your application.
|
|
47
10
|
|
|
48
|
-
|
|
49
|
-
2. **Rendering**: `CheckoutDonate` renders a button or custom UI based on the retrieved settings and its props.
|
|
50
|
-
3. **Interaction**: When a user initiates a donation, `CheckoutDonate` opens a dialog containing a `CheckoutForm` pre-configured for the donation.
|
|
51
|
-
4. **Payment**: The user completes the payment through the `CheckoutForm`.
|
|
52
|
-
5. **Confirmation**: After a successful payment, the `onPaid` callback is triggered, and the component automatically refreshes the list of supporters.
|
|
11
|
+
The following diagram illustrates how these providers wrap the `CheckoutDonate` component and interact with the payment backend and your application's session context.
|
|
53
12
|
|
|
54
|
-
|
|
13
|
+
<!-- DIAGRAM_IMAGE_START:flowchart:4:3:1765377352 -->
|
|
14
|
+

|
|
15
|
+
<!-- DIAGRAM_IMAGE_END -->
|
|
55
16
|
|
|
56
|
-
|
|
17
|
+
The example below demonstrates the required provider structure. The `DonateProvider` is configured with a unique `mountLocation` to distinguish this donation context from others in your application.
|
|
57
18
|
|
|
58
|
-
```
|
|
19
|
+
```javascript ProviderSetup.jsx icon=logos:react
|
|
59
20
|
import {
|
|
60
21
|
PaymentProvider,
|
|
61
22
|
DonateProvider,
|
|
62
23
|
CheckoutDonate,
|
|
63
24
|
} from '@blocklet/payment-react';
|
|
64
|
-
import { useSessionContext } from '../hooks/session-context'; //
|
|
25
|
+
import { useSessionContext } from '../hooks/session-context'; // This is your app's session context hook
|
|
65
26
|
|
|
66
|
-
function
|
|
67
|
-
const { session,
|
|
27
|
+
function DonationSection() {
|
|
28
|
+
const { session, connectApi } = useSessionContext();
|
|
68
29
|
|
|
69
|
-
// Ensure session is loaded before rendering providers
|
|
70
30
|
if (!session) {
|
|
71
|
-
return <div>Loading...</div>;
|
|
31
|
+
return <div>Loading session...</div>;
|
|
72
32
|
}
|
|
73
33
|
|
|
74
34
|
return (
|
|
75
|
-
<PaymentProvider session={session}
|
|
35
|
+
<PaymentProvider session={session} connectApi={connectApi}>
|
|
76
36
|
<DonateProvider
|
|
77
|
-
mountLocation="
|
|
78
|
-
description="
|
|
37
|
+
mountLocation="blog-post-donations"
|
|
38
|
+
description="Handles all donations for blog posts"
|
|
79
39
|
defaultSettings={{
|
|
80
40
|
btnText: 'Support Me',
|
|
41
|
+
historyType: 'avatar',
|
|
81
42
|
}}>
|
|
82
|
-
|
|
83
|
-
<CheckoutDonate
|
|
43
|
+
<CheckoutDonate
|
|
84
44
|
settings={{
|
|
85
|
-
target:
|
|
86
|
-
title:
|
|
87
|
-
description:
|
|
88
|
-
reference:
|
|
45
|
+
target: 'post-123',
|
|
46
|
+
title: 'Support the Author',
|
|
47
|
+
description: 'If you found this article helpful, consider a small donation.',
|
|
48
|
+
reference: 'https://example.com/posts/123',
|
|
89
49
|
beneficiaries: [
|
|
90
50
|
{
|
|
91
|
-
address:
|
|
92
|
-
share:
|
|
51
|
+
address: 'z2qa...gCLd', // Author's DID address
|
|
52
|
+
share: '100',
|
|
93
53
|
},
|
|
94
54
|
],
|
|
95
55
|
}}
|
|
@@ -100,44 +60,87 @@ function DonationPage() {
|
|
|
100
60
|
}
|
|
101
61
|
```
|
|
102
62
|
|
|
103
|
-
For more
|
|
63
|
+
For a more in-depth explanation of its props and functionality, please refer to the [DonateProvider documentation](./providers-donate-provider.md).
|
|
104
64
|
|
|
105
65
|
## Component Props
|
|
106
66
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
67
|
+
The `CheckoutDonate` component accepts several props to control its behavior and appearance.
|
|
68
|
+
|
|
69
|
+
<x-field-group>
|
|
70
|
+
<x-field data-name="settings" data-type="CheckoutDonateSettings" data-required="true">
|
|
71
|
+
<x-field-desc markdown>Configuration object for this specific donation instance. See the `CheckoutDonateSettings` section below for details.</x-field-desc>
|
|
72
|
+
</x-field>
|
|
73
|
+
<x-field data-name="onPaid" data-type="(session: TCheckoutSessionExpanded) => void" data-required="false">
|
|
74
|
+
<x-field-desc markdown>Callback function executed after a successful donation. It receives the checkout session details as an argument.</x-field-desc>
|
|
75
|
+
</x-field>
|
|
76
|
+
<x-field data-name="onError" data-type="(error: Error) => void" data-required="false">
|
|
77
|
+
<x-field-desc markdown>Callback function executed if an error occurs during the payment process.</x-field-desc>
|
|
78
|
+
</x-field>
|
|
79
|
+
<x-field data-name="mode" data-type="'default' | 'inline' | 'custom'" data-default="default" data-required="false">
|
|
80
|
+
<x-field-desc markdown>Specifies the rendering mode. `'default'` shows a button and supporter list. `'inline'` shows a button that opens a popover. `'custom'` uses a render prop for a completely custom UI.</x-field-desc>
|
|
81
|
+
</x-field>
|
|
82
|
+
<x-field data-name="inlineOptions" data-type="object" data-required="false">
|
|
83
|
+
<x-field-desc markdown>Configuration options specific to the `'inline'` mode.</x-field-desc>
|
|
84
|
+
<x-field data-name="button" data-type="ButtonType" data-required="false">
|
|
85
|
+
<x-field-desc markdown>Custom properties for the inline button, such as `text` and `icon`.</x-field-desc>
|
|
86
|
+
</x-field>
|
|
87
|
+
</x-field>
|
|
88
|
+
<x-field data-name="livemode" data-type="boolean" data-required="false">
|
|
89
|
+
<x-field-desc markdown>Overrides the `livemode` setting from `PaymentProvider`. Set to `true` for live transactions or `false` for test transactions.</x-field-desc>
|
|
90
|
+
</x-field>
|
|
91
|
+
<x-field data-name="timeout" data-type="number" data-default="5000" data-required="false">
|
|
92
|
+
<x-field-desc markdown>The delay in milliseconds before the donation dialog closes automatically after a successful payment.</x-field-desc>
|
|
93
|
+
</x-field>
|
|
94
|
+
<x-field data-name="theme" data-type="'default' | 'inherit' | PaymentThemeOptions" data-default="default" data-required="false">
|
|
95
|
+
<x-field-desc markdown>Controls the component's styling. See the [Theming guide](./guides-theming.md) for more information.</x-field-desc>
|
|
96
|
+
</x-field>
|
|
97
|
+
<x-field data-name="children" data-type="function" data-required="false">
|
|
98
|
+
<x-field-desc markdown>A render prop function used only when `mode` is set to `'custom'`. See the Custom UI Mode example for the function signature.</x-field-desc>
|
|
99
|
+
</x-field>
|
|
100
|
+
</x-field-group>
|
|
119
101
|
|
|
120
102
|
### `CheckoutDonateSettings`
|
|
121
103
|
|
|
122
|
-
This object is passed to the `settings` prop and defines the core details of the donation.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
104
|
+
This object is passed to the `settings` prop and defines the core details of the donation target.
|
|
105
|
+
|
|
106
|
+
<x-field-group>
|
|
107
|
+
<x-field data-name="target" data-type="string" data-required="true">
|
|
108
|
+
<x-field-desc markdown>A unique identifier for the donation target, such as a post ID or project name. This is used to group donations.</x-field-desc>
|
|
109
|
+
</x-field>
|
|
110
|
+
<x-field data-name="title" data-type="string" data-required="true">
|
|
111
|
+
<x-field-desc markdown>The title displayed at the top of the donation dialog.</x-field-desc>
|
|
112
|
+
</x-field>
|
|
113
|
+
<x-field data-name="description" data-type="string" data-required="true">
|
|
114
|
+
<x-field-desc markdown>A brief description of the donation's purpose, shown in the dialog.</x-field-desc>
|
|
115
|
+
</x-field>
|
|
116
|
+
<x-field data-name="reference" data-type="string" data-required="true">
|
|
117
|
+
<x-field-desc markdown>A URL related to the donation target, used for record-keeping and context.</x-field-desc>
|
|
118
|
+
</x-field>
|
|
119
|
+
<x-field data-name="beneficiaries" data-type="PaymentBeneficiary[]" data-required="true">
|
|
120
|
+
<x-field-desc markdown>An array of objects defining the fund recipients. Each object must include an `address` (recipient's DID) and a `share` (percentage).</x-field-desc>
|
|
121
|
+
</x-field>
|
|
122
|
+
<x-field data-name="amount" data-type="object" data-required="false">
|
|
123
|
+
<x-field-desc markdown>Configures the donation amounts. If not provided, it falls back to settings from `DonateProvider` or a system default.</x-field-desc>
|
|
124
|
+
<x-field data-name="presets" data-type="string[]" data-required="false" data-desc="An array of suggested donation amounts (e.g., ['1', '5', '10'])."></x-field>
|
|
125
|
+
<x-field data-name="preset" data-type="string" data-required="false" data-desc="The default selected amount from the presets."></x-field>
|
|
126
|
+
<x-field data-name="minimum" data-type="string" data-required="false" data-desc="The minimum allowed donation amount."></x-field>
|
|
127
|
+
<x-field data-name="maximum" data-type="string" data-required="false" data-desc="The maximum allowed donation amount."></x-field>
|
|
128
|
+
<x-field data-name="custom" data-type="boolean" data-required="false" data-desc="Determines if users can enter a custom donation amount."></x-field>
|
|
129
|
+
</x-field>
|
|
130
|
+
<x-field data-name="appearance" data-type="object" data-required="false">
|
|
131
|
+
<x-field-desc markdown>Customizes the component's visual elements.</x-field-desc>
|
|
132
|
+
<x-field data-name="button" data-type="object" data-required="false" data-desc="Customizes the donation button's `text`, `icon`, `size`, `color`, and `variant`."></x-field>
|
|
133
|
+
<x-field data-name="history" data-type="object" data-required="false" data-desc="Configures the appearance of the supporter history list. Set `variant` to 'avatar' or 'table'."></x-field>
|
|
134
|
+
</x-field>
|
|
135
|
+
</x-field-group>
|
|
133
136
|
|
|
134
137
|
## Usage Examples
|
|
135
138
|
|
|
136
139
|
### Default Mode
|
|
137
140
|
|
|
138
|
-
|
|
141
|
+
The default mode is the most straightforward implementation. It renders a donation button and a list of recent supporters. Clicking the button opens a dialog where the user can complete the donation.
|
|
139
142
|
|
|
140
|
-
```
|
|
143
|
+
```javascript DefaultMode.jsx icon=logos:react
|
|
141
144
|
import {
|
|
142
145
|
PaymentProvider,
|
|
143
146
|
DonateProvider,
|
|
@@ -146,17 +149,17 @@ import {
|
|
|
146
149
|
import { useSessionContext } from '../hooks/session-context';
|
|
147
150
|
|
|
148
151
|
function App() {
|
|
149
|
-
const { session,
|
|
152
|
+
const { session, connectApi } = useSessionContext();
|
|
150
153
|
|
|
151
154
|
if (!session) {
|
|
152
155
|
return <div>Loading session...</div>;
|
|
153
156
|
}
|
|
154
157
|
|
|
155
158
|
return (
|
|
156
|
-
<PaymentProvider session={session}
|
|
159
|
+
<PaymentProvider session={session} connectApi={connectApi}>
|
|
157
160
|
<DonateProvider
|
|
158
|
-
mountLocation="blog-post-
|
|
159
|
-
description="Donations for
|
|
161
|
+
mountLocation="blog-post-donations"
|
|
162
|
+
description="Donations for the main blog"
|
|
160
163
|
defaultSettings={{
|
|
161
164
|
btnText: 'Buy me a coffee',
|
|
162
165
|
historyType: 'avatar',
|
|
@@ -175,7 +178,7 @@ function App() {
|
|
|
175
178
|
],
|
|
176
179
|
}}
|
|
177
180
|
onPaid={() => {
|
|
178
|
-
|
|
181
|
+
alert('Thank you for your donation!');
|
|
179
182
|
}}
|
|
180
183
|
/>
|
|
181
184
|
</DonateProvider>
|
|
@@ -186,62 +189,64 @@ function App() {
|
|
|
186
189
|
|
|
187
190
|
### Custom UI Mode
|
|
188
191
|
|
|
189
|
-
For
|
|
192
|
+
For complete control over the layout and presentation, use `mode="custom"`. This mode utilizes a render prop passed as the component's `children`. The function provides access to the donation state and methods, allowing you to build a unique user experience.
|
|
190
193
|
|
|
191
|
-
```
|
|
194
|
+
```javascript CustomMode.jsx icon=logos:react
|
|
192
195
|
import {
|
|
193
196
|
PaymentProvider,
|
|
194
197
|
DonateProvider,
|
|
195
198
|
CheckoutDonate,
|
|
196
199
|
} from '@blocklet/payment-react';
|
|
197
200
|
import { useSessionContext } from '../hooks/session-context';
|
|
198
|
-
import { CircularProgress, Button } from '@mui/material';
|
|
201
|
+
import { CircularProgress, Button, Avatar, Box, Typography } from '@mui/material';
|
|
199
202
|
|
|
200
203
|
function CustomDonationDisplay() {
|
|
201
|
-
const { session,
|
|
204
|
+
const { session, connectApi } = useSessionContext();
|
|
202
205
|
|
|
203
206
|
if (!session) {
|
|
204
207
|
return <div>Loading session...</div>;
|
|
205
208
|
}
|
|
206
209
|
|
|
207
210
|
const donateSettings = {
|
|
208
|
-
target: '
|
|
209
|
-
title: 'Support
|
|
210
|
-
description: '
|
|
211
|
-
reference: 'https://example.com/
|
|
211
|
+
target: 'project-alpha',
|
|
212
|
+
title: 'Support Project Alpha',
|
|
213
|
+
description: 'Help us build the next generation of tools.',
|
|
214
|
+
reference: 'https://example.com/projects/alpha',
|
|
212
215
|
beneficiaries: [
|
|
213
216
|
{
|
|
214
|
-
address: 'z2qa...gCLd',
|
|
217
|
+
address: 'z2qa...gCLd',
|
|
215
218
|
share: '100',
|
|
216
219
|
},
|
|
217
220
|
],
|
|
218
221
|
};
|
|
219
222
|
|
|
220
223
|
return (
|
|
221
|
-
<PaymentProvider session={session}
|
|
224
|
+
<PaymentProvider session={session} connectApi={connectApi}>
|
|
222
225
|
<DonateProvider
|
|
223
|
-
mountLocation="
|
|
224
|
-
description="Donations for
|
|
226
|
+
mountLocation="project-alpha-donations"
|
|
227
|
+
description="Donations for Project Alpha">
|
|
225
228
|
<CheckoutDonate mode="custom" settings={donateSettings}>
|
|
226
229
|
{(openDonate, totalAmount, supporters, loading, settings) => (
|
|
227
|
-
<
|
|
228
|
-
<
|
|
229
|
-
<
|
|
230
|
-
|
|
230
|
+
<Box sx={{ border: '1px solid #e0e0e0', padding: '24px', borderRadius: '8px', textAlign: 'center' }}>
|
|
231
|
+
<Typography variant="h5">Our Supporters</Typography>
|
|
232
|
+
<Typography variant="body1" color="text.secondary" sx={{ mb: 2 }}>
|
|
233
|
+
Total Donated: <strong>{totalAmount}</strong>
|
|
234
|
+
</Typography>
|
|
235
|
+
<Button variant="contained" size="large" onClick={openDonate}>
|
|
231
236
|
{settings?.appearance?.button?.text || 'Donate Now'}
|
|
232
237
|
</Button>
|
|
233
|
-
{loading
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
<
|
|
240
|
-
</
|
|
238
|
+
{loading && <CircularProgress sx={{ display: 'block', margin: '16px auto' }} />}
|
|
239
|
+
{!loading && (supporters.supporters || []).length > 0 && (
|
|
240
|
+
<Box sx={{ mt: 3 }}>
|
|
241
|
+
{(supporters.supporters || []).slice(0, 5).map((supporter) => (
|
|
242
|
+
<Box key={supporter.id} sx={{ display: 'flex', alignItems: 'center', mb: 1 }}>
|
|
243
|
+
<Avatar src={supporter.customer?.avatar} sx={{ width: 24, height: 24, mr: 1 }} />
|
|
244
|
+
<Typography variant="body2">{supporter.customer?.name}</Typography>
|
|
245
|
+
</Box>
|
|
241
246
|
))}
|
|
242
|
-
</
|
|
247
|
+
</Box>
|
|
243
248
|
)}
|
|
244
|
-
</
|
|
249
|
+
</Box>
|
|
245
250
|
)}
|
|
246
251
|
</CheckoutDonate>
|
|
247
252
|
</DonateProvider>
|
|
@@ -250,10 +255,12 @@ function CustomDonationDisplay() {
|
|
|
250
255
|
}
|
|
251
256
|
```
|
|
252
257
|
|
|
253
|
-
|
|
258
|
+
#### Custom Render Prop Arguments
|
|
259
|
+
|
|
260
|
+
The `children` function provides the following arguments:
|
|
254
261
|
|
|
255
|
-
- `openDonate`: A function to
|
|
256
|
-
- `
|
|
257
|
-
- `supporters`: A `DonateHistory` object containing the `supporters` array
|
|
258
|
-
- `loading`: A boolean
|
|
259
|
-
- `
|
|
262
|
+
- `openDonate()`: A function to programmatically open the donation dialog.
|
|
263
|
+
- `donateTotalAmount`: A formatted string representing the total amount donated (e.g., `"125.00 T"`).
|
|
264
|
+
- `supporters`: A `DonateHistory` object containing the `supporters` array, total amount, currency, and method details.
|
|
265
|
+
- `loading`: A boolean that is `true` while supporter data is being fetched.
|
|
266
|
+
- `donateSettings`: The final, resolved donation settings, merged from `DonateProvider` and the component's `settings` prop.
|
|
@@ -8,42 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
捐贈流程由 `DonateProvider` 和 `CheckoutDonate` 共同協調。以下是高層次的概述:
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
user: {
|
|
15
|
-
shape: c4-person
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
app: {
|
|
19
|
-
label: "您的 React 應用程式"
|
|
20
|
-
|
|
21
|
-
checkout-donate: {
|
|
22
|
-
label: "CheckoutDonate"
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
checkout-form: {
|
|
26
|
-
label: "CheckoutForm (在對話方塊中)"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
payment-api: {
|
|
31
|
-
label: "支付後端 API"
|
|
32
|
-
shape: cylinder
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
# 初始載入
|
|
36
|
-
app.checkout-donate -> payment-api: "獲取設定和支持者"
|
|
37
|
-
|
|
38
|
-
# 捐贈流程
|
|
39
|
-
user -> app.checkout-donate: "1. 點擊捐贈"
|
|
40
|
-
app.checkout-donate -> app.checkout-form: "2. 開啟帶有 CheckoutForm 的對話方塊"
|
|
41
|
-
app.checkout-form -> payment-api: "3. 處理支付"
|
|
42
|
-
payment-api -> app.checkout-form: "4. 回傳成功"
|
|
43
|
-
app.checkout-form -> app.checkout-donate: "5. 觸發 onPaid 回呼"
|
|
44
|
-
app.checkout-donate -> payment-api: "6. 重新獲取支持者列表"
|
|
45
|
-
payment-api -> app.checkout-donate: "7. 回傳更新後的支持者"
|
|
46
|
-
```
|
|
11
|
+
<!-- DIAGRAM_IMAGE_START:flowchart:4:3::1765377352 -->
|
|
12
|
+

|
|
13
|
+
<!-- DIAGRAM_IMAGE_END -->
|
|
47
14
|
|
|
48
15
|
1. **初始化**:`DonateProvider` 從後端獲取並快取捐贈設定(如預設金額、按鈕文字),並透過唯一的 `mountLocation` 進行識別。
|
|
49
16
|
2. **渲染**:`CheckoutDonate` 根據檢索到的設定及其 props 渲染按鈕或自訂 UI。
|
|
@@ -8,42 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
捐赠流程由 `DonateProvider` 和 `CheckoutDonate` 共同协调。以下是其高级概述:
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
user: {
|
|
15
|
-
shape: c4-person
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
app: {
|
|
19
|
-
label: "您的 React 应用"
|
|
20
|
-
|
|
21
|
-
checkout-donate: {
|
|
22
|
-
label: "CheckoutDonate"
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
checkout-form: {
|
|
26
|
-
label: "CheckoutForm(在对话框中)"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
payment-api: {
|
|
31
|
-
label: "支付后端 API"
|
|
32
|
-
shape: cylinder
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
# 初始加载
|
|
36
|
-
app.checkout-donate -> payment-api: "获取设置和支持者"
|
|
37
|
-
|
|
38
|
-
# 捐赠流程
|
|
39
|
-
user -> app.checkout-donate: "1. 点击捐赠"
|
|
40
|
-
app.checkout-donate -> app.checkout-form: "2. 打开带有 CheckoutForm 的对话框"
|
|
41
|
-
app.checkout-form -> payment-api: "3. 处理支付"
|
|
42
|
-
payment-api -> app.checkout-form: "4. 返回成功"
|
|
43
|
-
app.checkout-form -> app.checkout-donate: "5. 触发 onPaid 回调"
|
|
44
|
-
app.checkout-donate -> payment-api: "6. 重新获取支持者列表"
|
|
45
|
-
payment-api -> app.checkout-donate: "7. 返回更新后的支持者"
|
|
46
|
-
```
|
|
11
|
+
<!-- DIAGRAM_IMAGE_START:flowchart:4:3::1765377352 -->
|
|
12
|
+

|
|
13
|
+
<!-- DIAGRAM_IMAGE_END -->
|
|
47
14
|
|
|
48
15
|
1. **初始化**:`DonateProvider` 从后端获取并缓存捐赠设置(如预设金额、按钮文本),这些设置由唯一的 `mountLocation` 标识。
|
|
49
16
|
2. **渲染**:`CheckoutDonate` 根据检索到的设置及其 props 渲染一个按钮或自定义 UI。
|