@tender-cash/agent-sdk-react 1.1.0 → 1.1.2

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.
@@ -167,7 +167,7 @@ interface ConfigContextType {
167
167
  paymentExpirySeconds?: number;
168
168
  theme?: "light" | "dark";
169
169
  onEventResponse?: (data: onFinishResponse) => void;
170
- onClose?: () => void;
170
+ closeModal?: () => void;
171
171
  }
172
172
  interface TenderAgentProps {
173
173
  fiatCurrency: string;
@@ -178,6 +178,7 @@ interface TenderAgentProps {
178
178
  amount?: number;
179
179
  paymentExpirySeconds?: number;
180
180
  theme?: "light" | "dark";
181
+ closeModal?: () => void;
181
182
  }
182
183
  interface StartPaymentParams {
183
184
  referenceId: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tender-cash/agent-sdk-react",
3
3
  "license": "MIT",
4
- "version": "1.1.0",
4
+ "version": "1.1.2",
5
5
  "repository": "git://github.com/tender-cash/agent-sdk-react.git",
6
6
  "description": "",
7
7
  "author": "Tender",
package/readme.md CHANGED
@@ -17,20 +17,11 @@ Using npm:
17
17
  npm install @tender-cash/agent-sdk-react
18
18
  ```
19
19
 
20
- ## Styling
21
-
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
-
24
- ```javascript
25
- import '@tender-cash/agent-sdk-react/dist/style.css';
26
- ```
27
-
28
20
  ## Usage
29
21
 
30
22
  Pass all payment parameters directly as props. The modal will automatically open when the component mounts with the required payment parameters.
31
23
 
32
24
  ```jsx
33
- import '@tender-cash/agent-sdk-react/dist/style.css';
34
25
  import { TenderAgentSdk, onFinishResponse } from '@tender-cash/agent-sdk-react';
35
26
 
36
27
  function PaymentComponent() {
@@ -81,8 +72,61 @@ The `TenderAgentSdk` component accepts the following props:
81
72
  | `paymentExpirySeconds` | `number` | Payment expiry time in seconds. Optional, defaults to 30 minutes. |
82
73
  | `theme` | `"light"` \| `"dark"` | Theme for the payment modal. Optional, defaults to "light". |
83
74
 
75
+
84
76
  **Note:** When `referenceId` and `amount` are provided as props, the modal will automatically open on component mount.
85
77
 
78
+ ### Using Ref to Control Modal
79
+
80
+ You can use a ref to programmatically control the modal from outside the widget:
81
+
82
+ ```jsx
83
+ import { useRef } from 'react';
84
+ import { TenderAgentSdk, TenderAgentRef } from '@tender-cash/agent-sdk-react';
85
+
86
+ function PaymentComponent() {
87
+ const tenderRef = useRef<TenderAgentRef>(null);
88
+
89
+ const handleOpenPayment = () => {
90
+ tenderRef.current?.initiatePayment({
91
+ amount: 150.00,
92
+ referenceId: "unique-payment-reference-123",
93
+ paymentExpirySeconds: 1800
94
+ });
95
+ };
96
+
97
+ const handleCloseModal = () => {
98
+ // Close the modal programmatically from outside the widget
99
+ tenderRef.current?.closeModal();
100
+ };
101
+
102
+ return (
103
+ <>
104
+ <button onClick={handleOpenPayment}>Open Payment</button>
105
+ <button onClick={handleCloseModal}>Close Modal</button>
106
+
107
+ <TenderAgentSdk
108
+ ref={tenderRef}
109
+ accessId="YOUR_ACCESS_ID"
110
+ fiatCurrency="USD"
111
+ env="test"
112
+ onEventResponse={(response) => console.log(response)}
113
+ amount={150.00}
114
+ referenceId="unique-payment-reference-123"
115
+ paymentExpirySeconds={1800}
116
+ />
117
+ </>
118
+ );
119
+ }
120
+ ```
121
+
122
+ #### Ref Methods (`TenderAgentRef`)
123
+
124
+ | Method | Description |
125
+ |-------------------|-----------------------------------------------------------------------------|
126
+ | `initiatePayment` | Opens the modal and initiates a payment with the provided parameters. |
127
+ | `dismiss` | Closes the modal. |
128
+ | `closeModal` | Closes the modal - can be called from outside the widget. |
129
+
86
130
  ## Callback Data (`onFinishResponse`)
87
131
 
88
132
  The `onEventResponse` callback receives an object with the following structure: