← Checkout Web overviewSTEP 04 / 05
When you call paymentForm.init(...), Flex It allows you to capture three callback functions. The most important result for front responseCallback(response).
Here.
responseCallback(response) as the main entrance of the result at front. The JSON That you get there reuses the same structure of API of Authorisation - ecommerce for the method of payment chosen within Flex.Callbacks available
responseCallback
It runs when the process gets to a business result and gives you the JSON response.
trackingCallback
It runs for every flow event, as a method change, clicks or user advance within the form.
Failed
It runs after a technical error occurs during the load or performance of 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 object
response following the contract of API from Authorisation with Card.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?.() complete the internal processes, list and resources that maintain the Flex. That operation is different from eliminating the form from DOM (flexContainer.innerHTML = "") and applying to any type of presentation.
The operator
?. run terminate() only when the method exists. That prevents an error if the loaded version of Flex Do not implement that method.When to dismount according to presentation
In all 3 cases, first process any outstanding result and then run
unmountFlex() before updating the visual presentation.
own result screen
When you set upsettings.display_result_screen: false, Flex doesn’t have his final screen. Your application should get the response, evaluate the status of the transaction and display an own result screen.
1
Mount form
paymentForm.init(...) challenges Flex inside the container.2
Receives result
Flex run
responseCallback(response). Read the result from response.transaction.state and conduct related business validations.3
Show your screen
Save the
response at the status of your application and navigate or render the result screen from the merchant.4
Unmount Flex
When the result has been processed, run
terminate(), cleanes the container and updates the presentation drunk, popup or expanded.Reusable cleaning
It encapsulates initiation and dismantling into an independent framework controller. You can use them from pure JavaScript or connect them to React’s life cycle, Vue, Angular or other technologies.JavaScript
Execut
destroy() before withdrawing the container from the page.Implementation SPA
Connect
destroy() to change of path or to dismount vision.Dynamic presentation
Do so by hiding the embossed block, closing the Popup or getting an expanded view.
container.replaceChildren() an empty constore equivalent to container.innerHTML = ""without dependent on a specific framework.
terminate() does not return the payment response. The result always comes with the first call of paymentForm.init(...). Check. Capture callback functions to interpret and confirm the operation.Management of closure with show_close_button
Figuresettings.show_close_button: true to display the native clasp of Flex. That option works with embumbing, pounding and expanding presentations.
cerro el carrito with onErrorCallback. Although using the error call, this message represents a voluntary action by the buyer and not a technical failure.
Show the button
Active
show_close_button inside settings.Play the event
Identifies the exact message
cerro el carrito in onErrorCallback.Close presentation
Execut
onClose() for dismantling 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 get an expanded view.
5. Testing and production
Review security, functional tests and production readiness.

