Skip to content
payrocdevelopers

Close a Hosted Fields session

Call the destroy method in your JavaScript to close an idle Hosted Fields session before starting a new one.

Important: To call the destroy method, you must be using one of the following versions of our Hosted Fields JavaScript library:

  • Test - 1.7.0.261457
  • Production - 1.7.0.261471

To close an idle session of Hosted Fields, call the destroy method in your JavaScript.

JavaScript
const hostedFields = new Payroc.hostedFields(options);
hostedFields.destroy(); 

After calling the destroy method, you must start a new Hosted Fields session before you can take payment from the customer. For more information about how to generate a session token, go to Authenticate your Hosted Fields session.

Note: You don't need to use this method for every integration, but it is considered good practice in scenarios where Hosted Fields might run on more than one session, for example, in single-page applications.

What does the destroy method do?

  • Removes our event listener associated with the session, so that we don't receive messages from more than one session.
  • Prevents further communication between the Hosted Fields JavaScript library and your Hosted Fields.
  • Helps to avoid memory leaks and duplicate event handling.

Browse guides

Search documentation

API reference169
Guides118
Knowledge38
legal1
Solutions32
Workflows74
↑↓highlight↵openView all search results

Menu

Theme

Sign out

Your saved plans remain in your organization. This browser’s private draft and account view will be cleared.

Talk to an engineer