Magento 2 Payment Methods

💳 Magento 2 Payment Methods – Add, Configure, and Customize

Magento 2 offers a variety of payment methods out-of-the-box, including offline options like Check/Money Order and online gateways such as PayPal and Braintree. You can also integrate custom or third-party payment methods for a flexible checkout experience.

⚙️ Configure Built-in Payment Methods

To enable or disable a built-in payment method:

  1. Go to Stores > Configuration > Sales > Payment Methods
  2. Select your desired method (e.g., Cash on Delivery)
  3. Enable it, add title, instructions, and set conditions

🔧 Example: Enable Check/Money Order Programmatically

You can enable it using the configuration scope:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$configWriter = $objectManager->get(\Magento\Framework\App\Config\Storage\WriterInterface::class);

$configWriter->save(
    'payment/checkmo/active',
    1,
    \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
    0
);

Try It Now

➕ Add a Custom Payment Method

To add a new payment method, you’ll need to:

  • Create a module
  • Extend \Magento\Payment\Model\Method\AbstractMethod
  • Declare your method in di.xml and payment.xml

🔧 Example: Define Custom Payment Method Class

namespace Vendor\Module\Model;

use Magento\Payment\Model\Method\AbstractMethod;

class CustomPayment extends AbstractMethod
{
    protected $_code = 'custompayment';
}

Try It Now

🔧 Example: Declare Method in payment.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Payment:etc/payment.xsd">
    <default>
        <payment>
            <custompayment>
                <active>1</active>
                <title>My Custom Method</title>
                <model>Vendor\Module\Model\CustomPayment</model>
            </custompayment>
        </payment>
    </default>
</config>

🔌 Use Third-Party Payment Gateways

Magento Marketplace offers many extensions to support payment gateways like Stripe, Razorpay, Square, and more. Just install, configure from Admin Panel, and test them in sandbox/live mode.

✅ Summary

  • Magento supports a wide range of payment methods
  • You can configure built-in methods or create your own
  • Use XML and PHP to define custom payment logic
  • Third-party integrations are easy via Magento Marketplace

Understanding and customizing Magento 2 payment methods gives you the power to handle transactions exactly how your business needs. Happy coding and smooth selling! 💰