I go to Magento 2 Admin > Marketing > Promotions > Cart Price Rules and create a new Rule: Bank Transfer Payment:
Tab Rule Information:
- Rule Name: Bank Transfer Payment
- Status: Active
- Websites: Main Website
- Customer Groups: select all
- Coupon: No Coupon
- Uses per Customer: 0
- From: blank
- To: blank
- Priority: 0
- Public in RSS Feed: No
Conditions tab:
- If ALL of these conditions are TRUE :
- Payment Method is Bank Transfer Payment
Actions Tab:
- Apply: percent of product price discount
- Discount Amount: 2
- Maximum Qty Discount is Applied To: 0
- Discount Qty Step (Buy X): 0
- Apply to Shipping Amount: No
- Discard subsequent rules: No
- Free Shipping: No
- Apply the rule only to cart items matching the following conditions (leave blank for all items): nothing
Then I enable Bank Transfer Payment method, go to checkout page, click on Bank Transfer Payment but the Discount Percent Price does not show up in Order Summary.
Please give me an advice. How can make a discount on payment method on Magento 2. For Magento 1, it wroks well.
Thanks very much
Best Answer
This rule doesn't work because Magento 2 doesn't save payment method to quote when you select one. And it also doesn't reload totals when selecting a payment method. And unfortunately, you have to write a custom module to solve the issue.
The new module needs only 4 files to be created:
app/code/Namespace/ModuleName/etc/frontend/routes.xml
This will define a new controller for our module.
app/code/Namespace/ModuleName/Controller/Checkout/ApplyPaymentMethod.php
This file creates controller action to save the selected payment method to quote
app/code/Namespace/ModuleName/view/frontend/requirejs-config.js
This file allows to override
Magento_Checkout/js/action/select-payment-method
fileapp/code/Namespace/ModuleName/view/frontend/web/js/action/select-payment-method.js
Sends ajax request to save payment method and reload cart totals.
P.S. Parts of the code were taken from Payment Fee extension for Magento 2.