2

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!

4

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.

2
  • Thank you Steve, will have a look and implement this solution. Nov 10 '20 at 9:36
  • Using the Transactions::EVENT_AFTER_CREATE_TRANSACTION event, I can change the paymentAmount variable and it works exactly how I wanted it. Thanks for the tips again Steve. Nov 10 '20 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.