Add the ability to set a default payment method

Created on 26 August 2016, about 9 years ago
Updated 13 November 2024, 12 months ago

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

📌 Task
Status

Needs work

Version

2.0

Component

Payment

Created by

🇷🇸Serbia bojanz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • update the patch for Drupal 10 & commerce 2.x-dev version

  • 🇯🇴Jordan Anas_maw

    Reroll the patch to the latest dev version

  • 🇧🇦Bosnia and Herzegovina nno

    Here is the patch updated for Commerce 3.x

  • 🇮🇱Israel jsacksick

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

  • 🇧🇦Bosnia and Herzegovina nno

    Here is the patch for 3.x without changes to the CartManager.

  • 🇮🇱Israel jsacksick

    Is is possible to open a merge request with the changes?

  • @nno opened merge request.
  • First commit to issue fork.
  • 🇳🇴Norway zaporylie

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

  • 🇮🇱Israel jsacksick

    I left a quick comment for a minor change with the controller. (using $commerce_payment_method directly).

    Also any idea why the tests are failing?

  • 🇮🇱Israel jsacksick

    Ok... tests aren't passing...

    The following code looks wrong to me:

    elseif (count($storage->loadMultipleByUser($this->getOwner())) == 1) {
          // Set as default if it is the only payment method for the user.
          $this->setDefault(TRUE);
          $this->save();
        }
    

    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().

  • 🇳🇴Norway zaporylie

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

  • 🇮🇱Israel jsacksick

    @zaporylie: Thank you for wrapping this up! Merged!

  • Now that this issue is closed, please review the contribution record.

    As a contributor, attribute any organization helped you, or if you volunteered your own time.

    Maintainers, please credit people who helped resolve this issue.

  • Issue was unassigned.
  • Status changed to Fixed about 1 month ago
Production build 0.71.5 2024