← Checkout Web overviewSTEP 04 / 05
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.- CARD
- YAPE
- BANK_TRANSFER
- QR
- CUOTEALO
- PAGOEFECTIVO
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.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.
Your own result screen
Withsettings.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.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
Setsettings.show_close_button: true to display the native Flex close button. This works with embedded, popup and expanded presentations.
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.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.
5. Testing and production
Review security, functional tests and production readiness.

