Problem/Motivation

When both commerce_usps 2.x and commerce_ups 4.x are installed with configured and enabled shipping methods, commerce_ups cannot retrieve rates with an error "401 UnAuthorized". If the USPS shipping method is disabled, the UPS method works again.

It appears to be because of this section of code

    $this->stack->push($middleware->onBefore());
    $this->stack->push($middleware->onFailure(2));

Steps to reproduce

Install both commerce_usps 2.x and commerce_ups 4.x
Configure a shipping method for both modules with at least one service.
Create a shipment on an order or go through checkout. You only see the USPS rate(s).

Proposed resolution

If I copy the code pattern from USPS USPSSdkFactory to the UPS UPSSdkFactory

    // When multiple shipping methods with the same API credentials
    // are configured the "stack" is overflowed with the OAuth callbacks which
    // leads to the failed request. We should remove those callback before
    // adding again to make it work properly.
    $this->stack->remove('oauth_before');
    $this->stack->remove('oauth_failure');
    $this->stack->push($middleware->onBefore(), 'oauth_before');
    $this->stack->push($middleware->onFailure(2), 'oauth_failure');

Then both function correctly.

It's unclear to me if this should be fixed in the USPS module or here so I created an issue in both.
This also might affect any other modules that use the OAuth middleware.

Remaining tasks

User interface changes

API changes

Data model changes

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:

Comments

rhovland created an issue. See original summary.

rhovland’s picture

jsacksick’s picture

This was fixed in #3571295: Multiple shipping method with different credentials, but didn't realize it was a 5.x issue and just noticed we don't have a 5.x release yet, so let's fix 4.x as well...

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

tbkot’s picture

Status: Active » Needs review
jsacksick’s picture

Status: Needs review » Fixed

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

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

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.