Overview
The Tender JavaScript SDK provides a simple component library for integrating the Tender Cash payment flow into your JavaScript and React applications. The SDK uses Shadow DOM for style isolation and provides a seamless payment experience.@tender-cash/agent-sdk-react
View package on npm
Installation
Usage in React
Pass all payment parameters directly as props. The modal will automatically open when the component mounts with the required payment parameters.The modal opens automatically on component mount when
referenceId and amount are provided as props.API Reference
Component Props (TenderAgentProps)
The TenderAgentSdk component accepts the following props:
Required Props
| Prop | Type | Description |
|---|---|---|
fiatCurrency | string | The fiat currency code (e.g., “USD”, “EUR”). |
accessId | string | Your Tender Cash merchant Access ID. |
env | "test" | "live" | "local" | The environment to use ("test" for testing, "live" for production, "local" for local development). |
Optional Props
| Prop | Type | Description |
|---|---|---|
onEventResponse | (data: onFinishResponse) => void | Callback function triggered on payment completion or status change. |
referenceId | string | Payment reference ID. Required to auto-open the modal. |
amount | number | Payment amount in fiat currency. Required to auto-open the modal. |
paymentExpirySeconds | number | Payment expiry time in seconds. Optional, defaults to 30 minutes. |
theme | "light" | "dark" | Theme for the payment modal. Optional, defaults to “light”. |
When
referenceId and amount are provided as props, the modal will automatically open on component mount.Using Ref to Control Modal
You can use a ref to programmatically control the modal from outside the widget:Ref Methods (TenderAgentRef)
| Method | Description |
|---|---|
initiatePayment | Opens the modal and initiates a payment with the provided parameters. |
dismiss | Closes the modal. |
closeModal | Closes the modal - can be called from outside the widget. |
Callback Data (onFinishResponse)
The onEventResponse callback receives an object with the following structure:
Handling Payment Status
Features
Shadow DOM Isolation
Shadow DOM Isolation
The component uses Shadow DOM to prevent CSS leaks and conflicts with your application styles.
Auto-Open Modal
Auto-Open Modal
The modal automatically opens when payment parameters are provided, streamlining the payment flow.
TypeScript Support
TypeScript Support
Full TypeScript definitions included for type safety and better developer experience.
Responsive Design
Responsive Design
Works seamlessly on desktop and mobile devices with adaptive layouts.
Theme Customization
Theme Customization
Support for both light and dark themes to match your application design.
Framework Agnostic
Framework Agnostic
While optimized for React, the SDK can be used with any JavaScript framework or vanilla JS.
Complete Example
Here’s a complete example showing payment initiation and status handling:Environment Setup
- Test Environment
- Production Environment
Use test environment for development and testing:Test environment uses testnet cryptocurrencies and doesn’t process real transactions.
Best Practices
Secure Credentials
Secure Credentials
- Store Access ID in environment variables
- Never commit credentials to version control
- Use different credentials for test and production
Reference IDs
Reference IDs
- Use unique reference IDs for each payment
- Include order/transaction identifiers
- Store reference IDs in your database for reconciliation
Error Handling
Error Handling
- Always implement
onEventResponsecallback - Handle all possible status values
- Log errors for debugging and monitoring
Payment Expiry
Payment Expiry
- Set reasonable expiry times (default: 30 minutes)
- Inform users about expiry duration
- Handle expired payments gracefully