Skip to main content
When you call paymentForm.init(...), Flex accepts three callback functions. The main payment result reaches your frontend through responseCallback(response).
Use responseCallback(response) as the main entry point for frontend results. The returned JSON follows the E-commerce authorization API structure for the payment method selected in Flex.

Callbacks available

responseCallback

Runs when the flow reaches a business outcome and returns the JSON response.

trackingCallback

Runs for flow events such as method changes, clicks or progress through the form.

onErrorCallback

Runs when a technical error occurs while loading or running the component.

Example of implementation

How to interpret responseCallback

The field response.payment_method indicates what reference to PayIn you have to use to interpret the JSON response returned by Flex.
Do not use response.meta.status.code to decide whether a payment was approved or declined. It only describes service processing. Read response.transaction.state and confirm the result from your backend using a query or server notifications for the payment method.
The response object follows the contract of Card authorization API.If your flow uses Redirect or 3DS authentication outside the same screen, complete this reading with Considerations for Redirect methods.
Use trackingCallback for events and onErrorCallback for technical failures. Neither replaces the business logic built around responseCallback and backend confirmation.

Life cycle of the instance

The following examples use unmountFlex() from the responsive example. Adapt cleanup to your presentation: embedded, popup or expanded.
paymentForm.terminate?.() ends Flex’s internal processes, listeners and resources. This is different from removing the form from the DOM (flexContainer.innerHTML = "") and applies to every presentation type.
The ?. operator calls terminate() only if the method exists. This avoids errors if the loaded Flex version does not implement it.

When to unmount each presentation

In all 3 cases, first process any outstanding result and then run unmountFlex() before updating the visual presentation.
Do not modify the internal styles of Flex. Call unmountFlex() When you withdraw the form, regardless of whether it’s embedded, into a popup or an expanded view.

Your own result screen

With settings.display_result_screen: false, Flex does not display its final screen. Your application must receive the response, evaluate the transaction state and display its own result screen.
1

Mount form

paymentForm.init(...) mounts Flex inside the container.
2

Receives result

Flex runs responseCallback(response). Read response.transaction.state and perform the relevant business validations.
3

Show your screen

Save response in your application state, then navigate to or render your result screen.
4

Unmount Flex

After processing the result, call terminate(), clear the container and update the embedded, popup or expanded presentation.
Do not call terminate() before receiving and processing responseCallback(response). Ending the instance early can interrupt the flow and lose the result Flex was about to return.

Reusable cleanup

Encapsulate initialization and cleanup in a framework-independent controller. Use it in plain JavaScript or connect it to the lifecycle of React, Vue, Angular or another framework.

JavaScript

Call destroy() before withdrawing the container from the page.

SPA integration

Call destroy() on route changes or when unmounting the view.

Dynamic presentation

Call it when hiding the embedded block, closing the popup or collapsing an expanded view.
container.replaceChildren() clears the container, like container.innerHTML = "", without depending on a framework.
terminate() does not return the payment response. The result arrives through the first callback passed to paymentForm.init(...). See Capture callback functions to interpret and confirm the operation.

Management of closure with show_close_button

Set settings.show_close_button: true to display the native Flex close button. This works with embedded, popup and expanded presentations.
When the customer presses the button, Flex sends cerro el carrito through onErrorCallback. Although it uses the error callback, this message represents a voluntary customer action, not a technical failure. Keep this literal message unchanged in code.

Show the button

Enable show_close_button in settings.

Handle the event

Identify the exact message cerro el carrito in onErrorCallback.

Close presentation

Call onClose() to unmount Flex and update the interface.
Implement a separate branch for voluntary closure and handle other messages as technical errors:
The closing flow is show_close_button → onErrorCallback → onClose() → unmountFlex(). hideFlexPresentation() represents the visual logic of your application: remove the embedded block, hide the popup or collapse an expanded view.
Call onClose() only after matching the exact message cerro el carrito. Continue handling any other value received by onErrorCallback as a technical error.

5. Testing and production

Review security, functional tests and production readiness.