💳 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:
- Go to Stores > Configuration > Sales > Payment Methods
- Select your desired method (e.g., Cash on Delivery)
- 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
);
➕ 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.xmlandpayment.xml
🔧 Example: Define Custom Payment Method Class
namespace Vendor\Module\Model;
use Magento\Payment\Model\Method\AbstractMethod;
class CustomPayment extends AbstractMethod
{
protected $_code = 'custompayment';
}
🔧 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! 💰