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):
- You invoke the Account.js SDK. Optional: Pass user information to pre-fill the form.
- The Account.js SDK puts a gray overlay on your window, and opens a popup window for the user to open an account.
-
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. - 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:
-
timeoutSeconds
(optional, defaults to 0): The number of seconds before the promise will return aaccount_state
ofaccount_timeout
. Set to 0 for unlimited time. -
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:
-
account_open
- The user successfully opened an account, although it is not yet email-verified. -
account_timeout
- The user failed to open an account withintimeoutSeconds
.
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
-
What if nothing happens when the account window is supposed to open?
If nothing is happening,
make sure
startUserAccount
is being triggered by user interaction. Next, look for errors in the Javascript Console. - How large is the account window when opened? On mobile devices, the window is ordinary full-screen tab. On desktop and laptop devices, the account window is up to 1200 pixels wide, and is 80% height.
-
What should be done with the
account_state
value? Possibly nothing. While this value is provided for your information, you should confirm the transaction status via the REST API before canceling/holding/fulfilling an order. - Can GunTab help with our code implementation? Yes, a GunTab software developer can consult with you if you need help implementing this SDK.