Free guide for developers & agencies

Payment Gateway Integration Guide for Websites and Apps

How to integrate a payment gateway the right way: the integration methods compared, how each one affects your PCI scope, the official NMI and Authorize.net tools, code you can copy, sandbox testing and a printable go-live checklist.

1ChooseThe right integration method
2Build and testTokenize, charge, verify webhooks
3Launch25-point go-live checklist
Key takeaways

Payment gateway integration in one minute

Pick the method firstHosted page, hosted fields, direct API, plugin or virtual terminal: the method decides your effort, your checkout design and your PCI workload.
Keep card data off your serverTokenize in the browser or use a hosted form. Your server only ever handles a token, which keeps PCI scope small.
Test before you launchBoth NMI and Authorize.net offer sandboxes. Test sales, declines, refunds and webhooks before switching to live keys.
You still need a merchant accountA gateway moves the transaction; a merchant account lets you get paid. You need both before you go live.
The basics

What is payment gateway integration, and how does it work?

Payment gateway integration is connecting your website, app or software to a payment gateway so customers can pay by card or bank account. The gateway securely carries each payment from your checkout to the processor and card networks, then returns an approval or decline in a few seconds.

1Customer paysThe customer enters card or bank details in a secure form on your checkout.
2Data is tokenizedThe gateway’s script or hosted form swaps the card details for a one-time token.
3Your server chargesYour backend sends the token, amount and order ID to the gateway API with your private key.
4Bank authorizesThe processor and card network ask the customer’s bank to approve or decline.
5You get the resultThe API response and webhooks update the order; approved funds settle to your merchant account.
Before you start

What you need to integrate a payment gateway

Gather these first so development doesn’t stall waiting on approvals. Not sure how the pieces fit? Read merchant account vs payment gateway.

Developer writing payment gateway API integration code on a laptop
  • An approved merchant account — the account that receives your card funds. Merchant accounts are approved through underwriting.
  • A gateway account — such as NMI or Authorize.net, linked to that merchant account.
  • Sandbox credentials — a free test account so you can build without moving real money.
  • API credentials — a public key for the browser and a private key for your server only.
  • An HTTPS website — payment scripts and forms must load over a secure connection.
  • A plan for PCI DSS — know which self-assessment questionnaire your method will put you in.
Integration methods

5 ways to integrate a payment gateway, compared

Every gateway offers several ways to connect. The right one depends on where customers pay, how much design control you want and how much security work you can take on.

Payment gateway integration methods compared
MethodHow it worksCheckout controlDev effortTypical PCI SAQ
Hosted payment pageCustomer is sent to (or shown in a pop-up) a payment page hosted by the gateway.Low to medium (logo, colors, fields)LowSAQ A
Hosted fields / JS tokenizationGateway script turns card details into a token on your own page; your server charges the token.HighMediumSAQ A or A-EP, depending on how the form is built
Direct API (server-to-server)Card data is collected and sent by your own server.FullHighSAQ D (largest scope)
E-commerce platform pluginAn extension connects your store platform to the gateway.Depends on the pluginLowDepends on whether the plugin uses hosted fields or a hosted page
Virtual terminal and invoicesStaff key in payments in the gateway portal, or send invoices and payment links.None neededNoneSAQ C-VT for keyed virtual terminal payments
PCI DSS

How your integration method changes your PCI scope

PCI DSS applies to every business that accepts cards. Under PCI SSC guidance, SAQ A needs every element of the payment page to come from a PCI DSS compliant service provider. SAQ A-EP covers e-commerce sites that don’t receive card data but control how it reaches the processor. Your acquiring bank confirms which questionnaire you file.

  • SAQ A — hosted payment pages and gateway-hosted forms. Authorize.net says Accept Hosted lets you keep “SAQ-A level PCI compliance”.
  • SAQ A-EP — your own payment form that sends card data straight from the browser to the gateway. Authorize.net describes Accept.js with your own form as a “PCI-DSS SAQ A-EP solution”.
  • SAQ D — card data passes through your servers. Avoid this unless you truly need it.
  • Keep scripts in check — whatever the method, limit and monitor the scripts that run on pages with your payment form.
Free tool

Which integration method fits your project?

Answer four quick questions to see the method we’d recommend, the typical PCI questionnaire, and the matching NMI and Authorize.net tools.

1Where will customers pay?
2How much control do you want over the checkout design?
3Will you charge customers again later (subscriptions or saved cards)?
4Who will build it?
Recommended

Hosted payment page

Developer effort
Typical PCI SAQ
With NMI
With Authorize.net
Next steps

    A starting point, not a compliance ruling. Your acquiring bank confirms which PCI SAQ applies.

    NMI and Authorize.net

    Official integration tools for NMI and Authorize.net

    Payment Circle sets merchants up on both gateways. Here is what each one offers developers, based on their own documentation. For a feature comparison, see NMI vs Authorize.net.

    NMI integration

    NMI recommends its newer tools for new builds and keeps its classic APIs for existing integrations.

    • Payment Component — a drop-in payment UI that tokenizes card, ACH and digital-wallet details in the browser. NMI recommends it for new integrations.
    • NMI REST API — your server charges the token using your private API key, which must never appear in client-side code.
    • Hosted Payment Page — NMI says no payment data touches your servers.
    • Collect.js and the classic Payment API — for existing integrations. Collect.js tokens are single-use and expire after 24 hours.
    • Customer Vault and recurring billing — store payment details as tokens and run subscriptions.
    • Sandbox — build against NMI’s sandbox environment before switching to production keys.

    Authorize.net integration

    Authorize.net’s Accept suite covers hosted and self-hosted checkouts, plus a full API.

    • Accept Hosted — a mobile-optimized hosted form shown by redirect, lightbox or embedded iframe. Its form token is valid for 15 minutes.
    • Accept.js — tokenizes card data on your page into a payment nonce (opaqueData) that is valid for 15 minutes. Needs your API Login ID and Public Client Key, and an HTTPS page.
    • API — createTransactionRequest with types such as authCaptureTransaction and authOnlyTransaction.
    • Customer Profiles and Recurring Billing (ARB) — stored payment profiles and subscriptions.
    • Webhooks — event notifications signed with HMAC-SHA512 in the X-ANET-Signature header.
    • Sandbox — apitest.authorize.net for testing and api.authorize.net for production.
    Step by step

    How to integrate a payment gateway in your website

    The integration process, from sandbox to live

    These steps apply to most gateways and most stacks. Plan one to three weeks for a custom checkout, including testing and approvals.

    Customer entering card details at an online checkout on a laptop
    • 1. Choose your method — use the tool above and confirm the PCI SAQ with your acquirer.
    • 2. Open a sandbox — create test credentials and keep them separate from live keys.
    • 3. Build the payment form — load the gateway’s hosted page, hosted fields or tokenization script over HTTPS.
    • 4. Charge from your server — send the token, amount and your order ID to the gateway API with your private key.
    • 5. Handle every response — approvals, declines, errors and timeouts, with clear messages for the customer.
    • 6. Add webhooks — verify each notification’s signature, then update orders, refunds and subscriptions.
    • 7. Turn on fraud tools — AVS, CVV, velocity rules and 3-D Secure where available.
    • 8. Test, then go live — run the checklist below, switch to production keys and endpoints, and watch the first transactions.

    Example: charge an Accept.js payment nonce (Authorize.net)

    After Accept.js returns the nonce in the browser, your server sends it to https://apitest.authorize.net/xml/v1/request.api (sandbox) or https://api.authorize.net/xml/v1/request.api (live). The nonce stands in for the card details.

    JSON request: createTransactionRequest
    {
      "createTransactionRequest": {
        "merchantAuthentication": {
          "name": "YOUR_API_LOGIN_ID",
          "transactionKey": "YOUR_TRANSACTION_KEY"
        },
        "refId": "order-1042",
        "transactionRequest": {
          "transactionType": "authCaptureTransaction",
          "amount": "49.00",
          "payment": {
            "opaqueData": {
              "dataDescriptor": "COMMON.ACCEPT.INAPP.PAYMENT",
              "dataValue": "PAYMENT_NONCE_FROM_ACCEPT_JS"
            }
          }
        }
      }
    }

    Example: verify a webhook signature

    Authorize.net signs each webhook with an HMAC-SHA512 hash of the body using your Signature Key, sent in the X-ANET-Signature header. Reject any notification whose hash doesn’t match, and reply with HTTP 200 quickly. Authorize.net retries failed deliveries and can mark a webhook inactive.

    Node.js / Express
    // Node.js (Express): verify an Authorize.net webhook before trusting it
    const crypto = require("crypto");
    
    app.post("/webhooks/authorize-net", express.raw({ type: "application/json" }), (req, res) => {
      const sent = String(req.get("X-ANET-Signature") || "").replace(/^sha512=/i, "").toUpperCase();
      const expected = crypto
        .createHmac("sha512", process.env.ANET_SIGNATURE_KEY)
        .update(req.body) // raw body, exactly as received
        .digest("hex")
        .toUpperCase();
    
      const ok = sent.length === expected.length &&
        crypto.timingSafeEqual(Buffer.from(sent), Buffer.from(expected));
      if (!ok) return res.sendStatus(401);
    
      res.sendStatus(200);            // answer fast, then process
      const event = JSON.parse(req.body.toString("utf8"));
      queueJob(event.eventType, event.payload); // e.g. net.authorize.payment.authcapture.created
    });
    Testing

    How to test your payment gateway integration

    Test every path, not just a successful sale. Sandbox transactions never reach a bank, so you can try declines, mismatches and refunds safely.

    Authorize.net sandbox test values
    Authorize.net sandbox testWhat to enterExpected result
    Visa approval4111111111111111, any future dateApproved
    Mastercard approval5424000000000015, any future dateApproved
    American Express370000000000002, 4-digit card codeApproved
    Discover6011000000000012Approved
    General declineZIP code 46282Declined (response code 2)
    AVS mismatchZIP code 46205AVS result N (no match)
    CVV mismatchCard code 901CVV result N (no match)

    Testing tips that save launch-day surprises

    These values come from Authorize.net’s testing guide. NMI publishes its own test data in its developer docs, so use NMI’s values when you test against the NMI sandbox.

    • Keep the sandbox in live mode — Authorize.net notes that test-mode transactions aren’t stored and return a transaction ID of zero.
    • Don’t mix credentials — sandbox and production keys aren’t interchangeable.
    • Load the right script — use the sandbox version of Accept.js (jstest.authorize.net) while testing.
    • Test webhooks end to end — including a bad signature, which your endpoint should reject.
    • Test refunds and voids — on both settled and unsettled transactions.
    Free checklist

    Payment gateway go-live checklist

    Tick what your integration already covers, then print it or save it as a PDF for your team or client handover.

    Accounts and credentials 0 of 4

    Checkout and PCI scope 0 of 5

    Transactions 0 of 5

    Fraud and security 0 of 4

    Webhooks and recurring billing 0 of 3

    Go-live 0 of 4

    FAQ

    Payment gateway integration: common questions

    How long does payment gateway integration take?

    A plugin or hosted payment page can be live in a day or two once your merchant account is approved. A custom checkout with tokenization, webhooks and recurring billing usually takes one to three weeks, including testing.

    Do I need a merchant account to integrate a payment gateway?

    Yes. The gateway carries the transaction, but a merchant account is what lets you accept card payments and receive the funds. Many businesses get both together.

    Which integration method is most secure?

    Methods that keep card data off your servers, such as hosted payment pages and hosted fields or tokenization, carry the least risk and the smallest PCI scope.

    Can I use NMI or Authorize.net with WooCommerce or another platform?

    Usually, yes. Most popular e-commerce platforms have extensions for major gateways. Choose one that uses a hosted page or tokenization, and check that it’s actively maintained.

    What is tokenization in payment processing?

    Tokenization replaces card details with a random token that is useless if stolen. Your server stores or sends the token, and the gateway maps it back to the real card.

    How do I test a payment gateway integration?

    Use the gateway’s sandbox with its published test card numbers and triggers for declines and mismatches. Test sales, refunds, voids, webhooks and failed payments before switching to live credentials.

    Sources

    Sources and further reading

    Related guides

    Building payments for your clients? We set up merchant accounts with NMI or Authorize.net gateways for agencies, developers and software companies, and help with sandbox and go-live. Call (571) 274-7950.

    Talk to our team →