Closed (fixed)
Project:
Commerce Core
Version:
3.x-dev
Component:
Payment
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
26 Aug 2016 at 10:57 UTC
Updated:
18 Sep 2025 at 12:49 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
miteshmapworking on this.
Comment #3
miteshmapcouldn't make it work. :(
Comment #4
vasikei'll try
Comment #5
vasikeThere is PR for this:
https://github.com/drupalcommerce/commerce/pull/655
- Create new route for set-default
- Build a controller for the route
- Add this to payment methods list operations
- Default by default for the first or unique user payment method
- Extend and update Payment method tests to include this functionality (both Entity and functional)
- Extend the payment method storage with loadMultipleByUser & loadDefaultByUser methods.
Not sure about the loadMultipleByUser & loadDefaultByUser methods implementations.
Maybe some extra properties should be involved.
Comment #6
vasikeNow that we have #2827144: Support multiple payment gateways on Checkout Payment information pane
we need to use the default payment method in the Payment information pane.
PR updated with a commit on this.
Comment #7
vasikePR updated with a commit to fix travis errors.
Now we're green
Last commit fix the postSave make it default for anonymous: no need to check/set the default for anonymous.
Comment #8
sumanthkumarc commentedAdding related issue, https://www.drupal.org/node/2860102, the getDefaultPaymentMethodOption doesn't check if gateway is avaialble.
Comment #9
vasikePR "reroll"
Comment #10
nikathoneUploading a patch based on @vasike PR for patching sake.
Comment #12
nikathoneAnother patch for the sake of patching with a rebase of the current commerce based on the PR at https://github.com/drupalcommerce/commerce/pull/848 which is just a rebase of https://github.com/drupalcommerce/commerce/pull/655 by @vasike
Comment #14
nikathoneThis might cause
Call to a member function id() on boolean in Drupal\commerce_payment\Plugin\Commerce\CheckoutPane\PaymentInformation->getDefaultPaymentMethodOption()if the current user doesn't have any payment method. Note when testing my user did have a completed order though. The fix would be something likeif ($default_payment_method && in_array($default_payment_method->id(), $option_ids))Comment #15
nikathoneRerolled PR at https://github.com/drupalcommerce/commerce/pull/655 with latest commerce.
Comment #17
nikathoneAdding an event to which is dispatched on post save about payment is default. I wasn't sure if this should be added on this patch or in a follow up issue. I will need the maintainer to let me know then we can go with the patch at #15 or if ok then we go with this one. Also leaving it to need work until we figure out why the test are not passing.
Comment #18
nikathoneJust found out that I uploaded a wrong file for #15. Here is another one hopefully it will pass the tests now.
Comment #19
nikathoneComment #21
nikathoneOops uploaded wrong patch file.
Comment #22
anas_maw commentedReroll the latest patch to the latest dev version
Comment #23
ctrladelRerolled against dev
Comment #24
ctrladelSmall fix to address when the order has a payment method attached but that payment method is not available in the options.
Comment #26
mjpa commentedAttached a reroll against dev and the following changes:
loadByUser()instead ofloadDefaultByUser()Comment #28
socialnicheguru commentedComment #29
socialnicheguru commenteddoes not apply to commerce 2.x-dev
Comment #32
rhip commented.
Comment #33
ahlam aljawahreh commentedupdate the patch for Drupal 10 & commerce 2.x-dev version
Comment #34
anas_maw commentedReroll the patch to the latest dev version
Comment #35
nno commentedHere is the patch updated for Commerce 3.x
Comment #36
jsacksick commentedCan we get an MR that applies to 3.x so we can see if the tests are green? The latest patch includes unrelated changes to the CartManager too.
Also,
PaymentMethod::postSave()should probably query payment methods that have theis_defaultflag set to TRUE, so we don't have to load all payment methods belonging to the user (not sure there is a risk of a customer having hundreds of payment methods but still.Comment #37
nno commentedHere is the patch for 3.x without changes to the CartManager.
Comment #38
jsacksick commentedIs is possible to open a merge request with the changes?
Comment #41
zaporylieI rebased the MR, reviewed it, and provided necessary updates, including fixes to code and tests. The current test actually revealed an issue with the owner check, which is now corrected.
Comment #42
jsacksick commentedI left a quick comment for a minor change with the controller. (using $commerce_payment_method directly).
Pushed a commit addressing that, and merged the 3.x changes, let's see where we stand now.
Comment #43
jsacksick commentedOk... tests aren't passing...
The following code looks wrong to me:
This doesn't belong to the postSave() method, as this will resave a payment method that was just saved, this should be moved to the presave().
Comment #44
zaporylieAdded test coverage for the PaymentOptionsBuilder.
There are 2 things that should likely be addressed:
1) non-reusable payment methods should never be set as default.
2) deleting default payment method should make the next eligible payment method default
Both these points can be done as follow-up(s) and need some extra considerations.
Comment #46
jsacksick commented@zaporylie: Thank you for wrapping this up! Merged!