Altruon.js reference
Install Altruon.js, see which key goes where, follow the call order, and find every method, callback and style option.
Altruon.js is the browser library that mounts the Altruon payment component in your own page. The component is an iframe that Altruon.js adds to a container element you choose. Your server creates the session and keeps the secret key.
This tab is for lookup. For a walkthrough, start with the Altruon.js quickstart.
Install
<script src="https://cdn.altruon.io/altruon-sdk.min.js"></script>The CDN script is the recommended way to load Altruon.js. It defines the global altruon object.
Keys
An integration uses two keys. Both are in the backoffice under Settings > API Keys.
| Key | Looks like | Where it runs | Used for |
|---|---|---|---|
| Publishable key | pk_sandbox_... | Browser | The first argument of init() |
| Secret key | sk_sandbox_test_... | Your server only | The x-secret-key header on Create a session and Get transaction details |
Never put the secret key in browser code
Create sessions and read transactions from your server. The browser only needs the publishable key and the session_id.
See Authentication for the header format and Sandbox and environments for the URLs of each environment.
Lifecycle
Call the methods in this order.
| Order | Call | What it does |
|---|---|---|
| 1 | init(publicKey, siteName) | Initializes Altruon.js. Call it once per page |
| 2 | on(eventName, callback) | Registers a callback. Register all four before you render |
| 3 | setSession(sessionId) | Binds Altruon.js to the session your server created |
| 4 | setCustomer(), setAddresses(), setBilling(), setPaymentExtra() | Pass the shopper's data to the session. Optional, and allowed before or after step 5 |
| 5 | renderComponent(selector) | Mounts the payment component in your container |
| 6 | processPaymentAndSubscription() | Starts the payment and creates the subscription. Altruon.js never calls it for you |
| 7 | onSuccess, onFailure, onDataRequired, onActionRequired | One of your callbacks receives the outcome |
altruon
.init('pk_sandbox_...', 'your-domain') // 1
.on('onSuccess', handleSuccess) // 2
.on('onFailure', handleFailure)
.on('onDataRequired', handleDataRequired)
.on('onActionRequired', handleActionRequired);
altruon.setSession(sessionId); // 3
altruon.setCustomer({ email: 'jane.smith@example.com' }); // 4
altruon.setAddresses({ billing: { country: 'US' } });
await altruon.renderComponent('#altruon-payment-container'); // 5
payButton.addEventListener('click', () => {
altruon.processPaymentAndSubscription(); // 6
});A session is single use and expires 15 minutes after it is created. After a failed payment, create a new session and repeat from step 3. Do not call init() again.