Global Payments Example
HTML
<script src="https://hps.github.io/token/gp-1.0.0/globalpayments.js"></script>
<form id="payment-form" action="/charge" method="get">
<!-- Other input fields to capture relevant data -->
<label for="billing-zip">Billing Zip Code</label>
<input id="billing-zip" name="billing-zip" type="tel" />
<!-- Target for the ACH/eCheck form -->
<div id="eCheck"></div>
</form>
JavaScript
// Configure account
GlobalPayments.configure({
publicApiKey: "pkapi_cert_dNpEYIISXCGDDyKJiV"
});
// Create Form
const eCheckForm = GlobalPayments.eCheck.form("#eCheck", {style: "blank"});
// form-level event handlers. examples:
eCheckForm.ready(() => {
console.log("Registration of all ACH/eCheck fields occurred");
});
eCheckForm.on("token-success", (resp) => {
// add payment token to form as a hidden input
const token = document.createElement("input");
token.type = "hidden";
token.name = "payment-reference";
token.value = resp.paymentReference;
// submit data to the integration's backend for processing
const form = document.getElementById("payment-form");
form.submit();
});
eCheckForm.on("token-error", (resp) => {
// show error to the consumer
});
// field-level event handlers. example:
eCheckForm.on("card-number", "register", () => {
console.log("Registration of Account Number occurred");
});