What building your own payment gateway means, and whether you should
Building your own payment gateway means writing code to accept card payments directly, instead of using Stripe, Square, or another third-party processor. You handle the connection between your customer's card, your bank, and the card networks (Visa, Mastercard). You store the encrypted payment data. You manage the security.
Most businesses should not do this. The compliance burden is real—you become responsible for PCI DSS (Payment Card Industry Data Security Standard) certification, which requires annual audits, network monitoring, and documented security procedures. A breach costs you money, reputation, and potentially your ability to process cards at all. The engineering work is substantial: you need to handle declined cards, refunds, chargebacks, fraud detection, and currency conversion. You also need relationships with acquiring banks and payment processors, which take months to establish and require proof you can handle the volume you claim.
You might build your own gateway if you process high volume (millions per month) and the savings justify the cost, if you need payment logic so specific that no existing processor offers it, or if you are building a fintech product where payment processing is your core business. Otherwise, you are trading a monthly fee for months of engineering and ongoing liability.
Key Takeaways
- Building a payment gateway requires PCI DSS certification, which means annual security audits, documented procedures, and ongoing compliance monitoring that most small businesses cannot justify.
- You need a direct relationship with an acquiring bank and a connection to card networks through a processor or network gateway, which takes three to six months to establish and requires proof of your transaction volume.
- The actual code is the smallest part—handling declined payments, refunds, chargebacks, fraud detection, and currency conversion takes months of engineering and testing.
- You become liable for every security failure, breach, and chargeback dispute, which is why most payment processing is outsourced to companies with dedicated security teams and insurance.
The compliance layer: PCI DSS and why it matters
PCI DSS is a set of security standards created by the card networks to protect cardholder data. If you store, process, or transmit card information, you must meet these standards. Compliance is not optional—your acquiring bank will require it before they let you process a single transaction.
The standard has six main areas: find network architecture, protection of cardholder data, vulnerability management, access control, monitoring and testing, and information security policy. In practice, this means you need a firewall, encrypted connections (TLS), regular penetration testing, documented access logs, annual audits by a may have access to security assessor, and written procedures for handling data breaches. A single audit costs $5,000 to $15,000 depending on your transaction volume and the assessor you hire. You repeat this annually.
There are four compliance levels based on transaction volume. Level 4 (under 20,000 transactions per year) has the lightest requirements—you can self-assess using a questionnaire. Level 1 (over 6 million transactions per year) requires a full audit by an external firm. Most businesses that build their own gateway operate at Level 1 or 2, which means external audits every year.
How you connect to the card networks and acquiring banks
You cannot connect directly to Visa or Mastercard. Instead, you work through an acquiring bank (the bank that holds your merchant account) and a payment processor or gateway provider that sits between you and the networks.
The acquiring bank is your contract holder. They take on the risk of your business, hold your settlement funds, and handle chargebacks. They require proof that you can process the volume you claim, a detailed description of your business, your processing history (if you have one), and evidence of your security practices. If you are new to payments, they may require a reserve account—they hold a percentage of your settlements for 6 to 12 months in case chargebacks spike. This can be 5 to 25 percent of your monthly volume.
The processor or gateway provider gives you the technical connection. They run the servers that talk to Visa and Mastercard, handle the encryption, and return approval or decline codes to your system. You connect via API (process programming interface). Common processors for custom gateways include First Data, Global Payments, and Worldpay, though these relationships are typically available only to larger merchants or through a reseller.
The entire setup—finding an acquiring bank, negotiating terms, getting approved, and connecting to a processor—takes three to six months. You will need a business license, tax ID, processing history or a personal may provide, and documentation of your security practices.
The code you have to write and maintain
The payment acceptance itself is one API call: you send the card data (encrypted), the amount, and the merchant ID to your processor, and they return an approval code or a decline reason. That part is straightforward.
Everything else is not. You need to handle declined cards and ask the customer for a different card or payment method. You need to store the approval code and the transaction ID so you can match them to orders in your system. You need to implement refunds—which means sending a separate request to the processor with the original transaction ID and the refund amount. You need to handle partial refunds, where a customer returns part of an order. You need to detect and log chargebacks (when a customer disputes the charge with their bank) and respond to them with proof of delivery or authorization.
You also need fraud detection. This means analyzing the transaction for red flags: card used in a different country than the billing address, multiple failed attempts in a short time, unusually large amounts, or patterns that match known fraud. You can build this yourself or license it from a fraud detection service like Kount or Sift. Either way, you need to decide what to do when fraud is suspected—block the transaction, require additional verification, or flag it for manual review.
Currency conversion, if you operate internationally, adds another layer. You need to handle multiple currencies, manage exchange rates (which change constantly), and may support your settlement happens in your home currency. This requires either a processor that handles multi-currency or a separate currency conversion service.
Testing is extensive. You need test cards for every scenario: approved transactions, declined cards, expired cards, insufficient funds, and fraud flags. You need to test refunds, partial refunds, and chargebacks. You need to test what happens when the processor is slow or unreachable. Most of this testing is manual the first time, then automated in your test suite.
The infrastructure and security you need to build
You cannot store full card numbers. PCI DSS forbids it. Instead, you store a token—a unique identifier that your processor issues for that card. When you need to charge the card again, you send the token, not the card number. This means you need a tokenization system: code that receives the card number from your customer, sends it directly to your processor (never through your servers), and stores the token your processor returns.
This is usually done with a hosted payment form or a JavaScript library that encrypts the card data before it leaves the customer's browser. Stripe's Stripe.js and Square's Web Payments SDK do this for you. If you build your own, you need to implement the same encryption and may support the card number never touches your servers.
You also need encrypted connections (TLS/SSL) for every transaction, regular security updates to your code and dependencies, intrusion detection on your network, and a way to log and monitor access to payment data. You need to segment your network so payment data is isolated from the rest of your systems. You need a plan for what to do if you discover a breach—who you notify, how quickly, and what you tell customers.
All of this requires infrastructure: servers (or cloud instances), a database, monitoring tools, and backup systems. You also need redundancy—if your payment system goes down, you cannot process orders. Most custom gateways run on cloud platforms like AWS or Google Cloud, with multiple availability zones and automated failover.
The cost and timeline comparison
Building your own gateway costs money upfront and ongoing. You need developers (at least one full-time engineer for six months to a year), infrastructure (servers, databases, monitoring), security tools (encryption libraries, fraud detection), and compliance (annual audits). A rough estimate: $200,000 to $500,000 in the first year, then $50,000 to $150,000 annually for maintenance, compliance, and updates.
Using an existing processor like Stripe costs 2.9 percent plus $0.30 per transaction for card payments, or 1.5 percent plus $0.25 for ACH transfers. At $1 million in annual volume, Stripe costs roughly $29,000 to $30,000 per year. At $10 million, it costs $290,000 to $300,000. Your own gateway breaks even only if you process enough volume that the percentage savings exceed your engineering and compliance costs. That usually means $50 million or more in annual volume.
The timeline also matters. Using Stripe, you can accept payments in days. Building your own takes six months to a year before you process your first transaction, then months more to handle edge cases and chargebacks properly.
When you might build your own, and what to do instead
You should consider building your own gateway only if you meet one of these conditions: you process more than $50 million annually and the percentage savings justify the cost; your payment logic is so specific that no existing processor offers it (for example, you need custom fraud rules or settlement timing); or you are building a fintech product where payment processing is your core business and you plan to offer it to other merchants.
If you do not meet these conditions, you have better options. Stripe, Square, and Adyen handle all the compliance and infrastructure for you. They offer APIs for custom integration, webhooks for real-time updates, and fraud detection built in. PayPal and Braintree (owned by PayPal) offer similar services. If you need lower fees, Authorize.net and Worldpay work with custom code but still handle the compliance layer.
If you need more control over the payment experience, you can use a payment orchestration platform like Spreedly or Primer. These sit between your code and multiple processors, letting you route transactions intelligently, retry failed payments, and manage multiple payment methods from one integration. They handle compliance and PCI requirements while giving you more flexibility than a standard processor.
Frequently Asked Questions
Can I build a payment gateway without PCI DSS certification?
No. Your acquiring bank will not give you a merchant account without it, and the card networks will not process your transactions. You can reduce your PCI scope by using tokenization and never storing card data, but you still need to meet the standard for the parts of your system that handle payments.
What happens if I get hacked and card data is stolen?
You are liable for the breach. You must notify affected customers, pay for credit monitoring, and face potential fines from the card networks (up to $100,000 per incident). Your acquiring bank may terminate your account. You may also face lawsuits from customers. This is why most businesses outsource payments—the processor carries the liability and insurance.
Can I use an open-source payment gateway like OpenCart or WooCommerce?
These are shopping cart systems, not payment gateways. They integrate with existing processors like Stripe or PayPal. They do not process payments themselves. If you want to build on open-source code, you would still need to connect to a processor and handle all the compliance yourself.
How long does it take to get approved by an acquiring bank?
Typically three to six months. The bank needs to verify your business, review your processing history, assess your fraud risk, and confirm your security practices. If you are new to payments or in a high-risk industry, it can take longer. Some banks require a reserve account, which adds another 30 to 90 days before you can access your full settlement.
What is the difference between a payment gateway and a payment processor?
A gateway is the software that accepts payment information and sends it to the processor. A processor is the company that routes the transaction to the card networks and returns the result. In practice, most companies use the terms interchangeably, and most processors provide both the gateway and the processing.