@blocklet/payment-react 1.20.5 → 1.20.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/.aigne/doc-smith/config.yaml +2 -2
  2. package/.aigne/doc-smith/upload-cache.yaml +381 -0
  3. package/docs/components-business-auto-topup.md +128 -179
  4. package/docs/components-business-overdue-invoice-payment.md +108 -143
  5. package/docs/components-business-resume-subscription.md +117 -104
  6. package/docs/components-business.md +12 -36
  7. package/docs/components-checkout-checkout-donate.md +209 -149
  8. package/docs/components-checkout-checkout-form.md +115 -136
  9. package/docs/components-checkout-checkout-table.md +92 -172
  10. package/docs/components-checkout.md +43 -109
  11. package/docs/components-history-credit-grants-list.md +45 -70
  12. package/docs/components-history-credit-transactions-list.md +57 -67
  13. package/docs/components-history-invoice-list.md +58 -52
  14. package/docs/components-history-payment-list.md +19 -40
  15. package/docs/components-history.md +42 -67
  16. package/docs/components-ui-form-elements-address-form.md +37 -65
  17. package/docs/components-ui-form-elements-country-select.md +80 -59
  18. package/docs/components-ui-form-elements-currency-selector.md +57 -73
  19. package/docs/components-ui-form-elements-phone-input.md +90 -112
  20. package/docs/components-ui-form-elements.md +46 -80
  21. package/docs/components-ui-payment-summary.md +71 -119
  22. package/docs/components-ui-pricing-table.md +117 -204
  23. package/docs/components-ui.md +59 -32
  24. package/docs/components.md +89 -62
  25. package/docs/getting-started.md +36 -63
  26. package/docs/guides-theming.md +122 -84
  27. package/docs/guides-utilities.md +107 -145
  28. package/docs/guides.md +7 -84
  29. package/docs/hooks-use-mobile.md +50 -36
  30. package/docs/hooks-use-subscription.md +72 -89
  31. package/docs/hooks.md +12 -82
  32. package/docs/overview.md +45 -52
  33. package/docs/providers-donate-provider.md +73 -95
  34. package/docs/providers-payment-provider.md +115 -169
  35. package/docs/providers.md +27 -86
  36. package/es/locales/en.js +7 -0
  37. package/es/locales/zh.js +8 -1
  38. package/es/payment/index.js +3 -0
  39. package/es/payment/progress-item.d.ts +12 -0
  40. package/es/payment/progress-item.js +78 -0
  41. package/es/payment/success.d.ts +4 -1
  42. package/es/payment/success.js +55 -3
  43. package/lib/locales/en.js +7 -0
  44. package/lib/locales/zh.js +8 -1
  45. package/lib/payment/index.js +3 -0
  46. package/lib/payment/progress-item.d.ts +12 -0
  47. package/lib/payment/progress-item.js +107 -0
  48. package/lib/payment/success.d.ts +4 -1
  49. package/lib/payment/success.js +59 -3
  50. package/package.json +3 -3
  51. package/src/locales/en.tsx +7 -0
  52. package/src/locales/zh.tsx +8 -1
  53. package/src/payment/index.tsx +6 -0
  54. package/src/payment/progress-item.tsx +107 -0
  55. package/src/payment/success.tsx +88 -3
@@ -1,131 +1,65 @@
1
1
  # Checkout Components
2
2
 
3
- Checkout components are high-level, pre-built components designed to serve as complete entry points for various payment flows. They encapsulate the entire user experience, from presenting payment options to processing transactions and handling success or error states. This allows you to integrate complex payment scenarios like one-time payments, subscriptions from a pricing table, or donations with minimal setup.
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
- These components act as orchestrators for the payment process, as illustrated below:
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
- ```d2
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
- user_journey: {
11
- action: "User Initiates Action"
12
- select_flow: "Selects Checkout Flow" { shape: diamond }
13
- action -> select_flow
14
+ User: {
15
+ shape: c4-person
14
16
  }
15
17
 
16
- checkout_components: "Checkout Components" {
17
- shape: package
18
- form: "CheckoutForm"
19
- table: "CheckoutTable"
20
- donate: "CheckoutDonate"
21
- }
18
+ Checkout-Flow: {
19
+ label: "Checkout Flow"
22
20
 
23
- payment_flow: "Payment Flow" {
24
- ui: "Payment UI"
25
- plan: "Plan Selection"
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
- select_flow -> checkout_components.form: "Direct Payment"
32
- select_flow -> checkout_components.table: "Select Plan"
33
- select_flow -> checkout_components.donate: "Make Donation"
25
+ CheckoutTable: {
26
+ label: "CheckoutTable"
27
+ }
34
28
 
35
- checkout_components.form -> payment_flow.ui
36
- checkout_components.table -> payment_flow.plan: "Displays PricingTable"
37
- payment_flow.plan -> checkout_components.form: "Creates Session & Uses"
38
- checkout_components.donate -> payment_flow.dialog: "Opens Dialog"
39
- payment_flow.dialog -> checkout_components.form: "Uses"
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
- This section provides an overview of the primary checkout components. For detailed API references and advanced usage, please refer to the specific documentation for each component.
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 core component for processing payments from a `paymentLink` or `checkoutSession`, managing the entire payment UI and state.
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
- Renders a pricing table and handles the checkout flow when a user selects a plan. Ideal for subscription-based services.
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 implementing donations, supporting multiple display modes and managing the donation payment process.
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
- ## Provider Dependencies
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 is designed to display a comprehensive list of credit grants associated with a specific customer. It presents key information such as the grant's status, remaining balance, scope, and effective dates in a clear, tabular format. This component is essential for both customers checking their credit balance and administrators managing credit grants.
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 information.
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
- The `CreditGrantsList` component accepts the following props to customize its behavior and filter the displayed data.
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
- | Prop | Type | Description |
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
- ## Usage Example
20
+ ### Basic Usage (For Logged-in Customer)
21
21
 
22
- To use `CreditGrantsList`, it must be wrapped in a `PaymentProvider`. The provider requires `session` and `connectApi` props, which should be supplied by a session context in your application.
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
- For a detailed guide on setting up `PaymentProvider` and creating a `useSessionContext` hook, please refer to the [PaymentProvider documentation](./providers-payment-provider.md).
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
- Below is a typical implementation:
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
- // Render the PaymentProvider only when the session is ready.
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
- <MyCreditGrantsPage />
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
- In this example, the `App` component retrieves `session` and `connectApi` using a local `useSessionContext` hook and passes them to `PaymentProvider`. The `MyCreditGrantsPage` component then renders `CreditGrantsList` within this context, ensuring it has access to the necessary data.
70
-
71
- ## Displayed Information
44
+ ### Admin or Dashboard Usage
72
45
 
73
- The component renders a table with the following columns, providing a detailed overview of each credit grant:
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
- - **Name**: The name of the credit grant, or its ID if no name is provided.
76
- - **Status**: The current status of the grant (e.g., `granted`, `pending`, `expired`), displayed using a color-coded chip for easy identification.
77
- - **Remaining Credit**: The amount of credit still available in the grant, along with the currency symbol.
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
- Each row in the table is clickable, navigating the user to a detailed view of that specific credit grant.
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
- | Status | Color |
89
- |-----------|---------|
90
- | `granted` | Success |
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
- Next, you can explore how to display a detailed log of credit usage with the [CreditTransactionsList](./components-history-credit-transactions-list.md) component.
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. It serves as a comprehensive log, allowing users to track how their credits have been utilized or adjusted over time. This component is essential for providing transparency in credit-based billing systems.
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
- ### Context Requirement
5
+ This component automatically handles data fetching, pagination, and formatting, offering a straightforward way to display transaction history.
6
6
 
7
- This component requires access to the session context to identify the current user. Therefore, it must be rendered within a `PaymentProvider`. For details on setting up the provider and a `useSessionContext` hook, please refer to the [PaymentProvider documentation](./providers-payment-provider.md).
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 omitted, it defaults to the DID of the currently logged-in user from the session context. | `session.user.did` |
16
- | `subscription_id` | `string` | Filters the transactions to show only those related to a specific subscription ID. | `''` |
17
- | `credit_grant_id` | `string` | Filters the transactions to show only those related to a specific credit grant ID. | `''` |
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 transaction data is fetched or updated. It receives the new data and the previous data as arguments. | `() => {}` |
20
- | `showAdminColumns` | `boolean` | If `true`, additional columns relevant to administrators (such as 'Meter Event') are displayed. This only applies if the logged-in user has an 'owner' or 'admin' role. | `false` |
21
- | `showTimeFilter` | `boolean` | If `true`, a date range picker is displayed above the table, allowing users to filter transactions by a specific time period. | `false` |
22
- | `source` | `string` | An optional string to filter transactions by their source. | `''` |
23
- | `mode` | `'dashboard' \| 'portal'` | Controls the navigation behavior of links within the table. Use `'dashboard'` for admin-facing views and `'portal'` for standard customer-facing portals. | `'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
- #### 1. Basic Customer View
21
+ ## Basic Usage for a Customer Portal
30
22
 
31
- To display the credit transaction history for the currently logged-in user, you can render the component without any specific IDs. It will automatically fetch the user's data from the session context.
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/components/history';
36
- // Assuming useSessionContext is set up according to the PaymentProvider guide
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
- export default function UserCreditHistoryPage() {
40
- const { session } = useSessionContext();
30
+ function MyCreditHistoryPage() {
31
+ const { session, connectApi } = useSessionContext();
41
32
 
42
- // Render the component only when the session is active
43
- if (!session.user) {
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 pageSize={5} />
51
- </>
40
+ <CreditTransactionsList />
41
+ </PaymentProvider>
52
42
  );
53
43
  }
44
+
45
+ export default MyCreditHistoryPage;
54
46
  ```
55
47
 
56
- #### 2. Admin View with Filters
48
+ ## Admin View with Filtering
57
49
 
58
- For an administrative dashboard, you can display transactions for a specific customer by providing their `customer_id`. You can also enable admin-specific columns and the date filter to provide more powerful data exploration tools.
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/components/history';
63
- // Assuming useSessionContext is set up according to the PaymentProvider guide
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
- export default function AdminCustomerCreditHistory({ customerId }) {
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 (!isAdmin) {
71
- return <p>Access Denied.</p>;
60
+ if (!session || !connectApi) {
61
+ return <div>Loading session...</div>;
72
62
  }
73
63
 
74
64
  return (
75
- <>
76
- <h2>Credit Transactions for Customer {customerId}</h2>
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
- #### 3. Transactions for a Specific Credit Grant
81
+ ## Displaying Transactions for a Specific Credit Grant
89
82
 
90
- When you need to show a detailed usage report for a single credit grant, pass the `credit_grant_id`. This will filter the list to show only the transactions associated with that grant.
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/components/history';
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
- <h3>Transaction History for this Grant</h3>
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
- The component renders a table with the following columns:
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
+ ```