Version: Beta

Events

Gr4vy Embed accepts an onEvent parameter that can be used to listen to certain events emitted from the form.

setup({
element: '.container',
...,
onEvent: (name, data) => {
...
}
})

Currently, we Gr4vy Embed emits the following events.

agumentError#

Returned when the initial input (element, options) are incorrectly formatted or missing.

{
"code": "argumentError",
"option": "currency",
"message": "must be a valid number"
}

formUpdate#

Dispatched when the card form changes validity. The card form is invalid if required data, such as card number, is not entered or if a required field is populated with invalid data. If all form fields are populated with valid data the form is valid.

e.g. if the form is valid the onEvent data will be:

true

transactionCreated#

Returns a full transaction object when the transaction was successfully created.

{
"type": "transaction",
"id": "8724fd24-5489-4a5d-90fd-0604df7d3b83",
"status": "pending",
...
}

paymentMethodSelected#

Returns a payment method object when a payment method was selected and in Gr4vy Embed. The method could be a new payment method(e.g. card) or a stored method (e.g. id).

{
"id": "8724fd24-5489-4a5d-90fd-0604df7d3b83",
"method": 'id'
...
}

apiError#

Returned when the form encounters an API error.

{
"type": "error",
"code": "unauthorized",
"status": 401,
"message": "No valid API authentication found",
"details": []
}