Examples
Example - Basic APM Payment
Minimal integration using getCustomerPaymentMethods() to display available APMs and trigger a payment.
JavaScript
// If you're loading the SDK via <script src="https://zplit-prod.s3.amazonaws.com/v1/bundle.min.js"></script> // you can use `const inline = new TonderSdk.LiteInlineCheckout(...)` instead of importing from 'tonder-web-sdk'. import { LiteInlineCheckout } from 'tonder-web-sdk' async function run() { const liteCheckout = new LiteInlineCheckout({ mode: 'stage', apiKey: '11e3d3c3e95e0eaabbcae61ebad34ee5f93c3d27', // YOUR API KEY returnUrl: window.location.href, }) await liteCheckout.injectCheckout() liteCheckout.verify3dsTransaction().then(response => { console.log("Verify 3ds response", response); }); let selectedMethod = null; const methods = await liteCheckout.getCustomerPaymentMethods() console.log('Available APMs:', methods) const payButton = document.getElementById("pay-button"); // Process payment with APM payButton.addEventListener("click", async function () { try { payButton.textContent = "Processing..."; // Pass the selected payment method or hardcode one from the available list. const response = await liteCheckout.payment({...checkoutData, payment_method: selectedMethod}); console.log("Payment response:", response); alert("Payment successfully"); } catch (error) { console.log("Payment error:", error); alert("Error while processing the payment"); } finally { payButton.textContent = "Pay"; } }); // Just an example to showcase the APMs. // Show all APMs or only the ones you want. const container = document.getElementById('apm-list') methods.forEach((method) => { const card = document.createElement('div') card.className = 'apm-card' card.onclick = () => { document.querySelectorAll('.apm-card.selected').forEach((el) => { el.classList.remove('selected') }) card.classList.add('selected') selectedMethod = method.payment_method; } const img = document.createElement('img') img.src = method.icon img.alt = method.label const label = document.createElement('div') label.className = 'label' label.textContent = method.label card.appendChild(img) card.appendChild(label) container.appendChild(card) }) } run() const checkoutData = { customer: { firstName: "Adrian", lastName: "Martinez", country: "Mexico", address: "Pinos 507, Col El Tecuan", city: "Durango", state: "Durango", postCode: "34105", email: "adrian@email.com", phone: "8161234567", identification:{ type: "CPF", number: "19119119100" } }, currency: "mxn", cart: { total: 399, items: [ { description: "Black T-Shirt", quantity: 1, price_unit: 1, discount: 0, taxes: 0, product_reference: 1, name: "T-Shirt", amount_total: 399, }, ], }, metadata: { order_id: "ORD-123456", }, order_reference: "ORD-123456", // configs for apm apm_config: {}, };
React
// If you're loading the SDK via <script src="https://zplit-prod.s3.amazonaws.com/v1/bundle.min.js"></script> // you can use `const inline = new TonderSdk.LiteInlineCheckout(...)` instead of importing from 'tonder-web-sdk'. import React, { useEffect, useState } from "react"; import { LiteInlineCheckout } from "tonder-web-sdk"; const checkoutData = { customer: { firstName: "Adrian", lastName: "Martinez", country: "Mexico", address: "Pinos 507, Col El Tecuan", city: "Durango", state: "Durango", postCode: "34105", email: "adrian@email.com", phone: "8161234567", identification:{ type: "CPF", number: "19119119100" } }, currency: "mxn", cart: { total: 399, items: [ { description: "Black T-Shirt", quantity: 1, price_unit: 1, discount: 0, taxes: 0, product_reference: 1, name: "T-Shirt", amount_total: 399 } ] }, metadata: { order_id: "ORD-123456" }, order_reference: "ORD-123456", // configs for apm apm_config: {} }; export default function App() { const [methods, setMethods] = useState([]); const [selected, setSelected] = useState(null); const [loading, setLoading] = useState(false); const [liteCheckout, setLiteCheckout] = useState(null); useEffect(() => { const run = async () => { const lite = new LiteInlineCheckout({ mode: "stage", apiKey: "11e3d3c3e95e0eaabbcae61ebad34ee5f93c3d27", returnUrl: window.location.href }); setLiteCheckout(lite); await lite.injectCheckout(); lite.verify3dsTransaction().then(response => { console.log("Verify 3ds response", response); }); const methods = await lite.getCustomerPaymentMethods(); setMethods(methods); }; run(); }, []); const handlePayment = async () => { setLoading(true); try { const response = await liteCheckout.payment({...checkoutData, payment_method: selected}); console.log("Payment response:", response); alert("Payment successfully"); }catch (e){ console.log("Payment error:", e); alert("Error while processing the payment"); }finally { setLoading(false) } } return ( <div style={{ fontFamily: "sans-serif" }}> <h3>Select a Payment Method</h3> <div id="apm-list"> {methods.map((method) => ( <div key={method.id} onClick={() => setSelected(method.payment_method)} style={{ border: selected === method.payment_method ? "2px solid #0070f3" : "1px solid #ccc", borderRadius: 8, padding: 8, width: 95, textAlign: "center", cursor: "pointer", background: selected === method.payment_method ? "#eef6ff" : "white" }} > <img src={method.icon} alt={method.label} style={{ width: 32, height: 32 }} /> <div style={{ marginTop: 8 }}>{method.label}</div> </div> ))} </div> <div className="button-container"> <button disabled={loading} onClick={handlePayment} id="pay-button" > {loading ? 'Processing...':'Pay'} </button> </div> </div> ); }
Angular
// If you're loading the SDK via <script src="https://zplit-prod.s3.amazonaws.com/v1/bundle.min.js"></script> // you can use `const inline = new TonderSdk.LiteInlineCheckout(...)` instead of importing from 'tonder-web-sdk'. import { Component, OnInit } from '@angular/core'; import { LiteInlineCheckout } from 'tonder-web-sdk'; @Component({ selector: 'app-root', template: ` <div style="font-family: sans-serif"> <h3>Select a Payment Method</h3> <div id="apm-list" class="apm-list"> <div *ngFor="let method of methods" (click)="selectMethod(method)" [ngStyle]="{ border: selected === method.payment_method ? '2px solid #0070f3' : '1px solid #ccc', borderRadius: '8px', padding: '8px', width: '95px', textAlign: 'center', cursor: 'pointer', background: selected === method.payment_method ? '#eef6ff' : 'white' }" > <img [src]="method.icon" [alt]="method.label" width="32" height="32" /> <div style="margin-top: 8px">{{ method.label }}</div> </div> </div> <div class="button-container"> <button [disabled]="loading" (click)="handlePayment()" id="pay-button"> {{ loading ? 'Processing...' : 'Pay' }} </button> </div> </div> `, styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { methods: any[] = []; selected: string | null = null; loading = false; liteCheckout: any; async ngOnInit() { this.liteCheckout = new LiteInlineCheckout({ mode: 'stage', apiKey: '11e3d3c3e95e0eaabbcae61ebad34ee5f93c3d27', returnUrl: window.location.href }); await this.liteCheckout.injectCheckout(); this.liteCheckout.verify3dsTransaction().then((response: any) => { console.log('Verify 3ds response', response); }); this.methods = await this.liteCheckout.getCustomerPaymentMethods(); } selectMethod(method: any) { this.selected = method.payment_method; } async handlePayment() { if (!this.selected) return; this.loading = true; const checkoutData = { customer: { firstName: 'Adrian', lastName: 'Martinez', country: 'Mexico', address: 'Pinos 507, Col El Tecuan', city: 'Durango', state: 'Durango', postCode: '34105', email: 'adrian@email.com', phone: '8161234567', identification: { type: 'CPF', number: '19119119100' } }, currency: 'mxn', cart: { total: 399, items: [ { description: 'Black T-Shirt', quantity: 1, price_unit: 1, discount: 0, taxes: 0, product_reference: 1, name: 'T-Shirt', amount_total: 399 } ] }, metadata: { order_id: 'ORD-123456' }, order_reference: 'ORD-123456', apm_config: {}, payment_method: this.selected }; try { const response = await this.liteCheckout.payment(checkoutData); console.log('Payment response:', response); alert('Payment successfully'); } catch (e) { console.error('Payment error:', e); alert('Error while processing the payment'); } finally { this.loading = false; } } }
Example - Custom APM UI with Amount Selector
Hardcoded APM list with a two-column layout and manual/quick amount input before calling payment().
JavaScript
// If you're loading the SDK via <script src="https://zplit-prod.s3.amazonaws.com/v1/bundle.min.js"></script> // you can use `const inline = new TonderSdk.LiteInlineCheckout(...)` instead of importing from 'tonder-web-sdk'. import { LiteInlineCheckout } from 'tonder-web-sdk' let selectedMethod = null; async function run() { const lite = new LiteInlineCheckout({ mode: 'stage', apiKey: '11e3d3c3e95e0eaabbcae61ebad34ee5f93c3d27', returnUrl: window.location.href, }); await lite.injectCheckout(); lite.verify3dsTransaction().then(res => console.log("Verify 3DS:", res)); // Select APM document.querySelectorAll('.apm-card').forEach(card => { card.addEventListener('click', () => { document.querySelectorAll('.apm-card.selected').forEach(el => el.classList.remove('selected')); card.classList.add('selected'); selectedMethod = card.dataset.method; }); }); // Quick amount buttons const input = document.getElementById('amount-input'); document.querySelectorAll('.preset-amount').forEach(btn => { btn.addEventListener('click', () => { input.value = btn.dataset.amount; }); }); // Pay const payBtn = document.getElementById('pay-button'); payBtn.addEventListener('click', async () => { if (!selectedMethod || !input.value) return alert('Select APM and amount'); const amount = parseFloat(input.value); const data = { ...checkoutData, cart: { ...checkoutData.cart, total: amount, items: [{ ...checkoutData.cart.items[0], amount_total: amount }] }, payment_method: selectedMethod, }; try { payBtn.textContent = "Processing..."; const res = await lite.payment(data); console.log("Payment response:", res); alert("Payment successful"); } catch (err) { console.error(err); alert("Payment failed"); } finally { payBtn.textContent = "Deposit"; } }); } const checkoutData = { customer: { firstName: "Adrian", lastName: "Martinez", country: "Mexico", address: "Pinos 507, Col El Tecuan", city: "Durango", state: "Durango", postCode: "34105", email: "adrian@email.com", phone: "8161234567", identification: { type: "CPF", number: "19119119100" } }, currency: "mxn", cart: { total: 399, items: [{ description: "Black T-Shirt", quantity: 1, price_unit: 1, discount: 0, taxes: 0, product_reference: 1, name: "T-Shirt", amount_total: 399 }] }, metadata: { order_id: "ORD-123456" }, order_reference: "ORD-123456", apm_config: {} }; run();
React
// If you're loading the SDK via <script src="https://zplit-prod.s3.amazonaws.com/v1/bundle.min.js"></script> // you can use `const inline = new TonderSdk.LiteInlineCheckout(...)` instead of importing from 'tonder-web-sdk'. import React, { useEffect, useState } from "react"; import { LiteInlineCheckout } from "tonder-web-sdk"; const checkoutData = { customer: { firstName: "Adrian", lastName: "Martinez", country: "Mexico", address: "Pinos 507, Col El Tecuan", city: "Durango", state: "Durango", postCode: "34105", email: "adrian@email.com", phone: "8161234567", identification: { type: "CPF", number: "19119119100" } }, currency: "mxn", cart: { total: 0, items: [ { description: "Deposit", quantity: 1, price_unit: 1, discount: 0, taxes: 0, product_reference: 1, name: "Deposit", amount_total: 0 } ] }, metadata: { order_id: "ORD-123456" }, order_reference: "ORD-123456", apm_config: {} }; const hardcodedMethods = [ { payment_method: "oxxopay", label: "OXXOPay", icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/oxxopay.png" }, { payment_method: "spei", label: "SPEI", icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/spei.png" }, { payment_method: "mercadopago", label: "MercadoPago", icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/mercadopago.png" } ]; export default function App() { const [selected, setSelected] = useState(null); const [amount, setAmount] = useState(""); const [loading, setLoading] = useState(false); const [liteCheckout, setLiteCheckout] = useState(null); useEffect(() => { const run = async () => { const lite = new LiteInlineCheckout({ mode: "stage", apiKey: "11e3d3c3e95e0eaabbcae61ebad34ee5f93c3d27", returnUrl: window.location.href }); await lite.injectCheckout(); lite.verify3dsTransaction().then(res => console.log("Verify 3DS:", res)); setLiteCheckout(lite); }; run(); }, []); const handleAmountClick = (value) => { setAmount(value); }; const handlePayment = async () => { if (!selected || !amount) return alert("Select an APM and amount"); setLoading(true); const updatedData = { ...checkoutData, cart: { ...checkoutData.cart, total: parseFloat(amount), items: [ { ...checkoutData.cart.items[0], amount_total: parseFloat(amount) } ] }, payment_method: selected }; try { const res = await liteCheckout.payment(updatedData); console.log("Payment response:", res); alert("Payment successful"); } catch (err) { console.error("Payment error:", err); alert("Payment failed"); } finally { setLoading(false); } }; return ( <div style={{ display: "flex", fontFamily: "sans-serif", gap: 20 }}> <div style={{ width: 120 }}> {hardcodedMethods.map((method) => ( <div key={method.payment_method} onClick={() => setSelected(method.payment_method)} style={{ border: selected === method.payment_method ? "2px solid #0070f3" : "1px solid #ccc", borderRadius: 8, padding: 8, textAlign: "center", cursor: "pointer", background: selected === method.payment_method ? "#eef6ff" : "white", marginBottom: 10 }} > <img src={method.icon} alt={method.label} style={{ width: 32, height: 32 }} /> <div style={{ marginTop: 8 }}>{method.label}</div> </div> ))} </div> <div style={{ flex: 1 }}> <h4>Select Amount</h4> <div style={{ display: "flex", gap: 10, marginBottom: 10 }}> {[300, 500, 1000].map((amt) => ( <button key={amt} onClick={() => handleAmountClick(amt)}>{amt}</button> ))} </div> <input type="number" value={amount} onChange={(e) => setAmount(e.target.value)} placeholder="Enter amount" style={{ padding: 8, width: "100%", marginBottom: 10 }} /> <button id="pay-button" onClick={handlePayment} disabled={loading}> {loading ? "Processing..." : "Depositar"} </button> </div> </div> ); }
Angular
// If you're loading the SDK via <script src="https://zplit-prod.s3.amazonaws.com/v1/bundle.min.js"></script> // you can use `const inline = new TonderSdk.LiteInlineCheckout(...)` instead of importing from 'tonder-web-sdk'. import { Component, OnInit } from '@angular/core'; import { LiteInlineCheckout } from 'tonder-web-sdk'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { methods = [ { payment_method: 'oxxopay', label: 'OXXOPay', icon: 'https://d35a75syrgujp0.cloudfront.net/payment_methods/oxxopay.png' }, { payment_method: 'spei', label: 'SPEI', icon: 'https://d35a75syrgujp0.cloudfront.net/payment_methods/spei.png' }, { payment_method: 'mercadopago', label: 'MercadoPago', icon: 'https://d35a75syrgujp0.cloudfront.net/payment_methods/mercadopago.png' } ]; presetAmounts = [300, 500, 1000]; selected: string | null = null; amount: number | null = null; loading = false; liteCheckout: any; async ngOnInit() { this.liteCheckout = new LiteInlineCheckout({ mode: 'stage', apiKey: '11e3d3c3e95e0eaabbcae61ebad34ee5f93c3d27', returnUrl: window.location.href }); await this.liteCheckout.injectCheckout(); this.liteCheckout.verify3dsTransaction().then(res => { console.log('Verify 3DS:', res); }); } selectMethod(method: any) { this.selected = method.payment_method; } setAmount(value: number) { this.amount = value; } async handlePayment() { if (!this.selected || !this.amount) return alert('Select an APM and amount'); this.loading = true; const checkoutData = { customer: { firstName: 'Adrian', lastName: 'Martinez', country: 'Mexico', address: 'Pinos 507, Col El Tecuan', city: 'Durango', state: 'Durango', postCode: '34105', email: 'adrian@email.com', phone: '8161234567', identification: { type: 'CPF', number: '19119119100' } }, currency: 'mxn', cart: { total: this.amount, items: [ { description: 'Deposit', quantity: 1, price_unit: 1, discount: 0, taxes: 0, product_reference: 1, name: 'Deposit', amount_total: this.amount } ] }, metadata: { order_id: 'ORD-123456' }, order_reference: 'ORD-123456', apm_config: {}, payment_method: this.selected }; try { const res = await this.liteCheckout.payment(checkoutData); console.log('Payment response:', res); alert('Payment successful'); } catch (err) { console.error('Payment error:', err); alert('Payment failed'); } finally { this.loading = false; } } }
Notes
- You must call
injectCheckout()before making a payment. - Always use a valid
returnUrlto support 3DS and APM flows. - If using
mercadopagooroxxopayAPM, consider passingapm_configwith extra info. - The method
verify3dsTransaction()can be used to retrieve the latest status of the transaction after the payment is completed and the user returns to your site.
ℹ️ These examples assume that all required third-party scripts (Skyflow, Openpay, etc.) are already included. See Integration Requirements for details on loading the correct
<script>tags.
Last updated on