Quick Answer
Payment gateway architecture for developers starts with hosted checkout for the lowest compliance burden, embedded fields for more on-page control, and direct API integration only when your team can own card-data security. Put a provider-neutral payment service between the application and gateway, then treat webhooks, idempotency, and reconciliation as core production systems rather than integration details.
Introduction
For most startups, hosted checkout is the correct starting architecture because it removes card entry from the application surface. Embedded fields can preserve more of the checkout experience, but the surrounding page still requires disciplined security controls. Direct API integrations offer the most control, yet they expand the operational and compliance work that engineering must sustain. A payment flow that succeeds in testing can still fail financially when retries, delayed webhooks, refunds, and chargebacks reach production.
Key Takeaways
Hosted checkout minimizes card-data exposure and accelerates launch.
Webhooks require signature checks, durable queues, and idempotent consumers.
Reconciliation turns payment events into accountable financial records.

Payment Gateway Architecture for Developers: Choose the Boundary First
The architecture decision is primarily about where sensitive payment entry occurs and which system owns the payment lifecycle. A practical PCI scope reduction strategy begins by keeping raw card data out of browsers, application servers, logs, analytics tools, and support workflows whenever possible.
Three integration patterns and their operational trade-offs
Hosted checkout redirects the customer to a processor-controlled page, embedded fields render processor-hosted payment components within your page, and direct API flows send payment details through infrastructure you operate. These are different security boundaries, not merely different user-interface choices.
Hosted checkout: Fast launch with provider-controlled card entry.
Embedded fields: More branding control through hosted iframes.
Direct API: Maximum interface control, highest security ownership.
Tokenization: Replaces reusable card data with provider references.
PCI scope is an architecture constraint
The PCI SSC's revised SAQ A eligibility criteria apply only to qualifying e-commerce pages that embed a third-party processor's payment page or form, including inline frames. For embedded payment pages, the PCI Security Standards Council states that SAQ A eligibility may apply to e-commerce merchants whose webpages include a third-party processor's embedded payment page or form, including inline frames, if they meet PCI DSS v4.0.1 criteria. Review the SAQ A eligibility criteria and the PCI DSS v4.0.1 SAQ A document with a qualified assessor, because page security, scripts, and implementation details still matter.[1][2]
Direct API designs often create a much broader compliance responsibility, commonly associated with SAQ D, while merchant-hosted payment pages can lead to SAQ A-EP considerations. Payment PCI compliance must be validated against your actual data flows, contracts, and assessor guidance, not inferred from a gateway marketing page. For build-versus-buy decisions, review payment PCI compliance considerations before selecting an integration model.
Build a Payment Service Layer, Not Gateway Calls Throughout the Codebase
A durable fintech app architecture isolates payment-provider behavior behind a small internal interface. This makes processor replacement, test simulation, and failure analysis manageable without leaking provider-specific concepts into orders, subscriptions, or billing screens.
Use tokens, states, and provider adapters
Your client should obtain a provider token or payment method reference, while the backend receives only that reference plus the intended amount and business context. A narrow service contract can remain stable even when the gateway SDK changes. For example:
authorize(paymentMethodToken, amount, idempotencyKey)
capture(paymentId, amount)
refund(paymentId, amount)
Store a payments record with internal identifiers, provider identifiers, currency, amount, and a state such as pending, authorized, captured, refunded, failed, or disputed. This supports payment API integration without coupling the rest of the product to one processor's event names.
The table separates architectural control from the costs that follow it. Compliance classifications are directional patterns, so confirm the final scope with an assessor.
Pattern | Card entry location | Application control | Typical PCI direction |
|---|---|---|---|
Hosted checkout | Processor page | Lower | Confirm applicable SAQ with assessor |
Embedded fields | Processor iframe | Moderate | SAQ A or A-EP depends on implementation |
Direct API | Your application flow | Highest | Often SAQ D |
The key trade-off is simple: each increase in checkout control also increases the security surface your team must monitor and maintain.
Reliability lives in asynchronous processing
Gateway responses are not the sole source of truth because authorization, settlement, refunds, and disputes may complete asynchronously. Use signed webhooks, verify the HMAC signature against the unmodified request body, write the event to durable storage, then process it through a queue. A hosted checkout implementation can maintain its own event and order records alongside the provider's checkout flow.
Apply idempotency keys to charge and refund requests, and maintain an event ledger keyed by provider event ID. When duplicate or out-of-order notifications arrive, record them, reject repeated state transitions, and retry only transient failures. These practices form the practical core of API gateway patterns for payment systems.

Reconcile Money Daily and Add Processors Deliberately
Robust payment workflows require comparing your payments table with the gateway's transaction reports every day. Match captures, refunds, fees where applicable, and disputes to internal records, then route mismatches to an operational queue with enough identifiers for investigation.
Second gateways solve concentrated risk but multiply state management
Add a second processor only when a documented business requirement justifies the additional routing, reporting, token portability, operational runbooks, and support complexity. A failover path also needs explicit behavior for in-flight payments, because blindly retrying a declined or timed-out charge through another processor can create duplicate customer charges.
Maintain processor-specific adapters and a normalized internal status model. Route decisions should be recorded with the payment, and no processor switch should bypass the same idempotency, webhook, and reconciliation controls used by the primary path.
Building with a partner does not outsource accountability
An agency or contractor should be able to explain token boundaries, webhook verification, secrets rotation, observability, failure recovery, and ownership of PCI evidence. Ask for a diagram of the data flow, a test plan for duplicate events, and a handoff plan for incident response and reconciliation.
Devvpro's engineering coverage can help teams frame build-versus-integrate questions before implementation begins. Startup teams weighing in-house versus specialist support can also review Ninja Studio's payment gateway integration guide, which compares DIY and service-based approaches for production payment systems.[3]
Your company remains responsible for production access, merchant agreements, financial controls, customer support policies, and the decision to release payment changes. Partners can implement systems, but they cannot own the business consequences of an incorrect charge or missing refund.

Conclusion
Start with hosted checkout when speed and a smaller payment surface matter most, then move to embedded fields only when on-page experience needs justify the added controls. Choose direct API architecture only with dedicated security ownership, mature operational practices, and a clear product requirement that hosted components cannot meet. Devvpro offers engineering perspectives for teams evaluating the decisions behind payment infrastructure. The durable choice is the one your team can monitor, reconcile, secure, and change without guessing.
Planning a resilient payment flow? Explore Devvpro's engineering journal for practical architecture guidance.
Frequently Asked Questions (FAQs)
How do payment gateways work under the hood?
Payment gateways work under the hood by securely transmitting a payment request to a processor, returning an initial outcome, and later emitting lifecycle events for actions such as capture, refund, settlement, or dispute.
Why is idempotency critical in payment processing systems?
Idempotency is critical in payment processing systems because network retries and user refreshes can repeat requests, while an idempotency key lets the payment service return the original result instead of creating another charge.
How do hosted checkout and direct API integrations compare for developers?
Hosted checkout and direct API integrations compare by shifting responsibility, because hosted checkout delegates card entry to the processor while direct API designs require the application team to protect a much larger payment-data surface.
What is the best way to handle asynchronous payment notifications?
The best way to handle asynchronous payment notifications is to verify each signed webhook, persist its raw event identity, enqueue processing, and make every resulting state transition safe to execute repeatedly.
What is the role of tokenization in secure payment portals?
Tokenization in secure payment portals replaces sensitive payment credentials with a provider-issued reference, allowing application services to initiate authorized actions without retaining reusable card data in their databases.
Is it better to build or buy payment processing infrastructure?
It is better to buy payment processing infrastructure when standard checkout and payment operations meet product needs, while custom work should focus on domain-specific workflows that processor components cannot safely represent.
Sources
- FAQ Clarifies New SAQ A Eligibility Criteria for E-Commerce Merchants (blog.pcisecuritystandards.org) ↩
- PCI DSS v4.0.1 SAQ A document — listings.pcisecuritystandards.org ↩
- Payment Gateway Integration Services vs DIY in 2026 (Ninja Studio) ↩


