Accepting a Credit Card Payment on your Website

Accepting a Credit Card Payment on your Website

As a developer, use Stax.js to accept a credit card payment on your website and check the payment result.

The payment flow tokenizes the card (securely stores its details and returns a payment method ID) and attempts to charge it. You can optionally provide additional payment details for Level 2 processing (processing that uses tax and purchase-order data to qualify eligible payments for specific processing rates).

Add Stax.js to your site

Add the script shown below to the <head> of your HTML file.

<script src="https://staxjs.staxpayments.com/staxjs-captcha.js"></script>

Run these examples together on the same HTML page. Create the form from the Create Payment Form tab before running the initialization JavaScript, so the field containers exist. Then load the card fields, register the form event handlers, define extraDetails, and register the payment handler.

Initialize Stax.js

  1. In Stax Pay > Apps > API Keys, copy your Web Payments Token (public key). Do not use your private API key in browser code.
  2. Initialize your Stax.js instance with the StaxJs class. Enter your public token when the example prompts you.

Note: Passing the number and CVV into the instance of staxjs generates the secure iFrame around these two fields, keeping sensitive card information from touching your servers.

// Copy your public token from Stax Pay > Apps > API Keys.
const webPaymentsToken = window.prompt("Enter your Web Payments Token (public key):");
if (!webPaymentsToken || !webPaymentsToken.trim()) {
  throw new Error("A Web Payments Token is required to initialize Stax.js.");
}

var staxjs = new StaxJs(webPaymentsToken.trim(), {
  number: {
    id: 'card-number',     // the html id of the div you want to contain the credit card number field
    placeholder: '0000 0000 0000 0000',    // the placeholder the field should contain
    style: 'height: 30px; width: 100%; font-size: 15px;',    // the style to apply to the field
    type: 'text',    // the input type (optional)
    format: 'prettyFormat'    // the formatting of the CC number (prettyFormat || plainFormat || maskedFormat)
  },
  cvv: {
    id: 'card-cvv',    // the html id of the div you want to contain the cvv field
    placeholder: 'CVV',    // the placeholder the field should contain
    style: 'height: 30px; width: 100%; font-size: 15px;',    // the style to apply to the field
    type: 'text'    // the input type (optional)
  }
});

Did this page help you?