Account.js SDK

If you want an easy way to add GunTab account creation to your app's flow, try our Account.js SDK.

Alpha version

This feature is subject to breaking changes at any time.

What problems does this solve?

Ordinarily, when asking your users to open a free GunTab account, you simply open the "Open an account" page in a new window. However, that requires you to write your own code. Also, when your user is finished opening a GunTab account, the GunTab window remains open while your original window has become outdated.

Our Account.js SDK equips you with pre-written code and an elegant, controllable user experience that allows you to close the GunTab window and bring your user back to an updated page on your site.

How it works

The Account.js SDK should be used to help your buyers open a free GunTab as part of your onboarding flow (or any other flow):

  1. You invoke the Account.js SDK. Optional: Pass user information to pre-fill the form.
  2. The Account.js SDK puts a gray overlay on your window, and opens a popup window for the user to open an account.
  3. After the user successfully opens an account, the Account.js SDK closes the account window, removes the gray overlay on your window, and returns the accountState via JS.
  4. Optional: Before considering a user to be registered with GunTab, your app should perform a server-side call to the Users REST API to confirm.

Script

Load the GunTabAccount class like this:

  
<script src="https://www.guntab.com/sdks/account.js"></script>
  

Usage

The GunTabAccount class has one method: startUserAccount. This method has two arguments:

  1. timeoutSeconds (optional, defaults to 0): The number of seconds before the promise will return a account_state of account_timeout. Set to 0 for unlimited time.
  2. userParams (optional, defaults to {}): The user information you want to pre-filled in the form. Available keys are:
    • first_name
    • last_name
    • email
    • phone_number

The startUserAccount method returns a promise, which resolves with a accountResult object. This object responds to accountState and the possible values are:

Example

  
<script src="https://www.guntab.com/sdks/account.js"></script>

<script>
  function openGunTabAccountWindow() {
    const guntabAccount = new GunTabAccount();
    const userParams = { first_name: 'Fred', last_name: 'Johnson', email: 'f.johnson@example.com', phone_number: '555-555-5555' }; // optional
    guntabAccount.startUserAccount(1800, userParams)
    .then((accountResult) => {
      if (accountResult.accountState == 'open') {
        // Redirect to the next step, which calls the REST API to confirm
      } else {
        // Handle accordingly
      }
    })
    .catch((error) => {
      console.error("Error:", error.message);
    });
  };
</script>

<button onclick="openGunTabAccountWindow()">Open free GunTab account</button>

  

Security warning

Do not rely on any values originating in your client-side Javascript, because that environment cannot be trusted. Instead, confirm server-side via the Users REST API.

Frequently asked questions