Skip to content

Commit

Permalink
Merge pull request #56269 from Expensify/vit-AmexFeedProduction
Browse files Browse the repository at this point in the history
Force Amex to production API
  • Loading branch information
nkuoch authored Feb 4, 2025
2 parents 6486b1d + 0ceef9e commit ad61525
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/libs/ApiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Request} from '@src/types/onyx';
import proxyConfig from '../../config/proxyConfig';
import * as Environment from './Environment/Environment';
import {getEnvironment} from './Environment/Environment';

// To avoid rebuilding native apps, native apps use production config for both staging and prod
// We use the async environment check because it works on all platforms
let ENV_NAME: ValueOf<typeof CONST.ENVIRONMENT> = CONST.ENVIRONMENT.PRODUCTION;
let shouldUseStagingServer = false;
Environment.getEnvironment().then((envName) => {
getEnvironment().then((envName) => {
ENV_NAME = envName;

// We connect here, so we have the updated ENV_NAME when Onyx callback runs
Expand All @@ -31,13 +31,13 @@ Environment.getEnvironment().then((envName) => {
});

/**
* Get the currently used API endpoint
* Get the currently used API endpoint, unless forceProduction is set to true
* (Non-production environments allow for dynamically switching the API)
*/
function getApiRoot(request?: Request): string {
function getApiRoot(request?: Request, forceProduction = false): string {
const shouldUseSecure = request?.shouldUseSecure ?? false;

if (shouldUseStagingServer) {
if (shouldUseStagingServer && forceProduction !== true) {
if (CONFIG.IS_USING_WEB_PROXY && !request?.shouldSkipWebProxy) {
return shouldUseSecure ? proxyConfig.STAGING_SECURE : proxyConfig.STAGING;
}
Expand Down
14 changes: 10 additions & 4 deletions src/libs/actions/getCompanyCardBankConnection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ export default function getCompanyCardBankConnection(policyID?: string, bankName
isCorporate: 'true',
scrapeMinDate: '',
};
const commandURL = getApiRoot({
shouldSkipWebProxy: true,
command: '',
});
const bank = CONST.COMPANY_CARDS.BANK_CONNECTIONS[bankConnection as keyof typeof CONST.COMPANY_CARDS.BANK_CONNECTIONS];

// The Amex connection whitelists only our production servers, so we need to always use the production API for American Express
const forceProductionAPI = bank === CONST.COMPANY_CARDS.BANK_CONNECTIONS.AMEX;
const commandURL = getApiRoot(
{
shouldSkipWebProxy: true,
command: '',
},
forceProductionAPI,
);
return `${commandURL}partners/banks/${bank}/oauth_callback.php?${new URLSearchParams(params).toString()}`;
}

0 comments on commit ad61525

Please sign in to comment.