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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

michfuer’s picture

Status: Active » Needs review
FileSize
2.27 KB

...and here's the patch.

michfuer’s picture

Forgot to pass the $order as a parameter. It's useful.

mglaman’s picture

+++ b/modules/payment/includes/commerce_payment.checkout_pane.inc
@@ -215,7 +215,9 @@ function commerce_payment_pane_checkout_form_submit($form, &$form_state, $checko
+          // $balance is the default transaction charge. Allow other modules to
+          // adjust it if desired.
+          drupal_alter('commerce_payment_transaction_charge', $order, $balance);

Seems 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.

michfuer’s picture

My 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.

acrollet’s picture

Status: Needs review » Reviewed & tested by the community

This patch works nicely for me - I have a separate use case that involves splitting payments between different methods.

rszrama’s picture

Status: Reviewed & tested by the community » Postponed

This 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.