@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.
@@ -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: ({ referenceId, amount, accessId, accessSecret, env, fiatCurrency, paymentExpirySeconds, onEventResponse }: TenderAgentProps) => import("react/jsx-runtime").JSX.Element;
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
- export { cn, getRequestSignature, applyTheme, sleep, TENDER_URLS, URL_PATHS, sentenceCase, };
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, };
@@ -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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tender-cash/agent-sdk-react",
3
3
  "license": "MIT",
4
- "version": "0.3.6",
4
+ "version": "1.0.1-beta",
5
5
  "repository": "git://github.com/tender-cash/agent-sdk-react.git",
6
6
  "description": "",
7
7
  "author": "Tender",
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 requires its CSS file to be imported for proper styling. Import it in your main application entry point (e.g., `src/index.js`, `src/main.tsx`):
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
- Import the `TenderAgentSdk` component and render it within your React application. Pass the required configuration as props.
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 React, { useState } from 'react';
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
- <div>
62
- {!showSdk && (
63
- <button onClick={handlePaymentRequest}>
64
- Pay ${amount.toFixed(2)} {fiatCurrency}
65
- </button>
66
- )}
67
-
68
- {showSdk && (
69
- <div>
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
- ## Component Props (`TenderAgentProps`)
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
- | Prop | Type | Required | Description |
100
- |------------------|---------------------------------------------|----------|-----------------------------------------------------------------------------|
101
- | `amount` | `number` | Yes | The amount to be charged in the specified fiat currency. |
102
- | `fiatCurrency` | `string` | Yes | The fiat currency code (e.g., "USD", "EUR"). |
103
- | `accessId` | `string` | Yes | Your Tender Cash merchant Access ID. |
104
- | `accessSecret` | `string` | Yes | Your Tender Cash merchant Access Secret. |
105
- | `env` | `"test"` \| `"live"` | Yes | The environment to use (`"test"` for testing, `"live"` for production). |
106
- | `onEventResponse`| `(data: onFinishResponse) => void` | No | Optional callback function triggered on payment completion or status change. |
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)