@blocklet/payment-react 1.20.4 → 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 +7 -7
- 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,131 +1,65 @@
|
|
|
1
1
|
# Checkout Components
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The `@blocklet/payment-react` library provides a set of high-level Checkout Components designed to serve as complete, ready-to-use entry points for various payment scenarios. These components encapsulate the entire user flow, from selecting a product to completing the payment, allowing you to integrate complex payment experiences with minimal setup.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Whether you need to display a pricing table, accept donations, or process a direct payment link, these components handle the underlying logic of session creation, state management, and UI rendering.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
### Component Flow
|
|
8
|
+
|
|
9
|
+
The typical flow involves a user interacting with an entry-point component like `CheckoutTable` or `CheckoutDonate`. These components then create a `CheckoutSession` and delegate the final payment processing to the core `CheckoutForm` component.
|
|
10
|
+
|
|
11
|
+
```d2 Checkout Component Flow icon=mdi:transit-connection-variant
|
|
8
12
|
direction: down
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
select_flow: "Selects Checkout Flow" { shape: diamond }
|
|
13
|
-
action -> select_flow
|
|
14
|
+
User: {
|
|
15
|
+
shape: c4-person
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
form: "CheckoutForm"
|
|
19
|
-
table: "CheckoutTable"
|
|
20
|
-
donate: "CheckoutDonate"
|
|
21
|
-
}
|
|
18
|
+
Checkout-Flow: {
|
|
19
|
+
label: "Checkout Flow"
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
dialog: "Donation Dialog"
|
|
27
|
-
completion: "Payment Completion"
|
|
28
|
-
ui -> completion
|
|
29
|
-
}
|
|
21
|
+
Entry-Points: {
|
|
22
|
+
label: "User-Facing Components"
|
|
23
|
+
shape: rectangle
|
|
30
24
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
CheckoutTable: {
|
|
26
|
+
label: "CheckoutTable"
|
|
27
|
+
}
|
|
34
28
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
CheckoutDonate: {
|
|
30
|
+
label: "CheckoutDonate"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
Core-Processor: {
|
|
35
|
+
label: "Core Payment Processor"
|
|
36
|
+
shape: rectangle
|
|
37
|
+
|
|
38
|
+
CheckoutForm: {
|
|
39
|
+
label: "CheckoutForm"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
41
43
|
|
|
42
|
-
|
|
44
|
+
User -> Checkout-Flow.Entry-Points.CheckoutTable: "Selects a subscription"
|
|
45
|
+
User -> Checkout-Flow.Entry-Points.CheckoutDonate: "Makes a donation"
|
|
46
|
+
Checkout-Flow.Entry-Points.CheckoutTable -> Checkout-Flow.Core-Processor.CheckoutForm: "On plan selection"
|
|
47
|
+
Checkout-Flow.Entry-Points.CheckoutDonate -> Checkout-Flow.Core-Processor.CheckoutForm: "On donate action"
|
|
48
|
+
Checkout-Flow.Core-Processor.CheckoutForm -> User: "Payment Result"
|
|
49
|
+
```
|
|
43
50
|
|
|
44
|
-
|
|
51
|
+
Explore the components below to find the best fit for your application's needs.
|
|
45
52
|
|
|
46
53
|
<x-cards data-columns="3">
|
|
47
54
|
<x-card data-title="CheckoutForm" data-icon="lucide:credit-card" data-href="/components/checkout/checkout-form">
|
|
48
|
-
The
|
|
55
|
+
The fundamental component for processing payments. It takes a `paymentLink` or `checkoutSession` ID and renders the complete payment UI.
|
|
49
56
|
</x-card>
|
|
50
57
|
<x-card data-title="CheckoutTable" data-icon="lucide:table" data-href="/components/checkout/checkout-table">
|
|
51
|
-
|
|
58
|
+
Displays a complete pricing table. When a user selects a plan, it automatically initiates a checkout session and renders the payment form.
|
|
52
59
|
</x-card>
|
|
53
|
-
<x-card data-title="CheckoutDonate" data-icon="lucide:heart" data-href="/components/checkout/checkout-donate">
|
|
54
|
-
A flexible component for
|
|
60
|
+
<x-card data-title="CheckoutDonate" data-icon="lucide:heart-handshake" data-href="/components/checkout/checkout-donate">
|
|
61
|
+
A flexible component for adding donation functionality. It handles donation setup, displays supporter history, and manages the donation payment flow.
|
|
55
62
|
</x-card>
|
|
56
63
|
</x-cards>
|
|
57
64
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
All checkout components require being wrapped within the `PaymentProvider` to function correctly, as it supplies the necessary context for API communication and session management.
|
|
61
|
-
|
|
62
|
-
For `CheckoutDonate`, it is also recommended to wrap it with `DonateProvider` to manage global donation settings and state effectively.
|
|
63
|
-
|
|
64
|
-
Here is a typical provider setup in an application. This example uses a local session context for DID connect, which is a common pattern.
|
|
65
|
-
|
|
66
|
-
```tsx
|
|
67
|
-
import React from 'react';
|
|
68
|
-
import { CheckoutTable, CheckoutDonate } from '@blocklet/payment-react';
|
|
69
|
-
import { PaymentProvider } from '@blocklet/payment-react/lib/contexts/payment';
|
|
70
|
-
import { DonateProvider } from '@blocklet/payment-react/lib/contexts/donate';
|
|
71
|
-
|
|
72
|
-
// This is a local file you would create to manage your DID-Connect session.
|
|
73
|
-
// See the PaymentProvider documentation for setup instructions.
|
|
74
|
-
import { SessionProvider, useSessionContext } from '../contexts/session';
|
|
75
|
-
|
|
76
|
-
const donationSettings = {
|
|
77
|
-
target: 'unique_target_id_for_your_project',
|
|
78
|
-
title: 'Support Our Project',
|
|
79
|
-
description: 'Your contribution helps us continue our work.',
|
|
80
|
-
beneficiaries: [{ did: 'z2qa...', weight: 100 }], // Replace with actual beneficiary DID
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
function MyPaymentFeatures() {
|
|
84
|
-
// Obtain session and connectApi from your local session context.
|
|
85
|
-
const { session, connectApi } = useSessionContext();
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
// PaymentProvider requires the session and connectApi for authentication and communication.
|
|
89
|
-
<PaymentProvider session={session} connect={connectApi}>
|
|
90
|
-
{/* Example 1: Using CheckoutTable for subscription plans */}
|
|
91
|
-
<div style={{ marginBottom: '40px' }}>
|
|
92
|
-
<h2>Choose a Subscription Plan</h2>
|
|
93
|
-
<CheckoutTable
|
|
94
|
-
id="prctbl_xxxxxxxxxxxx" // Replace with your pricing table ID
|
|
95
|
-
onPaid={(context) => console.log('Subscription successfully started!', context)}
|
|
96
|
-
onError={(error) => console.error('Subscription failed:', error)}
|
|
97
|
-
/>
|
|
98
|
-
</div>
|
|
99
|
-
|
|
100
|
-
{/* Example 2: Using CheckoutDonate with its specific provider */}
|
|
101
|
-
<div>
|
|
102
|
-
<h2>Make a Donation</h2>
|
|
103
|
-
<DonateProvider>
|
|
104
|
-
<CheckoutDonate
|
|
105
|
-
settings={donationSettings}
|
|
106
|
-
onPaid={() => console.log('Thank you for your donation!')}
|
|
107
|
-
onError={(error) => console.error('Donation failed:', error)}
|
|
108
|
-
/>
|
|
109
|
-
</DonateProvider>
|
|
110
|
-
</div>
|
|
111
|
-
</PaymentProvider>
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function App() {
|
|
116
|
-
// The SessionProvider wraps your application to provide session context.
|
|
117
|
-
// For a detailed guide on setting up your session context and PaymentProvider,
|
|
118
|
-
// please see the [PaymentProvider documentation](./providers-payment-provider.md).
|
|
119
|
-
return (
|
|
120
|
-
<SessionProvider>
|
|
121
|
-
<MyPaymentFeatures />
|
|
122
|
-
</SessionProvider>
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export default App;
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
## Next Steps
|
|
130
|
-
|
|
131
|
-
These components provide powerful, out-of-the-box solutions for common payment scenarios. To build more customized payment experiences, you can explore the lower-level [UI Components](./components-ui.md).
|
|
65
|
+
Each of these components is designed to be highly customizable and can be integrated seamlessly into your application. Click on any card to view its detailed documentation and usage examples.
|
|
@@ -1,98 +1,73 @@
|
|
|
1
1
|
# CreditGrantsList
|
|
2
2
|
|
|
3
|
-
The `CreditGrantsList` component
|
|
3
|
+
The `CreditGrantsList` component renders a paginated table displaying a customer's credit grants. It provides a clear overview of each grant's status, remaining balance, scope, and validity period.
|
|
4
4
|
|
|
5
|
-
This component must be used within a `PaymentProvider` to access the necessary session and context
|
|
5
|
+
This component is essential for both customer-facing portals where users can track their available credits and admin dashboards for managing customer grants. It must be used within a `PaymentProvider` to access the necessary session and API context.
|
|
6
6
|
|
|
7
7
|
## Props
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
| Prop | Type | Description | Default |
|
|
10
|
+
| --- | --- | --- | --- |
|
|
11
|
+
| `customer_id` | `string` | Optional. The ID of the customer. If omitted, it defaults to the DID of the currently authenticated user from the session context. | `session.user.did` |
|
|
12
|
+
| `subscription_id` | `string` | Optional. Filters the list to show only grants associated with a specific subscription. | `''` |
|
|
13
|
+
| `status` | `string` | Optional. A comma-separated string of statuses to filter by. Valid statuses include `granted`, `pending`, `expired`, `depleted`, and `voided`. | `'granted,pending,depleted,expired'` |
|
|
14
|
+
| `pageSize` | `number` | Optional. The number of items to display per page. | `10` |
|
|
15
|
+
| `onTableDataChange` | `(data, prevData) => void` | Optional. A callback function that is invoked whenever the table data is fetched or updated. | `() => {}` |
|
|
16
|
+
| `mode` | `'dashboard' \| 'portal'` | Optional. Determines the navigation behavior when a row is clicked. Use `'portal'` for customer-facing views and `'dashboard'` for admin panels, which generates different link paths. | `'portal'` |
|
|
10
17
|
|
|
11
|
-
|
|
12
|
-
|---------------------|------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
13
|
-
| `customer_id` | `string` | The ID of the customer whose credit grants are to be displayed. If not provided, it defaults to the DID of the currently logged-in user from the session context. |
|
|
14
|
-
| `subscription_id` | `string` | Optional. Filters the credit grants to show only those associated with a specific subscription ID. |
|
|
15
|
-
| `status` | `string` | Optional. A comma-separated string of statuses to filter by. Defaults to `'granted,pending,depleted,expired'`. Valid statuses include `granted`, `pending`, `expired`, `depleted`, and `voided`. |
|
|
16
|
-
| `pageSize` | `number` | Optional. The number of items to display per page. Defaults to `10`. |
|
|
17
|
-
| `onTableDataChange` | `(data, prevData) => void` | Optional. A callback function that is invoked when the table's data is fetched or updated. It receives the new and previous data sets as arguments. |
|
|
18
|
-
| `mode` | `'dashboard'` \| `'portal'` | Optional. Determines the navigation behavior. In `'dashboard'` mode (for admins), links navigate to admin-specific routes. In `'portal'` mode (for customers), links navigate to customer-facing routes. |
|
|
18
|
+
## Usage
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
### Basic Usage (For Logged-in Customer)
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
By default, the `CreditGrantsList` component fetches and displays the credit grants for the currently authenticated user. This is the most common use case for a customer's account page.
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
```jsx My Credit Grants icon=logos:react
|
|
25
|
+
import { CreditGrantsList, PaymentProvider } from '@blocklet/payment-react';
|
|
26
|
+
import { useSessionContext } from '/path/to/your/session/context'; // Adjust this import path
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
```jsx
|
|
29
|
-
import React from 'react';
|
|
30
|
-
import { PaymentProvider } from '@blocklet/payment-react';
|
|
31
|
-
import CreditGrantsList from '@blocklet/payment-react/lib/components/history/credit-grants-list';
|
|
32
|
-
// This is your local hook to get session context.
|
|
33
|
-
// See the PaymentProvider docs for how to create it.
|
|
34
|
-
import { useSessionContext } from '../../contexts/session';
|
|
35
|
-
|
|
36
|
-
// A component that displays the credit grants list.
|
|
37
|
-
const MyCreditGrantsPage = () => {
|
|
38
|
-
// If you don't provide a customer_id, the component will automatically
|
|
39
|
-
// use the DID of the currently logged-in user.
|
|
40
|
-
const customerId = 'cus_xxxxxxxxxxxxxx'; // Optional: replace with a specific customer ID
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
<div>
|
|
44
|
-
<h2>My Credit Grants</h2>
|
|
45
|
-
<CreditGrantsList customer_id={customerId} pageSize={5} />
|
|
46
|
-
</div>
|
|
47
|
-
);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// Your main App component where you set up the providers.
|
|
51
|
-
const App = () => {
|
|
28
|
+
function MyCreditGrantsPage() {
|
|
52
29
|
const { session, connectApi } = useSessionContext();
|
|
53
30
|
|
|
54
|
-
|
|
55
|
-
if (!session) {
|
|
31
|
+
if (!session || !connectApi) {
|
|
56
32
|
return <div>Loading session...</div>;
|
|
57
33
|
}
|
|
58
34
|
|
|
59
35
|
return (
|
|
60
36
|
<PaymentProvider session={session} connectApi={connectApi}>
|
|
61
|
-
<
|
|
37
|
+
<h2>My Credit Grants</h2>
|
|
38
|
+
<CreditGrantsList />
|
|
62
39
|
</PaymentProvider>
|
|
63
40
|
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export default App;
|
|
41
|
+
}
|
|
67
42
|
```
|
|
68
43
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
## Displayed Information
|
|
44
|
+
### Admin or Dashboard Usage
|
|
72
45
|
|
|
73
|
-
|
|
46
|
+
In an administrative dashboard, you can display the credit grants for any customer by providing the `customer_id` prop. You can also customize the filters and page size.
|
|
74
47
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
- **Scope**: Indicates whether the credit is `general` (applicable to any charge) or `specific` (applicable only to certain prices).
|
|
79
|
-
- **Effective Date**: The date and time when the credit grant becomes active.
|
|
80
|
-
- **Expiration Date**: The date and time when the credit grant expires. A hyphen (`-`) is shown if there is no expiration date.
|
|
48
|
+
```jsx Customer Credit Grants icon=logos:react
|
|
49
|
+
import { CreditGrantsList, PaymentProvider } from '@blocklet/payment-react';
|
|
50
|
+
import { useSessionContext } from '/path/to/your/session/context'; // Adjust this import path
|
|
81
51
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
## StatusChip Helper
|
|
85
|
-
|
|
86
|
-
The `CreditGrantsList` utilizes an internal `StatusChip` component to visually represent the status of each grant. The colors are mapped as follows:
|
|
52
|
+
function CustomerDetailsPage({ customerId }) {
|
|
53
|
+
const { session, connectApi } = useSessionContext();
|
|
87
54
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
| `pending` | Warning |
|
|
92
|
-
| `expired` | Default |
|
|
93
|
-
| `depleted`| Default |
|
|
94
|
-
| `voided` | Default |
|
|
55
|
+
if (!session || !connectApi) {
|
|
56
|
+
return <div>Loading session...</div>;
|
|
57
|
+
}
|
|
95
58
|
|
|
96
|
-
|
|
59
|
+
return (
|
|
60
|
+
<PaymentProvider session={session} connectApi={connectApi}>
|
|
61
|
+
<h3>Active Credit Grants for Customer</h3>
|
|
62
|
+
<CreditGrantsList
|
|
63
|
+
customer_id={customerId}
|
|
64
|
+
status="granted,pending"
|
|
65
|
+
pageSize={5}
|
|
66
|
+
mode="dashboard"
|
|
67
|
+
/>
|
|
68
|
+
</PaymentProvider>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
```
|
|
97
72
|
|
|
98
|
-
|
|
73
|
+
This example shows how to list only the 'granted' and 'pending' grants for a specific customer, displaying 5 items per page. The `mode="dashboard"` ensures that clicking a grant will navigate to an admin-specific URL.
|
|
@@ -1,116 +1,106 @@
|
|
|
1
1
|
# CreditTransactionsList
|
|
2
2
|
|
|
3
|
-
The `CreditTransactionsList` component renders a detailed and paginated table of credit transactions
|
|
3
|
+
The `CreditTransactionsList` component renders a detailed and paginated table of all credit transactions, providing a clear log of credit usage and adjustments. It is ideal for use in customer portals or administrative dashboards to track how credits are granted and consumed.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This component automatically handles data fetching, pagination, and formatting, offering a straightforward way to display transaction history.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
### Properties
|
|
10
|
-
|
|
11
|
-
The `CreditTransactionsList` component accepts the following properties:
|
|
7
|
+
## Props
|
|
12
8
|
|
|
13
9
|
| Prop | Type | Description | Default |
|
|
14
10
|
| --- | --- | --- | --- |
|
|
15
|
-
| `customer_id` | `string` | The ID of the customer whose transactions are to be displayed. If
|
|
16
|
-
| `subscription_id` | `string` | Filters the transactions to
|
|
17
|
-
| `credit_grant_id` | `string` | Filters the transactions to
|
|
11
|
+
| `customer_id` | `string` | The ID of the customer whose transactions are to be displayed. If not provided, it defaults to the DID of the currently logged-in user from the `PaymentProvider` context. | `session.user.did` |
|
|
12
|
+
| `subscription_id` | `string` | Filters the transactions to a specific subscription. | `undefined` |
|
|
13
|
+
| `credit_grant_id` | `string` | Filters the transactions to a specific credit grant. | `undefined` |
|
|
18
14
|
| `pageSize` | `number` | The number of transactions to display per page. | `10` |
|
|
19
|
-
| `onTableDataChange` | `(data, prevData) => void` | A callback function that is triggered when the
|
|
20
|
-
| `showAdminColumns` | `boolean` | If `true
|
|
21
|
-
| `showTimeFilter` | `boolean` | If `true`, a date range picker is displayed
|
|
22
|
-
| `source` | `string` | An optional string to filter transactions
|
|
23
|
-
| `mode` | `'dashboard' \| 'portal'` |
|
|
24
|
-
|
|
25
|
-
### Usage Scenarios
|
|
26
|
-
|
|
27
|
-
All examples assume you have a `useSessionContext` hook configured as outlined in the `PaymentProvider` guide.
|
|
15
|
+
| `onTableDataChange` | `(data, prevData) => void` | A callback function that is triggered when the table data is fetched or updated. | `() => {}` |
|
|
16
|
+
| `showAdminColumns` | `boolean` | If `true` and the user is an admin, additional columns like 'Meter Event' are shown. | `false` |
|
|
17
|
+
| `showTimeFilter` | `boolean` | If `true`, a date range picker is displayed to allow filtering transactions by date. | `false` |
|
|
18
|
+
| `source` | `string` | An optional source string to filter transactions. | `''` |
|
|
19
|
+
| `mode` | `'dashboard' \| 'portal'` | Determines the link structure for related items like credit grants. Use `'dashboard'` for admin views and `'portal'` for customer-facing views. | `'portal'` |
|
|
28
20
|
|
|
29
|
-
|
|
21
|
+
## Basic Usage for a Customer Portal
|
|
30
22
|
|
|
31
|
-
|
|
23
|
+
This example shows how to display the credit transaction history for the currently logged-in user. The component automatically uses the user's DID from the `PaymentProvider` context when `customer_id` is omitted.
|
|
32
24
|
|
|
33
|
-
```jsx
|
|
25
|
+
```jsx MyCreditHistoryPage.tsx icon=logos:react
|
|
34
26
|
import React from 'react';
|
|
35
|
-
import { CreditTransactionsList } from '@blocklet/payment-react
|
|
36
|
-
|
|
37
|
-
import { useSessionContext } from '../../contexts/session';
|
|
27
|
+
import { CreditTransactionsList, PaymentProvider } from '@blocklet/payment-react';
|
|
28
|
+
import { useSessionContext } from '../hooks/session-context'; // Your session context hook
|
|
38
29
|
|
|
39
|
-
|
|
40
|
-
const { session } = useSessionContext();
|
|
30
|
+
function MyCreditHistoryPage() {
|
|
31
|
+
const { session, connectApi } = useSessionContext();
|
|
41
32
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return <p>Please log in to see your credit history.</p>;
|
|
33
|
+
if (!session || !connectApi) {
|
|
34
|
+
return <div>Loading session...</div>;
|
|
45
35
|
}
|
|
46
36
|
|
|
47
37
|
return (
|
|
48
|
-
|
|
38
|
+
<PaymentProvider session={session} connectApi={connectApi}>
|
|
49
39
|
<h2>My Credit Transactions</h2>
|
|
50
|
-
<CreditTransactionsList
|
|
51
|
-
|
|
40
|
+
<CreditTransactionsList />
|
|
41
|
+
</PaymentProvider>
|
|
52
42
|
);
|
|
53
43
|
}
|
|
44
|
+
|
|
45
|
+
export default MyCreditHistoryPage;
|
|
54
46
|
```
|
|
55
47
|
|
|
56
|
-
|
|
48
|
+
## Admin View with Filtering
|
|
57
49
|
|
|
58
|
-
For an
|
|
50
|
+
For an admin dashboard, you can pass a specific `customer_id` and enable admin columns and time filters to provide a more powerful and detailed view of a user's transaction history.
|
|
59
51
|
|
|
60
|
-
```jsx
|
|
52
|
+
```jsx CustomerDetailsPage.tsx icon=logos:react
|
|
61
53
|
import React from 'react';
|
|
62
|
-
import { CreditTransactionsList } from '@blocklet/payment-react
|
|
63
|
-
|
|
64
|
-
import { useSessionContext } from '../../contexts/session';
|
|
54
|
+
import { CreditTransactionsList, PaymentProvider } from '@blocklet/payment-react';
|
|
55
|
+
import { useSessionContext } from '../hooks/session-context'; // Your session context hook
|
|
65
56
|
|
|
66
|
-
|
|
67
|
-
const { session } = useSessionContext();
|
|
68
|
-
const isAdmin = ['owner', 'admin'].includes(session?.user?.role || '');
|
|
57
|
+
function CustomerDetailsPage({ customerId }) {
|
|
58
|
+
const { session, connectApi } = useSessionContext();
|
|
69
59
|
|
|
70
|
-
if (!
|
|
71
|
-
return <
|
|
60
|
+
if (!session || !connectApi) {
|
|
61
|
+
return <div>Loading session...</div>;
|
|
72
62
|
}
|
|
73
63
|
|
|
74
64
|
return (
|
|
75
|
-
|
|
76
|
-
<
|
|
65
|
+
<PaymentProvider session={session} connectApi={connectApi}>
|
|
66
|
+
<h3>Transaction History for {customerId}</h3>
|
|
77
67
|
<CreditTransactionsList
|
|
78
68
|
customer_id={customerId}
|
|
79
69
|
showAdminColumns={true}
|
|
80
70
|
showTimeFilter={true}
|
|
71
|
+
pageSize={20}
|
|
81
72
|
mode="dashboard"
|
|
82
73
|
/>
|
|
83
|
-
|
|
74
|
+
</PaymentProvider>
|
|
84
75
|
);
|
|
85
76
|
}
|
|
77
|
+
|
|
78
|
+
export default CustomerDetailsPage;
|
|
86
79
|
```
|
|
87
80
|
|
|
88
|
-
|
|
81
|
+
## Displaying Transactions for a Specific Credit Grant
|
|
89
82
|
|
|
90
|
-
|
|
83
|
+
To show a detailed log of how a particular credit grant was consumed, pass the `credit_grant_id`. This is useful for pages that show the details of a single credit grant.
|
|
91
84
|
|
|
92
|
-
```jsx
|
|
85
|
+
```jsx CreditGrantDetailsPage.tsx icon=logos:react
|
|
93
86
|
import React from 'react';
|
|
94
|
-
import { CreditTransactionsList } from '@blocklet/payment-react
|
|
87
|
+
import { CreditTransactionsList, PaymentProvider } from '@blocklet/payment-react';
|
|
88
|
+
import { useSessionContext } from '../hooks/session-context'; // Your session context hook
|
|
89
|
+
|
|
90
|
+
function CreditGrantDetailsPage({ grantId }) {
|
|
91
|
+
const { session, connectApi } = useSessionContext();
|
|
92
|
+
|
|
93
|
+
if (!session || !connectApi) {
|
|
94
|
+
return <div>Loading session...</div>;
|
|
95
|
+
}
|
|
95
96
|
|
|
96
|
-
export default function CreditGrantUsageDetails({ grantId }) {
|
|
97
97
|
return (
|
|
98
|
-
|
|
99
|
-
<
|
|
98
|
+
<PaymentProvider session={session} connectApi={connectApi}>
|
|
99
|
+
<h4>Usage Details for Grant {grantId}</h4>
|
|
100
100
|
<CreditTransactionsList credit_grant_id={grantId} />
|
|
101
|
-
|
|
101
|
+
</PaymentProvider>
|
|
102
102
|
);
|
|
103
103
|
}
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### Table Columns
|
|
107
104
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
- **Amount**: The value of the credit transaction and its unit.
|
|
111
|
-
- **Credit Grant**: A link to the parent credit grant. This column is automatically hidden if the list is already filtered by a `credit_grant_id`.
|
|
112
|
-
- **Description**: Provides context for the transaction, such as the associated subscription or usage event.
|
|
113
|
-
- **Meter Event** (Admin Only): A link to the specific billing meter event that triggered the transaction. This is only visible when `showAdminColumns` is `true` and the user is an admin.
|
|
114
|
-
- **Date**: The timestamp indicating when the transaction was created.
|
|
115
|
-
|
|
116
|
-
After displaying credit usage, you might want to show an overview of all credit grants. To do this, you can use the [`CreditGrantsList`](./components-history-credit-grants-list.md) component.
|
|
105
|
+
export default CreditGrantDetailsPage;
|
|
106
|
+
```
|