The user's payment method pages need a "Set default" link. Just like profiles have.

CommentFileSizeAuthor
#26 interdiff-24-26.txt18.07 KBmjpa
#26 2790533-26.patch14.54 KBmjpa
#24 interdiff_23-24.txt622 bytesctrlADel
#24 2790533-24.patch18.77 KBctrlADel
#23 2790533-23.patch18.73 KBctrlADel
#22 2790533-22.patch19.07 KBAnas_maw
#21 2790533-19.patch22.79 KBnikathone
#19 interdiff_18-19.txt637 bytesnikathone
#19 2790533-19.patch22.78 KBnikathone
#18 interdiff_15-18.txt5.82 KBnikathone
#18 2790533-18.patch21.97 KBnikathone
#17 interdiff_15-17.txt3.09 KBnikathone
#17 commerce-add_ability_to_set_default_payment_method-2790533-17.patch20.39 KBnikathone
#15 commerce-add_ability_to_set_default_payment_method-2790533-15.patch16.72 KBnikathone
#12 commerce-add_ability_to_set_default_payment_method-2790533-12.patch19.57 KBnikathone
#10 commerce-add_ability_to_set_default_payment_method-2790533-10.patch20.79 KBnikathone

Issue fork commerce-2790533

Command icon 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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz created an issue. See original summary.

miteshmap’s picture

Assigned: Unassigned » miteshmap

working on this.

miteshmap’s picture

Assigned: miteshmap » Unassigned

couldn't make it work. :(

vasike’s picture

Assigned: Unassigned » vasike

i'll try

vasike’s picture

Status: Active » Needs review

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

vasike’s picture

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

vasike’s picture

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

sumanthkumarc’s picture

Adding related issue, https://www.drupal.org/node/2860102, the getDefaultPaymentMethodOption doesn't check if gateway is avaialble.

vasike’s picture

PR "reroll"

nikathone’s picture

Status: Needs review » Needs work
nikathone’s picture

Status: Needs review » Needs work
nikathone’s picture

+++ b/modules/payment/src/Plugin/Commerce/CheckoutPane/PaymentInformation.php
@@ -309,7 +309,18 @@ protected function getDefaultPaymentMethodOption(array $options) {
+        if (in_array($default_payment_method->id(), $option_ids)) {

This 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 like if ($default_payment_method && in_array($default_payment_method->id(), $option_ids))

Status: Needs review » Needs work
nikathone’s picture

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

nikathone’s picture

Just found out that I uploaded a wrong file for #15. Here is another one hopefully it will pass the tests now.

nikathone’s picture

Status: Needs work » Needs review
FileSize
22.78 KB
637 bytes

Status: Needs review » Needs work

The last submitted patch, 19: 2790533-19.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

nikathone’s picture

FileSize
22.79 KB

Oops uploaded wrong patch file.

Anas_maw’s picture

Status: Needs work » Needs review
FileSize
19.07 KB

Reroll the latest patch to the latest dev version

ctrlADel’s picture

Rerolled against dev

ctrlADel’s picture

Small fix to address when the order has a payment method attached but that payment method is not available in the options.

Status: Needs review » Needs work

The last submitted patch, 24: 2790533-24.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mjpa’s picture

Attached a reroll against dev and the following changes:

  • Removed the adding to cart changes as they're not related to the issue
  • Cleaned up the mark as default controller for D9
  • Changed the preSave / postSave default checks to match the Profile module
  • Updated loadMultipleByUser and loadByUser to match Profile's so it brings in the default first so the preSave/postSave work
  • Slight refactor on the code to select a default payment method if the one used is no longer available.
  • Updated the test to use loadByUser() instead of loadDefaultByUser()

Status: Needs review » Needs work

The last submitted patch, 26: 2790533-26.patch, failed testing. View results

SocialNicheGuru’s picture

SocialNicheGuru’s picture

does not apply to commerce 2.x-dev

scotthooker made their first commit to this issue’s fork.

RhiP’s picture

.