@tender-cash/agent-sdk-react 0.3.6 → 1.0.1-beta
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/dist/assets/icons/error.svg +9 -0
- package/dist/style.css +1 -1
- package/dist/tender-cash-agent-sdk-react.cjs.js +88 -58
- package/dist/tender-cash-agent-sdk-react.cjs.js.map +1 -1
- package/dist/tender-cash-agent-sdk-react.es.js +11157 -5593
- package/dist/tender-cash-agent-sdk-react.es.js.map +1 -1
- package/dist/types/module/_actions/details.d.ts +4 -0
- package/dist/types/module/_actions/index.d.ts +2 -0
- package/dist/types/module/index.d.ts +2 -2
- package/dist/types/module/lib/utils/index.d.ts +2 -1
- package/dist/types/module/screens/info.d.ts +3 -1
- package/dist/types/module/types.d.ts +16 -7
- package/dist/types/types.d.ts +2 -2
- package/package.json +1 -1
- package/readme.md +45 -60
|
@@ -13,14 +13,18 @@ declare const fetchPaymentDetailAction: ({ nextScreen, setPageLoading, }: {
|
|
|
13
13
|
referenceId: string;
|
|
14
14
|
}) => Promise<void>;
|
|
15
15
|
paymentError: {
|
|
16
|
+
type?: string;
|
|
16
17
|
title: string;
|
|
17
18
|
message: string;
|
|
18
19
|
data: any;
|
|
20
|
+
isError: boolean;
|
|
19
21
|
} | undefined;
|
|
20
22
|
setPaymentError: import('react').Dispatch<import('react').SetStateAction<{
|
|
23
|
+
type?: string;
|
|
21
24
|
title: string;
|
|
22
25
|
message: string;
|
|
23
26
|
data: any;
|
|
27
|
+
isError: boolean;
|
|
24
28
|
} | undefined>>;
|
|
25
29
|
confirmPayment: () => void | Promise<void>;
|
|
26
30
|
cancelPayment: () => void | Promise<void>;
|
|
@@ -22,9 +22,11 @@ declare const useAgentSdkAction: () => {
|
|
|
22
22
|
pageLoading: boolean;
|
|
23
23
|
coinFetching: boolean;
|
|
24
24
|
paymentError: {
|
|
25
|
+
type?: string;
|
|
25
26
|
title: string;
|
|
26
27
|
message: string;
|
|
27
28
|
data: any;
|
|
29
|
+
isError: boolean;
|
|
28
30
|
} | undefined;
|
|
29
31
|
};
|
|
30
32
|
export default useAgentSdkAction;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { TenderAgentProps } from './types';
|
|
2
|
-
declare const TenderAgentSdk: (
|
|
1
|
+
import { TenderAgentProps, TenderAgentRef } from './types';
|
|
2
|
+
declare const TenderAgentSdk: import('react').ForwardRefExoticComponent<TenderAgentProps & import('react').RefAttributes<TenderAgentRef>>;
|
|
3
3
|
export default TenderAgentSdk;
|
|
@@ -16,4 +16,5 @@ declare const getRequestSignature: ({ accessId, accessSecret, }: IGetRequestSign
|
|
|
16
16
|
declare const applyTheme: (theme: ITheme) => void;
|
|
17
17
|
declare const sleep: (milliseconds: number) => void;
|
|
18
18
|
declare const sentenceCase: (str: string) => string;
|
|
19
|
-
|
|
19
|
+
declare const formatCurrency: (amount: number, currency: string) => string;
|
|
20
|
+
export { cn, getRequestSignature, applyTheme, sleep, TENDER_URLS, URL_PATHS, sentenceCase, formatCurrency, };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
declare const InfoScreen: ({ title, message, dataToView, }: {
|
|
1
|
+
declare const InfoScreen: ({ type, title, message, dataToView, isError, }: {
|
|
2
|
+
type?: string;
|
|
2
3
|
title?: string;
|
|
3
4
|
message?: string;
|
|
5
|
+
isError?: boolean;
|
|
4
6
|
dataToView?: {
|
|
5
7
|
network: string;
|
|
6
8
|
coin: string;
|
|
@@ -39,7 +39,7 @@ declare enum paymentStatusMap {
|
|
|
39
39
|
}
|
|
40
40
|
type PaymentTypeProps = "partial" | "complete" | "over" | "pending" | "error";
|
|
41
41
|
type PaymentStatusProps = "partial-payment" | "completed" | "overpayment" | "pending" | "error" | "cancelled";
|
|
42
|
-
type TenderEnvironments = "test" | "live";
|
|
42
|
+
type TenderEnvironments = "test" | "live" | "local";
|
|
43
43
|
interface FormHeaderProps {
|
|
44
44
|
title: string;
|
|
45
45
|
description: string;
|
|
@@ -160,7 +160,6 @@ interface onFinishResponse {
|
|
|
160
160
|
interface ConfigContextType {
|
|
161
161
|
referenceId: string;
|
|
162
162
|
accessId: string;
|
|
163
|
-
accessSecret: string;
|
|
164
163
|
amount: number;
|
|
165
164
|
fiatCurrency: string;
|
|
166
165
|
env: TenderEnvironments;
|
|
@@ -168,16 +167,26 @@ interface ConfigContextType {
|
|
|
168
167
|
paymentExpirySeconds?: number;
|
|
169
168
|
theme?: "light" | "dark";
|
|
170
169
|
onEventResponse?: (data: onFinishResponse) => void;
|
|
170
|
+
onClose?: () => void;
|
|
171
171
|
}
|
|
172
172
|
interface TenderAgentProps {
|
|
173
|
-
referenceId: string;
|
|
174
|
-
amount: number;
|
|
175
173
|
fiatCurrency: string;
|
|
176
174
|
accessId: string;
|
|
177
|
-
accessSecret: string;
|
|
178
175
|
env: TenderEnvironments;
|
|
179
|
-
paymentExpirySeconds?: number;
|
|
180
176
|
onEventResponse?: (data: onFinishResponse) => void;
|
|
177
|
+
referenceId?: string;
|
|
178
|
+
amount?: number;
|
|
179
|
+
paymentExpirySeconds?: number;
|
|
180
|
+
theme?: "light" | "dark";
|
|
181
|
+
}
|
|
182
|
+
interface StartPaymentParams {
|
|
183
|
+
referenceId: string;
|
|
184
|
+
amount: number;
|
|
185
|
+
paymentExpirySeconds?: number;
|
|
186
|
+
}
|
|
187
|
+
interface TenderAgentRef {
|
|
188
|
+
initiatePayment: (params: StartPaymentParams) => void;
|
|
189
|
+
dismiss: () => void;
|
|
181
190
|
}
|
|
182
191
|
interface PaymentChain {
|
|
183
192
|
_id: string;
|
|
@@ -214,4 +223,4 @@ interface PaymentCoinsResponse {
|
|
|
214
223
|
page: number;
|
|
215
224
|
limit: number;
|
|
216
225
|
}
|
|
217
|
-
export { type IAny, type FormHeaderProps, type FormFooterProps, type IPaymentData, type PaymentTypeProps, type PaymentStatusProps, type paymentResponseProps, type paymentDetailsProps, type newPaymentResponse, type Option, type IGetRequestSignatureParam, type IGetRequestSignature, type ITheme, type ConfigContextType, type TenderEnvironments, type TenderAgentProps, type QueueItem, type PaymentCoinsResponse, type PaymentChainResponse, type PaymentCoin, type APIResponse, type APIError, type onFinishResponse, paymentStatusMap, PAYMENT_STAGE, PAYMENT_STATUS, PAYMENT_RESPONSES, PAYMENT_ICONS, };
|
|
226
|
+
export { type IAny, type FormHeaderProps, type FormFooterProps, type IPaymentData, type PaymentTypeProps, type PaymentStatusProps, type paymentResponseProps, type paymentDetailsProps, type newPaymentResponse, type Option, type IGetRequestSignatureParam, type IGetRequestSignature, type ITheme, type ConfigContextType, type TenderEnvironments, type TenderAgentProps, type StartPaymentParams, type TenderAgentRef, type QueueItem, type PaymentCoinsResponse, type PaymentChainResponse, type PaymentCoin, type APIResponse, type APIError, type onFinishResponse, paymentStatusMap, PAYMENT_STAGE, PAYMENT_STATUS, PAYMENT_RESPONSES, PAYMENT_ICONS, };
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { TenderEnvironments, TenderAgentProps, onFinishResponse } from 'module/types';
|
|
2
|
-
export { type TenderEnvironments, type TenderAgentProps, type onFinishResponse, };
|
|
1
|
+
import { TenderEnvironments, TenderAgentProps, TenderAgentRef, onFinishResponse } from './module/types';
|
|
2
|
+
export { type TenderEnvironments, type TenderAgentProps, type TenderAgentRef, type onFinishResponse, };
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -19,7 +19,7 @@ npm install @tender-cash/agent-sdk-react
|
|
|
19
19
|
|
|
20
20
|
## Styling
|
|
21
21
|
|
|
22
|
-
The component
|
|
22
|
+
The component uses Shadow DOM to prevent CSS leaks into your application. The styles are automatically injected into the shadow root, so you don't need to import the CSS file manually. However, if you're using the component in a build that doesn't bundle CSS automatically, you can still import it:
|
|
23
23
|
|
|
24
24
|
```javascript
|
|
25
25
|
import '@tender-cash/agent-sdk-react/dist/style.css';
|
|
@@ -27,83 +27,61 @@ import '@tender-cash/agent-sdk-react/dist/style.css';
|
|
|
27
27
|
|
|
28
28
|
## Usage
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
Pass all payment parameters directly as props. The modal will automatically open when the component mounts with the required payment parameters.
|
|
31
31
|
|
|
32
32
|
```jsx
|
|
33
|
-
import
|
|
34
|
-
import '@tender-cash/agent-sdk-react/dist/style.css'; // Don't forget styles!
|
|
33
|
+
import '@tender-cash/agent-sdk-react/dist/style.css';
|
|
35
34
|
import { TenderAgentSdk, onFinishResponse } from '@tender-cash/agent-sdk-react';
|
|
36
35
|
|
|
37
36
|
function PaymentComponent() {
|
|
38
|
-
const [showSdk, setShowSdk] = useState(false);
|
|
39
|
-
const [sdkResponse, setSdkResponse] = useState<onFinishResponse | null>(null);
|
|
40
|
-
|
|
41
|
-
// --- Configuration ---
|
|
42
|
-
const accessId = 'YOUR_ACCESS_ID'; // Replace with your actual Access ID
|
|
43
|
-
const accessSecret = 'YOUR_ACCESS_SECRET'; // Replace with your actual Access Secret
|
|
44
|
-
const amount = 150.00; // Amount to charge
|
|
45
|
-
const fiatCurrency = 'USD'; // Currency code
|
|
46
|
-
const environment = 'test'; // 'test' or 'live'
|
|
47
|
-
|
|
48
|
-
const handlePaymentRequest = () => {
|
|
49
|
-
setSdkResponse(null);
|
|
50
|
-
setShowSdk(true);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
37
|
const handleEventResponse = (response: onFinishResponse) => {
|
|
54
38
|
console.log('SDK Response:', response);
|
|
55
|
-
setSdkResponse(response);
|
|
56
|
-
setShowSdk(false); // Hide the component after response
|
|
57
39
|
// Handle success, partial payment, overpayment, error based on response.status
|
|
58
40
|
};
|
|
59
41
|
|
|
60
42
|
return (
|
|
61
|
-
<
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
{
|
|
69
|
-
|
|
70
|
-
<TenderAgentSdk
|
|
71
|
-
accessId={accessId}
|
|
72
|
-
accessSecret={accessSecret}
|
|
73
|
-
amount={amount}
|
|
74
|
-
fiatCurrency={fiatCurrency}
|
|
75
|
-
env={environment}
|
|
76
|
-
onEventResponse={handleEventResponse}
|
|
77
|
-
/>
|
|
78
|
-
<button onClick={() => setShowSdk(false)}>Cancel Payment</button>
|
|
79
|
-
</div>
|
|
80
|
-
)}
|
|
81
|
-
|
|
82
|
-
{sdkResponse && (
|
|
83
|
-
<div>
|
|
84
|
-
<h3>Payment Result:</h3>
|
|
85
|
-
<p>Status: {sdkResponse.status}</p>
|
|
86
|
-
<p>Message: {sdkResponse.message}</p>
|
|
87
|
-
{sdkResponse.data && <pre>{JSON.stringify(sdkResponse.data, null, 2)}</pre>}
|
|
88
|
-
</div>
|
|
89
|
-
)}
|
|
90
|
-
</div>
|
|
43
|
+
<TenderAgentSdk
|
|
44
|
+
accessId="YOUR_ACCESS_ID"
|
|
45
|
+
fiatCurrency="USD"
|
|
46
|
+
env="test"
|
|
47
|
+
onEventResponse={handleEventResponse}
|
|
48
|
+
amount={150.00}
|
|
49
|
+
referenceId="unique-payment-reference-123"
|
|
50
|
+
paymentExpirySeconds={1800}
|
|
51
|
+
/>
|
|
91
52
|
);
|
|
92
53
|
}
|
|
93
54
|
|
|
94
55
|
export default PaymentComponent;
|
|
95
56
|
```
|
|
96
57
|
|
|
97
|
-
|
|
58
|
+
**Note:** The modal opens automatically on component mount when `referenceId` and `amount` are provided as props.
|
|
59
|
+
|
|
60
|
+
## API Reference
|
|
61
|
+
|
|
62
|
+
### Component Props (`TenderAgentProps`)
|
|
63
|
+
|
|
64
|
+
The `TenderAgentSdk` component accepts the following props:
|
|
98
65
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
|
102
|
-
|
|
103
|
-
| `
|
|
104
|
-
| `
|
|
105
|
-
| `env` | `"test"` \| `"live"`
|
|
106
|
-
|
|
66
|
+
#### Required Props
|
|
67
|
+
|
|
68
|
+
| Prop | Type | Description |
|
|
69
|
+
|------------------|---------------------------------------------|-----------------------------------------------------------------------------|
|
|
70
|
+
| `fiatCurrency` | `string` | The fiat currency code (e.g., "USD", "EUR"). |
|
|
71
|
+
| `accessId` | `string` | Your Tender Cash merchant Access ID. |
|
|
72
|
+
| `env` | `"test"` \| `"live"` \| `"local"` | The environment to use (`"test"` for testing, `"live"` for production, `"local"` for local development). |
|
|
73
|
+
|
|
74
|
+
#### Optional Props
|
|
75
|
+
|
|
76
|
+
| Prop | Type | Description |
|
|
77
|
+
|-------------------------|---------------------------------------------|-----------------------------------------------------------------------------|
|
|
78
|
+
| `onEventResponse` | `(data: onFinishResponse) => void` | Callback function triggered on payment completion or status change. |
|
|
79
|
+
| `referenceId` | `string` | Payment reference ID. Required to auto-open the modal. |
|
|
80
|
+
| `amount` | `number` | Payment amount in fiat currency. Required to auto-open the modal. |
|
|
81
|
+
| `paymentExpirySeconds` | `number` | Payment expiry time in seconds. Optional, defaults to 30 minutes. |
|
|
82
|
+
| `theme` | `"light"` \| `"dark"` | Theme for the payment modal. Optional, defaults to "light". |
|
|
83
|
+
|
|
84
|
+
**Note:** When `referenceId` and `amount` are provided as props, the modal will automatically open on component mount.
|
|
107
85
|
|
|
108
86
|
## Callback Data (`onFinishResponse`)
|
|
109
87
|
|
|
@@ -129,6 +107,13 @@ interface IPaymentData {
|
|
|
129
107
|
}
|
|
130
108
|
```
|
|
131
109
|
|
|
110
|
+
## Features
|
|
111
|
+
|
|
112
|
+
- **Shadow DOM Isolation**: The component uses Shadow DOM to prevent CSS leaks and conflicts with your application styles.
|
|
113
|
+
- **Auto-Open**: The modal automatically opens when payment parameters are provided.
|
|
114
|
+
- **TypeScript Support**: Full TypeScript definitions included.
|
|
115
|
+
- **Responsive Design**: Works seamlessly on desktop and mobile devices.
|
|
116
|
+
|
|
132
117
|
## License
|
|
133
118
|
|
|
134
119
|
[MIT](./LICENSE)
|