People who ask how to build a payment gateway from scratch usually mean the whole stack, and you rarely need to write all of it. If you're wondering how to start your own payment gateway, you can follow one payment from checkout to the bank below and see which parts to build, which to license and which to rent.
Before you start
A gateway routes payment requests and doesn't settle funds itself, so agree with your acquirer or PSP how settlement works before you write code. Have these ready:
- the countries and currencies you'll accept
- the card brands and local methods your customers use
- a named contact at one or more acquirers or PSPs who can issue test credentials
- an owner for PCI DSS, whether that's a person or an outside assessor
- a rough monthly payment volume, even if it's a guess
- a decision on who the gateway serves: your own sites only, or merchants who are not you
With those answers you can pick a core and estimate effort. Without them, any quote you collect is a guess.
Step by step: how to create a payment gateway
1. Decide who sends payments to the gateway
A gateway for your own online store is a smaller job than one that other businesses connect to. Merchants who aren't you need their own accounts, fee settings and reports. That merchant layer adds onboarding, pricing and reporting, so estimate it as separate work. Write down which one you're building before anything else.
2. Line up acquirers and write down what each one accepts
Ask each acquirer which card brands and currencies it covers, how it reports declines and what its test environment looks like. Put the answers in one sheet. It becomes your first routing table, so a few tidy notes here save hours in step 4.
3. Choose how you get the core: build, license or rent
You have three options. Writing the core yourself gives total control and the longest road. Buying source code gives you a working base that your team then owns, with maintenance, upgrades and support landing on you. Renting a white label platform gives you a running core. Then the work is branding and configuration. Our page on gateway software options lays out the trade-offs in more detail.
What you pay for is much the same in all three: people, servers and upkeep. Development projects are quoted, not listed, so ask for a scoped estimate against the sheet from step 2.
4. Design the route of one payment
Draw one card payment on paper. The customer enters card details, the gateway validates them, the core picks an acquirer, sends the authorization, reads the answer and returns an approval or decline to your checkout. Then add the second acquirer, and write what picks between them. Even a first version benefits from a rule as simple as "cards from country A go to acquirer one".
5. Keep card data out of your own systems
The simplest design is a hosted payment page or an embedded field that sends card data straight to a vault, so your servers see only a token. Every system that touches card numbers, and every system that can affect their security, falls under PCI DSS. The PCI Security Standards Council publishes the standard, and your acquirers will ask which validation level applies to you.
6. Write the failure rules before launch
Decide what happens on a soft decline, a timeout and a provider outage. Does the payment go to the second acquirer, and how many tries does one payment get?
A timeout is the risky case, since the first acquirer may already have approved the payment and simply been slow to say so. Link every attempt to one order with an internal ID, and confirm the first attempt's status with its provider before you send another authorization.
7. Test against sandboxes, then with real cards at low volume
Run every case in the sandbox: approval, hard decline, soft decline, timeout, a malformed response. Then go live with a small slice of real traffic, such as your own staff's purchases and one merchant. Compare each payment against the acquirer's settlement report.
8. Run it: monitor, reconcile and add routes
After launch, the job is watching approval rates, declines by reason, response times and settlement matches for each acquirer. Add each new acquirer as a route once its connector and response mapping are ready. Can't see these numbers in one place by week two? Add reporting before you add volume.
What breaks and how to catch it
Most early trouble comes from the seams between acquirer, core and checkout. The table below lists five failures worth testing for, each with a first fix.
| Problem | Symptom | Fix |
|---|---|---|
| Acquirer answer isn't mapped | Customers see "error" on a plain decline | Map every acquirer response code to one of your own reasons |
| Timeout treated as decline | A customer is charged twice after retrying | One payment ID across attempts, plus a status check before retrying |
| Raw card data in logs | PCI scope grows to cover your log store | Tokenize before logging, and scan logs for card number patterns |
| One acquirer for everything | A bank outage stops all sales | Connect a second acquirer and a fallback rule before launch |
| No settlement match | Payments approved but money missing | Reconcile each acquirer's report against your own records daily |
Test these five cases in the sandbox before you raise live traffic, and name an owner for each. The rules from step 6 should exist before launch, not after the first incident.
Where the platform does these steps
Steps 3 to 8 are what a switching core exists to do. We run one. You connect your acquirers and PSPs, set routing and fallback rules, get one record per payment and brand the payment page and admin panel as your own, with a payment team of ours helping on acquirer selection and configuration.
For a gateway with merchants of its own, the white label gateway adds the merchant layer from step 1.