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
// 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');
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 which has this in the same location
$this->stack->push($middleware->onBefore());
$this->stack->push($middleware->onFailure(2));
Then both function correctly.
It's unclear to me if this should be fixed in the UPS 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
Issue fork commerce_usps-3571397
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
rhovlandComment #3
trobey commentedcommerce_usps 2.x has not been working for me. Commerce UPS already is enabled and is working. When I change the order of the two in shipping methods Commerce USPS works and Commerce UPS fails.
Comment #4
rhovlandAh yes that makes sense. UPS came after USPS in my shipping method list.
Comment #5
jsacksick commentedAs suggested in the related issue, I think we should create a new stack, like the following, rather than adding to the existing / global one:
Comment #9
tbkot commented