Problem/Motivation
Commerce implemented a concept into orders recording the total amount paid and the remaining amount which has to be paid, called balance. #2804227-6: Add getTotalPaid() and getBalance() methods to orders:
The order tracks its paid_total. getBalance() then subtracts the paid_total from the total.
This concept has not yet been implemented into commerce_stripe and is needed to solve issues like #2935337-4: Native support for deposits/later payment of balance.
Proposed resolution
Do the house keeping mentioned by mglaman in #2935337-7: Native support for deposits/later payment of balance by implementing the use of those methods, especially of getBalance() when creating and updating payment intents and payments, instead of getTotalPrice().
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | commerce_stripe-implement-getbalance-3100093-13.patch | 4.25 KB | mjb3141 |
| #9 | interdiff-7-9.txt | 844 bytes | yanniboi |
| #9 | commerce_stripe-implement-getbalance-3100093-9.patch | 4.19 KB | yanniboi |
| #2 | commerce_stripe-implement-getbalance-3100093-2.patch | 2.91 KB | mvonfrie |
Issue fork commerce_stripe-3100093
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mvonfrie commentedComment #3
mvonfrie commentedThe tests of #2 are failing because they are missing the patch #3100709-3: Update tests for Commerce 2.15.
Comment #4
andrewbelcher commentedThe patch in 2 works, but leaves one specific scenario not covered, which is that the payment passed in may not be for the balance of the order (see #3086504: Allow the PraymentProcess pane to process an amount other than the balance - I take responsibility for that being a scenario!).
The danger of this is that the payment recorded in Drupal can be for a different amount to the payment recorded in Stripe, with both showing as completed. That is not a good state to be in.
So I have added an update to the intent that happens immediately before processing the payment. That should ensure the two are always in sync.
Comment #5
andrewbelcher commentedMy previous patch got a weird diff, this is it correctly formed!
Comment #7
yanniboi commentedAfter some discussion with @andrewbelcher we decided that his approach was not quite right as by the time
\Drupal\commerce_stripe\Plugin\Commerce\PaymentGateway\Stripe::createPaymentis executed, the payment intent has often already been confirmed in Stripe and should not be updated with a new price.Instead, the amount of the Drupal Payment entity created should definitely match the amount of the payment made in Stripe, so for the scenario that the Intent amount is different to the Payment amount, the payment should be updated with the amount stored in Stripe. So this is what my patch adds to #2.
Comment #8
yanniboi commentedComment #9
yanniboi commentedSorry, I forgot that currency code's are case sensitive...
Comment #12
johnpitcairn commentedComment #13
mjb3141 commentedRe-rolling patch for head.
Comment #15
tomtech commentedComment #18
tomtech commented