September 24, 2024

Magento 2 Payment Gateway Integration: Guide for Store Owners

Ilia Sokolov

Architect and Lead Magento Developer. Experienced in custom eCommerce solutions, Magento extensions, and all phases of development, from architecture to optimization.

Magento (Adobe Commerce)

Payment Gateway Integration in Magento 2: Complete Guide

Ilia Sokolov

Architect and Lead Magento Developer. Experienced in custom eCommerce solutions, Magento extensions, and all phases of development, from architecture to optimization.

Magento (Adobe Commerce)

Payment Gateway Integration in Magento 2: Complete Guide

Failed payment transactions are a merchant’s worst nightmare. In the short term, they mean lost sales. In the long run, they lead to negative reviews, endless customer complaints, and ultimately lost revenue. As a Magento store owner, you expect your site to handle payments flawlessly. In fact, secure and customer-friendly digital payments are a cornerstone for a winning e-shopping experience. 

Are you wondering how to add payments to your Magento 2 store? In this post, Ilia Sokolov, our Head of Magento 2 Department with over a decade of experience, shares valuable insights on the Magento 2 payment gateway integration process. We also list the best payment gateways, their features, pros, and pricing to help you power your Magento store with the best payment options available.

Key Takeaways

  • You can integrate payments in your Magento 2 site using built-in payment gateway providers such as Paypal, Braintree, and Authorize.Net, third-party Magento payment modules, or custom payment gateway integration. The choice depends on your business needs, Magento 2 infrastructure complexity, target locations, and customer preferences. 
  • To add a payment gateway to Magento 2, you need to set up the development environment, create a custom module, implement the required payment methods, and configure the payment functionality at the backend and frontend of your site. Once done, make sure to cover the integration with different test scenarios. If no errors are detected, deploy your store in production. 
  • NEKLO provides Magento payment gateway integration services for businesses of all sizes. Whether you manage high-volume transactions or handle international orders, we ensure your payment system is optimized for security, efficiency, and scalability.

Payment Integrations: Key Terms to Know

Before we delve into the technical intricacies of Magento payment gateway integration, let's review key terms. You'll encounter these terms when deciding on the best payment solution to integrate into your site or when setting up payments on your Magento site. 

These components, though often used interchangeably, play distinct roles in the transaction process and have their own technical characteristics.

  • Payment gateway — A third-party service included in Magento either by default or integrated manually. Its goal is to handle online payments at your site.
  • Payment processor — A component of a payment gateway initiating the actual transaction. It transfers the payment details between the customer, the merchant, and the bank.   
  • Payment method — How customers pay for their purchases, e.g. Visa, Mastercard, digital wallets, bank transfers, or other ways.
  • Checkout process — The series of steps customers take on your site to complete a purchase. 

Now that you know the essential terminology, let's examine how these components work together in a Magento store's payment process.

How Do Payments Work in Magento 2?

How payment gateway works

Payment processing in any e-commerce store starts at the checkout. For Magento Abode Commerce, its beauty lies in the ultimate flexibility of the checkout experience you can achieve at your store. 

If you own a Magento 2 store, you can enable any payment method imaginable, giving your customers complete freedom to choose how they want to pay for their orders. You can also customize the checkout flow — make it a consistent multi-step process or a quick one-page effort. 

When a customer is ready to pay for their cart, they share their payment data on the frontend. This includes entering their card or account credentials, selecting a preferred payment method, currency, and other details. Once this is done, the payment processor takes over on the backend. It collects the customer’s data, verifies its accuracy, and if everything is in order, triggers the payment gateway to complete the transaction.

It’s important to note that a payment processor is a third-party component. This means neither you nor Magento are responsible for its performance or ownership. 

Usually, payment gateways come bundled with specific payment processors, with Stripe and PayPal being top-of-mind examples. Other payment gateways like Authorize.net let you connect third-party processors depending on your business’s needs. 

Integrating the right payment gateways and processors in your Magento store is crucial. It ensures that none of your customers leave without completing their purchase. So, let’s explore what Magento 2 has to offer to help you cater to your customers’ payment preferences.  

Which Built-in Payments Methods does Magento 2 Offer?

Magento 2 payment methods

Magento 2 is a robust e-commerce platform that includes many out-of-the-box payment methods. You can configure them in the admin panel to better address your client's preferences. 

Among the Magento 2 payment methods:

  • Check/money order: send payment to a store's address.
  • Bank transfer: send payment to a store's bank account.
  • Cash on delivery (COD): pay for orders by their delivery.
  • Purchase order: pay for orders by sending a purchase order to a store.
  • Zero subtotal checkout: complete the purchase without payment information, e.g. when its cost is covered by bonuses or you have free orders, e.g. test samples or free-goodies.
  • PayPal: pay for the purchase using your PayPal credit card or account.
  • Braintree: create a customized checkout experience that includes various payment methods (credit cards, debit cards, PayPal, mobile payments, etc).

While these options are fine for most smaller stores with basic needs, your business might require more advanced features — such as support for multiple currencies, subscription management, or cryptocurrency payments. This is where integrating additional payment gateways comes into play.

Payment Gateway Integration Types Used in Magento 2

So, how can you add a payment gateway to your Magento 2 site? There are three basic ways: built-in payment solutions, third-party extensions, or custom integration. 

Build-in

Magento 2 supports three built-in or out-of-the-box payment gateways: PayPal, Braintree, and Authorize.Net. All of them are highly reputable payment providers with ultimate security features. You can enable and configure them straight away after installing Magento Adobe Commerce — no additional software add-ons are required.  

All configurations are intuitive and easy to set up via the admin panel to create a straightforward payment flow in your Magento 2 store.

Best for:

  • Small e-commerce businesses
  • Standard purchase process
  • Simple default store infrastructure

3rd party extensions

You can purchase payment gateway extensions if you’d like to set up payments for different countries and regions. Examples are Magento payment modules like Stripe and Paya, which are common for the US markets, Barclaycard, Worldpay for the UK, Moneris if you target Canada, or Alipay for China.

Best for:

  • Mid-size Magento stores
  • Regional payment providers
  • More flexible and varied payments

Custom integration

Many enterprise Magento commerce stores opt for custom payment gateway integration. This involves creating custom code that connects your Magento 2 store with a payment service that is either not natively supported by Magento or requires a unique payment flow. 

Sometimes, custom payment gateway integration is a mere necessity, e.g., you are looking for completely tailored functionality that none of the ready-made modules provides. In other cases, it is a strategic choice for stores with complex infrastructure or those overly cluttered with third-party extensions when another add-on can cause instability in the entire Magento payment system.

Best for:

  • Unique or niche business 
  • Regional payment providers
  • Highly customizable payment process 
  • Complex stores 
  • Multiple payment gateway integrations

How to Integrate a Custom Payment Gateway into Magento 2

Now, from theory to practice. Let’s see what technical steps you need to go through when adding a payment gateway integration to your Magento 2 store. 

Before Integration

Ensure that you have Magento 2 installed on your local development environment and it’s compatible with the required PHP version and extensions. Misconfigured server settings (PHP, MySQL) can cause Magento 2 to crash or run slowly. 

Step 1. Enable Developer Mode

Set Magento in developer mode for better error reporting. Developer mode makes debugging easy as errors are displayed instantly and directly.


php bin/magento deploy:mode:set developer

Step 2. Create a Custom Payment Gateway Module

Create the directory structure for your custom module.

app/code/Vendor/PaymentGateway/

Create registration.php, module.xml and composer.json files and enable the module.

If the module isn't properly registered, Magento may throw errors. Check file paths and ensure the module name is consistent across files.

php bin/magento setup:upgrade

Step 3. Define Payment Methods

Define the payment method in the payment.xml and config.xml files.

Incorrect configuration or missing references in config.xml can lead to issues with payment method visibility. Verify all settings are correctly added.

Step 4. Create the Payment Model

Implement the logic for the payment method in the model file.

Extending the wrong base class or misconfiguration of the payment method code can prevent the payment method from being listed.

Add Configuration Options to Admin Panel

Make the payment method configurable from the Magento admin. Define the settings in system.xml.

Errors in system.xml will cause the payment gateway to not appear in the admin configuration. Always ensure fields are well-formed and placed under the correct section.

Step 5. Handle Payment Gateway API Integration

Use the payment gateway’s API documentation to create a service that will implement request sending (for example, authorizing a payment). Handle success and failure responses.

Inadequate error handling can lead to incorrect status updates or incomplete transactions. Always handle API response statuses carefully and throw meaningful errors.

Step 6. Implement Frontend UI for Payment Method

Implement a UI component for the payment method in the frontend.

  • Create a custom template file under view/frontend/web/template/payment/.
  • Create a KnockoutJS component (payment-method.js) to manage the payment method on the checkout page.
  • Declare the payment method in the checkout layout: <your_module_dir>/view/frontend/layout/checkout_index_index.xml

Incorrect implementation of the UI component can lead to the payment method not appearing at checkout. Check the require.js paths and make sure the component is correctly registered.

Step 8. Test the Payment Gateway

After implementing all the code, enable the module.

php bin/magento setup:upgrade

php bin/magento cache:clean

Test the payment gateway for different transaction scenarios (e.g., success, failure, refund). Always test edge cases like network failure or incorrect payment details.

Step 9. Deploy to Production

When moving to production, ensure you enable caching and switch to production mode for performance.

php bin/magento deploy:mode:set production

Double-check error logs and server configurations post-deployment.

Custom Payment Gateway Integration

A custom payment gateway integration in Magento 2 involves developing a bespoke solution to connect your Magento store with a payment service provider (PSP) that is not natively supported by Magento or through existing extensions. This type of integration is tailored to meet specific business requirements, offering greater flexibility and control over the payment process.

When to Use Custom Magento Payment Gateway Integration

  • The payment gateway is not supported out-of-the-box or by existing Magento extensions.
  • You need advanced payment functionality, e.g., fraud detection or custom transaction workflows.
  • You target niche regions where other payment providers or methods are widespread compared to global payment gateways.
  • Your business commands nonstandard payment processes, e.g., split payments or integration with accounting or ERP systems.

10 Best Payment Gateway Integrations For Magento 2

Magento Adobe Commerce platform supports a variety of payment gateways. It doesn't use just one; rather, it offers integration with numerous payment gateways to give merchants flexibility. 

Payment Gateway Pricing Key Features
PayPal 2.9% + $0.30 per transaction (US)
  • Global availability
  • Multi-currency support
  • PayPal Express Checkout
  • Subscription payments
  • Fraud protection tools
Braintree 2.9% + $0.30 per transaction (US)
  • Supports PayPal, cards, digital wallets
  • Advanced fraud protection
  • Multi-currency support
  • Recurring billing
  • Customizable checkout
Authorize.Net $25 monthly fee + 2.9% + $0.30 per transaction
  • Cards, eChecks, digital wallets
  • Recurring billing
  • Advanced fraud prevention
  • Invoicing features
  • PCI compliance
Stripe 2.9% + $0.30 per transaction (US)
  • Supports cards, wallets, local payment methods
  • One-click payments
  • Recurring billing
  • Developer-friendly APIs
  • Advanced fraud detection
Klarna Varies by country and service
  • "Buy Now, Pay Later" options
  • Pay in installments
  • Multi-currency support
  • No interest for consumers
  • High conversion rates for high-ticket items
Worldpay 2.75% + £0.20 per transaction (UK)
  • Global currency support
  • Supports cards, bank transfers, eWallets
  • Recurring billing
  • Fraud detection tools
  • PCI compliance
Adyen 2.9% + $0.12 per transaction (US)
  • Supports 250+ payment methods
  • Unified commerce (online and in-store)
  • Advanced risk management
  • Multi-currency support
  • Real-time data and analytics
Amazon Pay 2.9% + $0.30 per transaction (US)
  • Easy integration for Amazon customers
  • Trusted Amazon brand
  • One-click checkout
  • Fraud protection
  • Multi-currency support
Square 2.6% + $0.10 per transaction (US)
  • All-in-one POS and online payments
  • Flat-rate pricing
  • Real-time sales reporting
  • No monthly fees for basic services
  • Mobile payments
Verifone (2Checkout) 3.5% + $0.35 per transaction
  • Global payment processing
  • Supports 45+ currencies
  • Recurring billing
  • Advanced fraud protection
  • Customizable checkout

Below, we provide a list of most popular payment gateways compatible with Magento 2. Some of them, like we’ve mentioned earlier, are already available by default. Others you can integrate by purchasing a ready-made module or with Magento payment gateway integration service

1. PayPal

PayPal payment gateway

PayPal is one of the most widely used payment gateways globally with 35% market share, and Magento 2 offers pre-built integration with it. With 426 million active accounts worldwide and total payment volume hitting $1.53 trillion in Q4 2023, PayPal is trusted by both businesses and consumers for its secure transactions. It’s ideal for Magento 2 stores looking to serve a broad, international audience.

For Magento 2, PayPal supports features like PayPal Express Checkout, Credit and PayPal Payflow. This ensures that customers can complete their payments quickly without leaving your website. It also offers multi-currency support, making it ideal for businesses that sell to customers in different regions.

  • Advantages: Wide global acceptance, high customer trust, multi-currency support, built-in to Magento 2 solution
  • Features Supported: Express Checkout, Payflow, PayPal Credit, invoicing
  • Best for: Small to mid-sized stores, international businesses

2. Braintree

Braintree payment gateway

Braintree, owned by PayPal, offers a full-stack payment solution that supports digital wallets and even cryptocurrency. Its integration with Magento 2 is also built-in. You can easily configure it to accept credit cards, debit cards, PayPal, and mobile wallets like Apple Pay and Google Pay.

One of Braintree's key benefits is its advanced fraud protection, Dynamic 3D Secure (3DS) authentication and detailed analytics, helping store owners reduce chargebacks and gain insight into customer payment behavior. The gateway operates in 45 countries and supports over 130 currencies, making it an excellent choice for international businesses using Magento 2. Braintree’s scalability also ensures that as your business grows, you won’t need to change your payment processor.

  • Advantages: Multi-currency support, advanced fraud protection, support for digital wallets, scalability, easy customization
  • Features Supported: Credit/debit cards, PayPal, Apple Pay, Google Pay, fraud protection
  • Best for: Mid to large-sized stores, businesses with high transaction volumes, global sales

3. Authorize.Net

Authorize.Net payment gateway

Authorize.Net, a trusted payment solution owned by Visa, has been in the payment processing industry for over 20 years. It’s a reliable option for Magento 2 users, with strong support for secure transactions, fraud prevention tools, and recurring billing. It’s a popular choice for stores with subscription services or those needing extensive fraud protection.

For Magento 2, Authorize.Net provides easy integration via its extension, offering a secure and PCI-compliant payment experience. It supports multiple payment methods, including credit cards, eChecks, and Apple Pay. While its market share is only about 5%, Authorize.Net remains a popular choice for Magento businesses seeking a secure and established payment solution.

  • Advantages: High security, recurring billing, fraud prevention tools, extensive market presence
  • Features Supported: Credit/debit cards, eChecks, Apple Pay, fraud prevention
  • Best for: Subscription-based services, high-risk industries, small to large-sized stores

4. Stripe

Stripe payment gateway for Magento 2 store

Stripe has quickly gained traction as one of the most developer-friendly payment gateways, and its Magento 2 integration is widely used by businesses looking for flexibility and customization. Stripe offers a broad range of payment options, including credit/debit cards, mobile wallets, and local payment methods like SEPA and Alipay.

For Magento 2, Stripe’s integration is available as a third-party extension. It provides a highly customizable checkout experience and supports features like one-click payments and recurring billing. With over 3.1 million websites using Stripe globally, it’s clear that this payment gateway is growing in popularity, particularly for tech-savvy businesses looking for advanced functionality.

  • Advantages: Developer-friendly, support for multiple payment methods, global reach, customizable
  • Features Supported: Credit/debit cards, mobile wallets, local payment methods, one-click payments
  • Best for: Tech-driven businesses, international stores, subscription services

5. Klarna

Klarna payment gateway for Magento 2 store

Klarna has made a name for itself in the "Buy Now, Pay Later" (BNPL) space. If your business model allows customers to split payments into installments, Klarna can be your go to choice. Magento 2’s integration with Klarna provides store owners with an easy way to offer these flexible payment plans, which can increase conversion rates, especially for high-ticket items.

Klarna is growing in popularity across Europe and North America, with more than 150 million consumers and over 450,000 merchants using the service in 2022. Its Magento 2 extension allows customers to choose from various payment plans, including pay later or pay in installments, directly at checkout. This is especially useful for businesses looking to reduce cart abandonment and increase order values.

  • Advantages: Flexible payment plans, popular in Europe and North America, split payments
  • Features Supported: Pay later, pay in installments, pay now, flexible payment options
  • Best for: High-ticket items, businesses targeting younger consumers, stores focused on increasing average order value

6. Worldpay

Worldpay payment gateway for Magento 2 store

Worldpay, now part of FIS, is a global payment gateway that supports more than 120 currencies and offers extensive fraud detection tools. The Magento 2 integration with Worldpay allows store owners to accept a wide range of payment methods, including cards, eWallets, and bank transfers. Worldpay’s global reach and strong fraud protection make it a good fit for Magento 2 merchants with international customers.

The Worldpay Magento 2 extension is easy to set up and offers full PCI compliance, ensuring that customer payment data is handled securely. With Worldpay controlling 40% of the UK’s payment processing market, it’s an excellent choice for businesses looking for a trusted, reliable payment solution.

  • Advantages: Global currency support, advanced fraud detection, trusted brand, PCI compliance
  • Features Supported: Credit/debit cards, bank transfers, eWallets, recurring payments
  • Best for: Global businesses, stores requiring strong security measures, mid to large-sized stores

7. Adyen

Adyen payment gateway for Magento 2 store

Adyen is a global payment gateway that has quickly gained traction with major brands due to its unified platform, allowing businesses to process payments both online and in-store. The Magento 2 integration with Adyen is highly flexible, supporting over 250 payment methods and 150 currencies. This makes it ideal for stores with an international customer base.

Magento 2’s Adyen extension supports features like recurring payments, risk management, and multi-currency processing. Its unified commerce solution allows store owners to have a single view of payments across all sales channels, providing better insights and customer experiences. Adyen’s market presence has grown significantly, with clients like eBay, Spotify, and Uber using its platform.

  • Advantages: Supports over 250 payment methods, unified platform for online and in-store payments, direct card network integration
  • Features Supported: Recurring payments, risk management, multi-currency processing, unified commerce
  • Best for: Large international businesses, omnichannel retailers, high-volume merchants

8. Amazon Pay

Amazon Pay paymet gateway  integration for Magento 2 store

Amazon Pay leverages Amazon's trusted payment system to provide a seamless checkout experience for customers who are already familiar with Amazon's platform. Magento 2 integration with Amazon Pay allows store owners to offer a convenient payment option where customers can use the payment methods stored in their Amazon accounts. This provides a smoother checkout process, as customers don’t need to re-enter their payment details.

With Amazon Pay, Magento 2 stores benefit from Amazon’s security and fraud protection measures, which are robust and well-regarded in the industry. Given that Amazon has a substantial user base, integrating Amazon Pay in your Magento 2 store can also help in attracting customers.

  • Advantages: Leverages Amazon's trusted payment system, easy checkout for Amazon account holders, high-security standards
  • Features Supported: One-click payment, secure transactions, integration with Amazon account payment methods
  • Best for: businesses aiming to leverage Amazon’s trust

9. Square

Square payment gateway integration for Magento 2 store

Square, known for its simple and user-friendly point-of-sale solutions, also offers a robust payment gateway that integrates seamlessly with Magento 2. It is particularly popular among small to mid-sized businesses for its ease of use and flat-rate pricing model. Square supports a wide range of payment methods, including credit and debit cards, and integrates with various online and in-person sales channels.

With its commitment to transparency and user experience, Square is a solid choice for Magento 2 businesses looking for an all-in-one payment solution that simplifies both online and offline transactions.

  • Advantages: User-friendly, flat-rate pricing, integrated analytics and reporting, seamless online and in-person payment processing
  • Features Supported: Credit/debit cards, contactless payments, real-time sales reporting, point-of-sale integration
  • Best for: Small to mid-sized businesses, companies needing both online and in-person payment solutions

10. Verifone (aka 2Checkout)

2Checkout (Verifone) payment gateway integration for Magento 2 store

2Checkout, recently rebranded as Verifone, is a versatile payment gateway that offers global payment processing capabilities. It is designed to handle transactions in multiple currencies and support a variety of payment methods. The integration with Magento 2 provides store owners with a reliable solution for managing both one-time and recurring payments, making it suitable for businesses with a diverse customer base.

With 2Checkout, Magento 2 merchants can benefit from features such as advanced fraud protection, customizable checkout options, and comprehensive reporting tools. Its global reach and support for over 45 currencies make it an appealing choice for businesses aiming to expand internationally.

  • Advantages: Global payment processing, support for multiple currencies, advanced fraud protection, customizable checkout
  • Features Supported: Credit/debit cards, PayPal, local payment methods, recurring billing
  • Best for: International businesses, stores requiring advanced fraud protection

Summing Up

Magento 2 gives you the freedom to choose from a variety of payment gateway integrations. The choice of the right solution depends on things like transaction fees, supported currencies, and where your customers are located — all of which can directly affect your conversion rates and help reduce cart abandonment. In the end, it’s about making payments easy and secure for your customers, which is key to your store's success.

Partnering with a team like NEKLO can take your checkout process to the next level, letting you create a fully customized, smooth, and secure payment experience in your store. Get in touch for a free consultation!