Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By default commerce_payment sets the payment transaction charge amount to the order balance during checkout. Adding an alter hook that allows other modules to adjust the charge amount is useful in certain situations e.g. when an order contains out of stock items that we don't want to charge for initially.
Comment | File | Size | Author |
---|---|---|---|
#2 | commerce-txn_charge_alter_hook-2221775-2.patch | 2.29 KB | michfuer |
#1 | commerce-txn_charge_alter_hook-2221775-1.patch | 2.27 KB | michfuer |
Comments
Comment #1
michfuer CreditAttribution: michfuer commented...and here's the patch.
Comment #2
michfuer CreditAttribution: michfuer commentedForgot to pass the $order as a parameter. It's useful.
Comment #3
mglamanSeems a bit of a UX problem for your use case rather than a full feature.
As a consumer I'd be pretty pissed if I placed an order to find out, without warning, an item was removed. I'd motion for this as a won't fix, but at least patch lives for those who live on the UX wild side.
Comment #4
michfuer CreditAttribution: michfuer commentedMy use case for this patch did not involve removing items from the order. It required charging customers only for items that are in-stock and ready to ship, and thus possibly a fraction of the order total. Selling pre-orders is a common marketing technique, and merchants can have legal limitations on when they can charge for a particular product.
Comment #5
acrollet CreditAttribution: acrollet commentedThis patch works nicely for me - I have a separate use case that involves splitting payments between different methods.
Comment #6
rszrama CreditAttribution: rszrama at Centarro commentedThis request is related to #2089217: In payment method modules, charge the order balance instead of the order total in that they both really require some sort of visual indication on the checkout form that the amount charged is not going to be the order total amount. Additionally, I think to satisfy both issues we need to update the payment API with respect to off-site / redirected payment methods to ensure they are getting the charge array as well. Right now only on-site payment methods get the actual charge array.
The workaround for those stuck in the meantime is to alter a wrapper callback onto the payment method info array so that your module can update the charge array and then pass it on to the payment method's original callback for submitting payments.