Skip to main content
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.
Do not use response.meta.status.code as an approved or refused payer. That code indicates only the result of the service processing or if the response was generated correctly. To validate the payment result, check response.transaction.state and confirms from backend with Consultation or Notificationswith the method of payment.
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.
trackingCallback and onErrorCallback for technical faults. No one replaces the business logic you have to build up about 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?.() 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.
Do not modify the internal styles of Flex. Execut unmountFlex() When you withdraw the form, regardless of whether it’s embedded, into a popup or an expanded view.

own result screen

When you set up settings.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.
Don’t run terminate() before receiving and processing responseCallback(response). If you finish the instance earlier, you can stop the flow and lose the result that Flex He’s been put up.

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

Figure settings.show_close_button: true to display the native clasp of Flex. That option works with embumbing, pounding and expanding presentations.
When the buyer presses the button, Flex send message 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.
It implements an exclusive branch for voluntary closure and preserves other messages as technical errors:
The closing flow is show_close_buttononErrorCallbackonClose()unmountFlex(). hideFlexPresentation() represents the visual logic of your application: remove the embedded block, hide the popup or get an expanded view.
Execut onClose() only after complete message cerro el carrito. Any other value received at onErrorCallback have to continue to manage technical errors.

5. Testing and production

Review security, functional tests and production readiness.