Customer data
Pass the shopper's name, addresses, tax document and billing details to an Altruon.js session from the browser.
Your checkout form collects the shopper's details. Four setter methods pass them to the session before you trigger the payment. This page shows each one and explains which values the browser cannot set.
What you can set from the browser
A session needs four values before a payment can start. Three of them are fixed when your server creates the session.
| Data | Required | Where you set it |
|---|---|---|
Currency (paymentData.currency) | Yes | Create Session only. The browser cannot set or change it |
Line items (billingData.lineItems) | Yes | Create Session only. The browser cannot change them |
Billing platform (billingData.billingPlatformId) | Yes | Create Session only. The browser cannot change it |
| Billing address country | Yes | setAddresses(), or customerData.billingAddress.country on Create Session |
| Name, email, phone, IP address | No | setCustomer(), or customerData on Create Session |
| Billing and shipping address | No | setAddresses(), or customerData on Create Session |
| Tax document, card type, wallet username | No | setPaymentExtra() |
| Coupon codes | No | Create Session only (billingData.couponCodes). To change them, create a new session |
Apart from the billing address country, every customer field is optional. For the server side, see Create a session. For coupons, see Coupons.
When to call the setters
Call them after setSession() and before processPaymentAndSubscription(). The component can already be on screen: the merchant demo renders it first and calls the setters when the shopper clicks the pay button.
altruon.setSession(sessionId);
await altruon.renderComponent('#altruon-payment-container');
payButton.addEventListener('click', () => {
altruon.setCustomer({ firstName, lastName, email });
altruon.setAddresses({ billing: { street, city, zipCode, country } });
altruon.processPaymentAndSubscription();
});Set the customer
altruon.setCustomer({
firstName: 'Jane',
lastName: 'Smith',
email: 'jane.smith@example.com',
phone: '+1234567890',
ip: '127.0.0.1',
});All five properties are optional strings. Some acquirers use the IP address. See setCustomer for the full list.
Set the addresses
Pass the billing address, and a shipping address if it differs.
altruon.setAddresses({
billing: {
street: '123 Main St',
number: 'Apt 4B',
city: 'New York',
state: 'NY',
zipCode: '10001',
country: 'US',
},
shipping: {
street: '456 Oak Ave',
city: 'Brooklyn',
state: 'NY',
zipCode: '11201',
country: 'US',
},
});country is an ISO 3166-1 alpha-2 code. number holds the apartment, suite or unit. shipping is optional. See setAddresses.
The billing country is required
A payment cannot complete without a billing address country. Set it with setAddresses(), or in customerData when you create the session. If it is missing, onDataRequired reports it.
Set extra payment data
Some payment methods need data that belongs to the payment, not to the customer. Brazilian payment methods such as Pix need a tax document (CPF or CNPJ). UPI needs the shopper's wallet identifier.
altruon.setPaymentExtra({
document: taxDocument, // CPF or CNPJ for Brazilian payment methods
cardType: 'visa', // optional card brand hint
walletUsername: 'user@upi', // wallet or UPI identifier
});The merchant demo sets the document only when the payment is Brazilian:
// PagBrasil (BRL) requires a CPF or CNPJ document on the payment.
if (country === 'BR' || currency === 'BRL') {
altruon.setPaymentExtra({ document: taxDocument });
}All three properties are optional. See setPaymentExtra.
Set billing platform data
setBilling() passes billing platform data from the browser.
altruon.setBilling({
lineItems: [{ type: 'plan', id: '{plan-id}', quantity: 1 }],
platformId: '{billing-platform-id}',
platformName: 'stripe',
});lineItems and platformId are required in this object. platformId is the same connection ID that the Create Session API calls billingData.billingPlatformId. Both values must be on the session when your server creates it, and the browser cannot change them afterwards. platformName (for example stripe or chargebee) and frequency (for example monthly or yearly) are optional. See setBilling.
Collect data progressively
You do not need every value before you show the component. Initialize early, keep the form values in an object, and pass them to the session when the shopper moves on.
altruon
.init('pk_sandbox_...', 'your-domain')
.on('onSuccess', (data) => { window.location.href = `/success?trx_id=${data.transactionId}`; })
.on('onFailure', (error) => { showError(error.message); });
altruon.setSession(sessionId);
const customer = {};
for (const field of ['email', 'firstName', 'lastName']) {
document.getElementById(field).addEventListener('blur', (event) => {
customer[field] = event.target.value;
});
}
// The shopper finished the details step: pass the data and show the component.
document.getElementById('continue-button').addEventListener('click', () => {
altruon.setCustomer(customer);
altruon.renderComponent('#altruon-payment-container');
});
// The shopper entered the payment details: start the payment.
document.getElementById('pay-button').addEventListener('click', () => {
altruon.processPaymentAndSubscription();
});When a value changes later, call the setter again with the complete object.
When data is missing
If a payment cannot complete because a value is missing, Altruon.js calls onDataRequired with the names of the missing fields, for example billingAddress.zipCode,phone,document. Collect them, call the matching setter and trigger the payment again. See Data required.
Test it
In the sandbox, leave a required field empty and click your pay button. onDataRequired fires and requiredFields names what is missing. Fill the field in, call the setter and trigger the payment again.