@tender-cash/agent-sdk-react 0.3.6 → 1.0.0
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 +55 -50
- package/dist/tender-cash-agent-sdk-react.cjs.js.map +1 -1
- package/dist/tender-cash-agent-sdk-react.es.js +3697 -3597
- 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 +12 -7
- package/dist/types/types.d.ts +2 -2
- package/package.json +1 -1
- package/readme.md +74 -47
|
@@ -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,17 +167,23 @@ 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;
|
|
181
177
|
}
|
|
178
|
+
interface StartPaymentParams {
|
|
179
|
+
referenceId: string;
|
|
180
|
+
amount: number;
|
|
181
|
+
paymentExpirySeconds?: number;
|
|
182
|
+
}
|
|
183
|
+
interface TenderAgentRef {
|
|
184
|
+
initiatePayment: (params: StartPaymentParams) => void;
|
|
185
|
+
dismiss: () => void;
|
|
186
|
+
}
|
|
182
187
|
interface PaymentChain {
|
|
183
188
|
_id: string;
|
|
184
189
|
name: string;
|
|
@@ -214,4 +219,4 @@ interface PaymentCoinsResponse {
|
|
|
214
219
|
page: number;
|
|
215
220
|
limit: number;
|
|
216
221
|
}
|
|
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, };
|
|
222
|
+
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
|
@@ -27,66 +27,54 @@ import '@tender-cash/agent-sdk-react/dist/style.css';
|
|
|
27
27
|
|
|
28
28
|
## Usage
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
For more control over the modal, use the `TenderAgentSdk` component with a ref. This allows you to programmatically initiate and dismiss the payment modal.
|
|
31
31
|
|
|
32
32
|
```jsx
|
|
33
|
-
import
|
|
33
|
+
import { useRef } from 'react';
|
|
34
34
|
import '@tender-cash/agent-sdk-react/dist/style.css'; // Don't forget styles!
|
|
35
|
-
import { TenderAgentSdk, onFinishResponse } from '@tender-cash/agent-sdk-react';
|
|
35
|
+
import { TenderAgentSdk, TenderAgentRef, onFinishResponse } from '@tender-cash/agent-sdk-react';
|
|
36
36
|
|
|
37
37
|
function PaymentComponent() {
|
|
38
|
-
const
|
|
39
|
-
const [sdkResponse, setSdkResponse] = useState<onFinishResponse | null>(null);
|
|
38
|
+
const tenderRef = useRef<TenderAgentRef>(null);
|
|
40
39
|
|
|
41
|
-
// --- Configuration ---
|
|
40
|
+
// --- Static Configuration ---
|
|
42
41
|
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
42
|
const fiatCurrency = 'USD'; // Currency code
|
|
46
43
|
const environment = 'test'; // 'test' or 'live'
|
|
47
44
|
|
|
48
|
-
const handlePaymentRequest = () => {
|
|
49
|
-
setSdkResponse(null);
|
|
50
|
-
setShowSdk(true);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
45
|
const handleEventResponse = (response: onFinishResponse) => {
|
|
54
46
|
console.log('SDK Response:', response);
|
|
55
|
-
setSdkResponse(response);
|
|
56
|
-
setShowSdk(false); // Hide the component after response
|
|
57
47
|
// Handle success, partial payment, overpayment, error based on response.status
|
|
58
48
|
};
|
|
59
49
|
|
|
50
|
+
const handleOpenModal = () => {
|
|
51
|
+
tenderRef.current?.initiatePayment({
|
|
52
|
+
amount: 150.00,
|
|
53
|
+
referenceId: 'unique-payment-reference-123',
|
|
54
|
+
paymentExpirySeconds: 1800,
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const handleDismissModal = () => {
|
|
59
|
+
tenderRef.current?.dismiss();
|
|
60
|
+
};
|
|
61
|
+
|
|
60
62
|
return (
|
|
61
63
|
<div>
|
|
62
|
-
{
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
)}
|
|
64
|
+
<button onClick={handleOpenModal}>
|
|
65
|
+
Pay ${amount.toFixed(2)} {fiatCurrency}
|
|
66
|
+
</button>
|
|
67
|
+
<button onClick={handleDismissModal}>
|
|
68
|
+
Close Modal
|
|
69
|
+
</button>
|
|
70
|
+
|
|
71
|
+
<TenderAgentSdk
|
|
72
|
+
ref={tenderRef}
|
|
73
|
+
accessId={accessId}
|
|
74
|
+
fiatCurrency={fiatCurrency}
|
|
75
|
+
env={environment}
|
|
76
|
+
onEventResponse={handleEventResponse}
|
|
77
|
+
/>
|
|
90
78
|
</div>
|
|
91
79
|
);
|
|
92
80
|
}
|
|
@@ -94,15 +82,54 @@ function PaymentComponent() {
|
|
|
94
82
|
export default PaymentComponent;
|
|
95
83
|
```
|
|
96
84
|
|
|
97
|
-
##
|
|
85
|
+
## API Reference
|
|
86
|
+
|
|
87
|
+
### `TenderAgentSdk` Component with Ref
|
|
88
|
+
|
|
89
|
+
The `TenderAgentSdk` component can be used with a ref to programmatically control the modal.
|
|
90
|
+
|
|
91
|
+
**Ref Methods (`TenderAgentRef`):**
|
|
92
|
+
|
|
93
|
+
| Method | Description |
|
|
94
|
+
|---------------------|----------------------------------------------------------|
|
|
95
|
+
| `initiatePayment()` | Initiates a payment and opens the payment modal |
|
|
96
|
+
| `dismiss()` | Closes/dismisses the payment modal |
|
|
97
|
+
|
|
98
|
+
**Example:**
|
|
99
|
+
```typescript
|
|
100
|
+
import { useRef } from 'react';
|
|
101
|
+
import { TenderAgentSdk, TenderAgentRef } from '@tender-cash/agent-sdk-react';
|
|
102
|
+
|
|
103
|
+
const tenderRef = useRef<TenderAgentRef>(null);
|
|
104
|
+
|
|
105
|
+
// Open modal
|
|
106
|
+
tenderRef.current?.initiatePayment({
|
|
107
|
+
amount: 150.00,
|
|
108
|
+
referenceId: 'unique-payment-reference-123',
|
|
109
|
+
paymentExpirySeconds: 1800,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Close modal
|
|
113
|
+
tenderRef.current?.dismiss();
|
|
114
|
+
|
|
115
|
+
// Render component
|
|
116
|
+
<TenderAgentSdk
|
|
117
|
+
ref={tenderRef}
|
|
118
|
+
accessId="YOUR_ACCESS_ID"
|
|
119
|
+
fiatCurrency="USD"
|
|
120
|
+
env="test"
|
|
121
|
+
/>;
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Component Props (`TenderAgentProps`)
|
|
125
|
+
|
|
126
|
+
The `TenderAgentSdk` component (when used directly) accepts the following configuration props:
|
|
98
127
|
|
|
99
128
|
| Prop | Type | Required | Description |
|
|
100
129
|
|------------------|---------------------------------------------|----------|-----------------------------------------------------------------------------|
|
|
101
|
-
| `amount` | `number` | Yes | The amount to be charged in the specified fiat currency. |
|
|
102
130
|
| `fiatCurrency` | `string` | Yes | The fiat currency code (e.g., "USD", "EUR"). |
|
|
103
131
|
| `accessId` | `string` | Yes | Your Tender Cash merchant Access ID. |
|
|
104
|
-
| `
|
|
105
|
-
| `env` | `"test"` \| `"live"` | Yes | The environment to use (`"test"` for testing, `"live"` for production). |
|
|
132
|
+
| `env` | `"test"` \| `"live"` \| `"local"` | Yes | The environment to use (`"test"` for testing, `"live"` for production, `"local"` for local development). |
|
|
106
133
|
| `onEventResponse`| `(data: onFinishResponse) => void` | No | Optional callback function triggered on payment completion or status change. |
|
|
107
134
|
|
|
108
135
|
## Callback Data (`onFinishResponse`)
|