Craft CMS Asked on January 17, 2021
Is there any way of partially paying for an order, so if the order total amount was $100, how can I programmatically set the payment amount to $50, and then pay the other $50 using another payment method later on?
There was a way to do this in Craft2 using a custom plugin, but in Craft3 I tried using the Payments::EVENT_BEFORE_PROCESS_PAYMENT
event but the variable is null
in the $event->transaction
.
Please let me know, thank you!
This is certainly still possible with Commerce 3 and Craft 3.
In a custom plugin or module you can listen for the Transactions::EVENT_AFTER_CREATE_TRANSACTION
event and amend the transaction amount at this point in the process.
For example, you could make your own payment form that includes a partPaymentAmount
field and posts to the normal commerce/payments/pay
controller action.
Then in your event listener to the Transactions::EVENT_AFTER_CREATE_TRANSACTION
event, test to see if a value exists for the partPaymentAmount
POST variable. If it does, amend the transaction amount accordingly. The payment should proceed with the amended amount, so long as it is still a valid amount to pay against the current order (i.e. it is less than or equal to the total amount of the order).
The nice thing about doing it this way is that it is a very light touch on Commerce and still utilises the existing Commerce workflow for processing the transaction and making sure that everything is updated properly.
Correct answer by Steve Rowling on January 17, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP