Card Not Present
The first step in collecting payments in a web application is to use the credit card collection form component to capture credit card information from the customer. Once the credit card information is captured, a nonce will be provided where you can exchange it for a token and process the payment further using the Moolah payments API.
Setting up the credit card collection form
- To begin working with credit card collection form, you must insert the following scripts on your webpage's frontend.
<script
type="text/javascript"
src= "https://collect.commerce.godaddy.com/sdk.js"
async
defer
></script>2. You can then instantiate the credit card collection component
var collect = new TokenizeJs("<businessId>", "urn:aid:df5ae5f0-6360-4024-819f-b7a17b92d5c7");The business Id is unique for each business that receives a merchant account, and is provided to you by Moolah on boarding your merchant.
3. Create an empty DOM element for the collect component to mount the credit card form.
<html>
<head></head>
<body>
<div id="card-element">
<!-- Credit card form iFrame will be inserted here -->
</div>
<button>Pay</button>
</body>
</html>Credit card collection methods
Once you have created the collect object, and prepared your DOM to mount the form you can call the following method to mount the form in the DIV.
collect.mount
collect.mount("card-element", document, options);The mount method takes the following options:
const options = {
iFrame: {
width: "500px",
height: "400px",
border: "1px",
borderRadius: "4px",
boxShadow: "0 7px 14px rgba(50, 50, 93, 0.1), 0 3px 6px rgba(0, 0, 0, 0.08)"
},
style: {
theme: "default" // or "customer" (alternative default theme)
},
displayComponents: {
firstName: false, // set to true to show the field
lastName: false,
emailAddress: false,
submitButton: false,
showEndingPage: true, // controls the ending page
labels: false
},
fields: {
emailAddress: customerEmail,
firstName: firstName,
lastName: lastName,
zipCode: zipCode
},
additionalFieldsToValidate: [], // fields to validate
enableReCaptcha: true,
// Card on file — required to be true if you intend to store the card.
// Without this, transactions against a stored card may fail.
enableCardOnfile: true,
// If true, the save-card checkbox is pre-checked and cannot be unchecked.
forceSaveCardOnFile: false,
// Merchant details shown in the card agreement disclosure.
cardAgreementOptions: {
businessName: "string",
businessPhone: "string"
},
reCaptchaOptions: {
type: "DEFAULT" // "DEFAULT" | "TEXT"
}
};Card On File
If you plan to store the customer's card for future payments (recurring billing, payment plans, one-click checkout), the card on file flow must be enabled on the collection form before the nonce is generated. A nonce created without card on file consent cannot be exchanged for a reusable token — transactions against a stored card may fail if consent was not captured at collection time.
Enabling card on file on the form
onst options = {
// ...
enableCardOnfile: true, // required if you intend to store cards
forceSaveCardOnFile: false, // set true to lock the checkbox in the checked state
cardAgreementOptions: {
businessName: "Smile Dental Group", // shown in the agreement text
businessPhone: "(949) 555-0123"
}When enableCardOnfile is true, the form displays a "save card on file" checkbox along with a card agreement disclosure. The agreement text is populated with the businessName and businessPhone you provide in cardAgreementOptions these should be the merchant's legal name and a customer-reachable phone number, as this constitutes the cardholder's stored-credential consent record. If forceSaveCardOnFile is true, the checkbox is pre-checked and cannot be unchecked by the customer. Use this only for flows where saving the card is a condition of the service (e.g. enrolling in a payment plan), and make sure that's disclosed to the customer elsewhere in your UI.
Get nonce and the card agreement
when you exchange this nonce for a token via the Moolah Payment API, the resulting token is a multi-use (card on file) token that can be stored and charged for subsequent transactions. If the customer did not check the box (and forceSaveCardOnFile sdis false), the nonce yields a single-use token only — attempting to reuse it or store it will fail.
The card agreement acceptance (status, email, id) is recorded as part of tokenization and serves as your evidence of cardholder consent for stored-credential transactions, as required by card brand rules.
Retrieving a nonce
Once the credit card information is entered by the customer, you can retrieve a nonce that is used to process the payment further with the Moolah Payments API. To collect a nonce use the following method:
collect.getNonce
collect.getNonce({});The getNonce method will either fire an error or nonce event
To receive the nonce on success:
collect.on("nonce", response => {
console.log('collect on get nonce', response.data.nonce);
})To handle an error on the retrieval of a nonce:
collect.on("error", err => {
console.log("collect on error", err);
});That's it for the client side of your web application! Once you have a nonce, you can turn your nonce into a token which is used for processing transactions using the Moolah Payments API .