Setting up a custom payment gateway in WooCommerce

How to add a custom or local payment gateway to WooCommerce: checking for an official plugin, building a gateway class, webhooks, testing and security.

Usman Muhammad UsmanUpdated October 13, 2026
Setting up a custom payment gateway in WooCommerce

Many of my clients sell in markets where the big gateways are not available or where customers prefer a local bank, wallet or card processor. WooCommerce handles this well because any gateway can be added as a plugin. This guide explains how I approach it, from checking for an existing extension to building and testing a custom gateway that is safe to take real money.

Check for an official plugin first

Before writing any code, check whether the payment provider already offers a WooCommerce plugin. Most established processors do, and an official plugin is maintained by people who know the provider’s API, handles updates and usually supports refunds and webhooks. Read the reviews, check when it was last updated and confirm it supports the WooCommerce version and checkout type you use.

Also check compatibility with the newer block-based checkout. Many older gateways only support the classic shortcode checkout, so you may need to keep the classic checkout page until the plugin is updated. If an official plugin exists and is maintained, use it. Custom development only makes sense when there is no plugin, the plugin is abandoned or the client needs behaviour it does not offer.

How a custom gateway works

A WooCommerce gateway is a PHP class that extends WC_Payment_Gateway. It defines the settings shown in WooCommerce > Settings > Payments, such as the title, description and API keys, and a process_payment method that runs when the customer places an order. That method either charges the customer directly through the provider’s API or redirects them to a hosted payment page.

Hosted payment pages are usually the safer choice for small businesses because card details never touch your server, which keeps your PCI compliance scope small. After payment, the provider sends the customer back to a thank-you URL and, separately, sends a server-to-server notification confirming the result. I package the gateway as a small standalone plugin, never inside the theme, so it survives theme changes.

Custom gateway workflow
  1. 1Check pluginsOfficial extension first
  2. 2Build the classSettings and process_payment
  3. 3Handle webhooksVerify, then mark paid
  4. 4Sandbox testingSuccess, failure, refunds
  5. 5Go liveOne real test purchase

Webhooks and order status

Never mark an order as paid just because the customer landed on the thank-you page, since that URL can be visited without paying. The reliable signal is the webhook or IPN the provider sends to your site. The gateway verifies the signature of that request, checks the amount and order ID, and then calls payment_complete on the order.

Handle every outcome: success, failure, cancellation, pending bank transfers and duplicate notifications. Store the provider’s transaction ID on the order so refunds and disputes can be matched later. Log requests to a WooCommerce log file during development and keep logging available as a setting, because payment issues are much easier to solve when you can see exactly what the provider sent.

Testing before going live

Every serious provider offers a sandbox environment with test cards or test accounts. I test on a staging site first, running through successful payments, declined cards, abandoned payments, refunds and partial refunds. I also check what happens when the customer closes the browser mid-payment, because the webhook should still update the order correctly.

Test on mobile as well as desktop, and with the exact theme and checkout plugins used on the live site. Once the sandbox works, I switch to live keys and make one small real purchase, then refund it. Only then is the gateway enabled for customers. Keep test mode as a simple setting so you can debug later without editing code.

Security and compliance

Keep API keys out of the code and in the gateway settings, restrict who can see WooCommerce settings through user roles, and serve the whole site over HTTPS. Validate and sanitise every value that comes back from the provider. If the gateway collects card details on your own page, you take on a much larger PCI responsibility, which is rarely worth it for a small store.

Keep WordPress, WooCommerce and the gateway plugin updated, and include payment checks in your monthly maintenance. I also recommend reading my WooCommerce security basics guide, because a store that takes payments is a more attractive target than a brochure site.

Supporting the block checkout

WooCommerce’s block-based cart and checkout are now the default for new stores. A gateway that only implements the classic PHP class will not appear there. Block support needs a small JavaScript integration registered with the payment method API, plus a PHP class that tells WooCommerce which scripts to load and which settings to expose.

If budget is limited, keep the store on the classic checkout until the gateway is updated; it is still fully supported. Whichever checkout you use, test the full flow after every WooCommerce major update, because checkout changes are where gateways most often break. A short automated test or a monthly manual purchase catches problems before customers do.

When to hire a developer

If you are comfortable with PHP and APIs, a basic redirect gateway is a manageable project. For most business owners, though, payments are not the place to experiment. A mistake can mean orders marked paid that were not, or real payments that never reach an order, both of which cost money and customer trust.

I build and maintain custom gateways as part of my WooCommerce development service. A typical project includes the gateway plugin, webhook handling, refunds, block checkout support, logging and documentation. If you are deciding between platforms because of payments, read WooCommerce vs Shopify, where gateway support is often the deciding factor.

Key takeaways

  • Use the provider's official plugin whenever a maintained one exists.
  • Prefer hosted payment pages to keep card data off your server.
  • Mark orders paid only after a verified webhook, never on the thank-you page.
  • Test every payment outcome on staging before taking real money.

Frequently asked questions

Do I need to be PCI compliant?

Every store that takes card payments has PCI obligations. Using a hosted payment page or embedded fields from the provider keeps your scope small, usually to a short self-assessment questionnaire.

Will my gateway work with the block checkout?

Only if it registers block checkout support. Many older plugins only work with the classic checkout, so check before switching your checkout page to blocks.

How long does a custom gateway take to build?

A redirect-based gateway with webhooks and refunds usually takes a few days of development plus testing time, depending on the quality of the provider's documentation.

Can I offer several gateways at once?

Yes. WooCommerce lets you enable multiple gateways and choose their order. Many stores offer a card processor, PayPal and a local option side by side.

Can a custom gateway handle refunds?

Yes, if the provider's API supports them. The gateway declares refund support and implements a process_refund method, so refunds can be issued from the WooCommerce order screen.

Free website audit

Get a free audit of your website

Tell me your URL and I'll send a short, prioritized list of the speed, SEO and security fixes that will make the biggest difference.

  • No obligation, no sales call
  • 5.0 rating on Google and Upwork
  • Reply within one business day
Written by Muhammad UsmanWeb Development Team Lead with 5+ years building WordPress, WooCommerce, Shopify and Wix websites. Experience · Certificates About me

More on WordPress & WooCommerce

All WordPress & WooCommerce articles

Have a project in mind?

Tell me what you're building and I'll reply with next steps and an estimate.