Express callbacks
API documentation for version 2 and version 3 of the Spreedly Express Javascript API.
Callbacks
Express supports a variety of callbacks that allow developers to be notified on specific events.
onInit
Triggered when init
has successfully completed and Express is ready for display or further configuration.
SpreedlyExpress.onInit(function() {
document.getElementById("pay-button").disabled = false;
});
Callback signature
function()
onViewClose
Triggered when the Express view is closed. This callback is invoked when either the user manually closes the view or unload()
is called.
SpreedlyExpress.onViewClose(function() {
console.log('event: view closed');
});
Callback signature
function()
onPaymentMethod
Triggered when a payment method has been successfully tokenized at Spreedly. The resulting payment method token (and any additional data) should now be sent to your backend server environment for transacting.
SpreedlyExpress.onPaymentMethod(function(token, paymentMethod) {
// Send requisite payment method info to backend
var tokenField = document.getElementById("payment_method_token");
tokenField.setAttribute("value", token);
var masterForm = document.getElementById('payment-form');
masterForm.submit();
});
Callback signature
function(token, formData)
Arguments
Name | Description |
---|---|
token | The token of the newly tokenized payment method. Tokens are alphanumerics in the form M8TBiUmc19cjV16PdMbsj65uViL . |
formData | A map of the data entered into the Express payment form, i.e. “full_name” ,“month” ,“year” |
Updated 15 days ago