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:
API request to any Airwallex endpoint, excluding Authorization, is made.
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.
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.
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: