airwallex / paymentacceptance-plugin-magento

Airwallex payment magento plugin
12 stars 3 forks source link

Token lifetime fallback #8

Closed laurisdedumets closed 2 years ago

laurisdedumets commented 2 years ago

Added as a fallback for PR #7 in case, for whatever reason, the cached Airwallex token has expired before the Magento cache has been cleared. In the old implementation, if this happened, users would be locked out from using the Airwallex payment methods until the cache lifetime expired because every request would return a 401 error.

Workflow after these changes:

  1. API request to any Airwallex endpoint, excluding Authorization, is made.
  2. If it returns a 401 (Access Denied) response, clear the token from the cache, generate a new one and recreate the request, only using the new token.
  3. As a new token was just generated, the new request should work without issue. If another 401 error is still returned, the extension isn't configured properly and is handled just like other errors are.