Embed events
Embed accepts an onEvent
parameter that can be used to listen to certain
events emitted from the form.
setup({
element: '.container',
...,
onEvent: (name, data) => {
...
}
})
Embed emits the following events:
argumentError
Returned when the initial input (element
, options
) are incorrectly formatted or missing.
{
"code": "argumentError",
"option": "currency",
"message": "must be a valid number"
}
optionsLoaded
Returned when options are loaded. Stored options include the id
.
[
{
"id": "...",
"method": "card",
"mode": "card"
},
{
"method": "card",
"mode": "card"
}
]
formUpdate
Returned when the form updates. Currently this only informs the developer if the form is valid.
{
"valid": false
}
transactionCreated
Returns a full transaction object when Gr4vy accepted the transaction,
regardless of its status. Be aware that this can be a pending or declined
transaction. To track API failures please use the transactionFailed
event.
{
"type": "transaction",
"id": "8724fd24-5489-4a5d-90fd-0604df7d3b83",
"status": "pending",
...
}
transactionCancelled
Returned when a buyer has explicitly canceled a transaction, e.g. closing a popup or dismissing Apple Pay. This is currently not supported for 3-D Secure transactions and should not be conflated with transaction being declined or an error occurring.
{
"type": "transactionCancelled"
}
transactionFailed
Returned when an API call fails to create a transaction due to a client or
server error. In other words, this event is raised when incorrect data (like an
invalid JWT) is passed to the Gr4vy API and a HTTP status code in the 4XX
or
5XX
range is returned.
To catch failed or declined transactions due to
downstream issues with the payment service, please subscribe to the
transactionCreated
event.
{
"type": "error",
"code": "unauthorized",
"status": 401,
"message": "No valid API authentication found"
}
apiError
Returned when the form encounters an API error.
{
"type": "error",
"code": "unauthorized",
"status": 401,
"message": "No valid API authentication found",
"details": []
}
Was this page helpful?