JavaScript SDK
JavaScript SDK
The Synapto JS SDK securely collects card details in the browser. It renders card inputs inside an iframe so raw card data never touches your servers.
For complete integration walkthroughs, see Taking Payments and Saving Cards.
Installation
Add the script tag to your page. Use the URL matching your environment:
| Environment | Script URL |
|---|---|
| Sandbox | https://js.synapto.construction/synapto.js |
| Production | https://js.synaptopay.com/synapto.js |
<script src="https://js.synaptopay.com/synapto.js"></script>Initialization
const syn = Synapto("pk_YOUR_PUBLISHABLE_KEY");Contact [email protected] to get your publishable key.
How it works
- Your server creates a payment intent or setup intent via the API, receiving a
client_secret - Your server passes the
client_secretto the frontend - The frontend creates a payment element with the
client_secretand mounts it to a DOM element — this renders a card input form in a secure iframe - When the customer submits, the frontend calls
confirmPayment()orconfirmSetup()— the SDK tokenizes the card data and sends it to Synapto - The SDK returns the result (success or error) to your frontend
The client_secret authorizes the customer to view and confirm the specific intent. Your API key is never exposed to the browser.
Payment element
syn.paymentElement(clientSecret)
syn.paymentElement(clientSecret)Creates a payment element bound to a payment intent or setup intent.
const paymentElement = syn.paymentElement("pi_..._secret_...");paymentElement.mount(selector)
paymentElement.mount(selector)Renders the card input form inside the specified DOM element.
paymentElement.mount("#payment-container");paymentElement.confirmPayment(options?)
paymentElement.confirmPayment(options?)Confirms a payment intent — tokenizes the card data, sends it to Synapto, and processes the payment. Returns a promise.
const { paymentIntent, error } = await paymentElement.confirmPayment();Returns:
| Field | Type | Description |
|---|---|---|
paymentIntent.name | string | Resource name |
paymentIntent.state | string | REQUIRES_PAYMENT_METHOD, REQUIRES_CONFIRMATION, PROCESSING, SUCCEEDED, or CANCELED |
paymentIntent.amount | string | Amount in smallest currency unit |
paymentIntent.currency | string | Three-letter ISO currency code |
paymentIntent.customer | string | Customer resource name (if set) |
paymentIntent.latest_charge | string | Most recent charge resource name |
error | string | undefined | Error message if payment failed |
paymentElement.confirmSetup(options?)
paymentElement.confirmSetup(options?)Confirms a setup intent — tokenizes the card data and saves it as a payment method. Returns a promise.
const { setupIntent, error } = await paymentElement.confirmSetup();Returns:
| Field | Type | Description |
|---|---|---|
setupIntent.name | string | Resource name |
setupIntent.state | string | REQUIRES_PAYMENT_METHOD, REQUIRES_CONFIRMATION, PROCESSING, SUCCEEDED, or CANCELED |
setupIntent.customer | string | Customer resource name |
setupIntent.payment_method | string | Saved payment method resource name |
error | string | undefined | Error message if setup failed |
paymentElement.awaitReady()
paymentElement.awaitReady()Waits until the payment element iframe is loaded and ready. Call this if you need to ensure the element is initialized before confirming.
await paymentElement.awaitReady();3D Secure
Both confirmPayment() and confirmSetup() handle 3D Secure automatically. If the card issuer requires authentication, the SDK displays a challenge modal and resolves the promise once the customer completes it.
You can customize the 3D Secure behavior with an options object:
const { paymentIntent, error } = await paymentElement.confirmPayment({
modalSelector: "#my-3ds-modal",
onModal: (visible) => {
console.log("3DS modal visible:", visible);
},
});| Option | Type | Description |
|---|---|---|
modalSelector | string | undefined | CSS selector for a custom 3DS modal container. If not provided, the SDK creates one automatically. |
onModal | function | undefined | Callback invoked with true when the 3DS challenge is shown and false when it completes. |
Updated about 1 month ago