Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
clientAccessToken? : string,
csp? : {
nonce? : string
},
cardButtonExperiment? : boolean
|};
export const DEFAULT_STYLE = {
LAYOUT: BUTTON_LAYOUT.VERTICAL,
COLOR: BUTTON_COLOR.GOLD,
SHAPE: BUTTON_SHAPE.RECT
};
export const DEFAULT_PROPS = {
LOCALE: {
country: COUNTRY.US,
lang: LANG.EN
},
COMMIT: COMMIT.TRUE,
VAULT: VAULT.FALSE,
INTENT: INTENT.CAPTURE,
ENV: ENV.PRODUCTION,
PLATFORM: PLATFORM.DESKTOP
};
// $FlowFixMe
export function normalizeButtonStyle(style : ButtonStyleInputs) : ButtonStyle {
if (!style) {
throw new Error(`Expected props.style to be set`);
}
clientAccessToken? : string,
csp? : {
nonce? : string
},
content? : { [string] : string }
|};
export const DEFAULT_STYLE = {
LAYOUT: BUTTON_LAYOUT.VERTICAL,
COLOR: BUTTON_COLOR.GOLD,
SHAPE: BUTTON_SHAPE.RECT
};
export const DEFAULT_PROPS = {
LOCALE: {
country: COUNTRY.US,
lang: LANG.EN
},
COMMIT: COMMIT.TRUE,
VAULT: VAULT.FALSE,
INTENT: INTENT.CAPTURE,
ENV: ENV.PRODUCTION,
PLATFORM: PLATFORM.DESKTOP
};
// $FlowFixMe
export function normalizeButtonStyle(style : ButtonStyleInputs) : ButtonStyle {
if (!style) {
throw new Error(`Expected props.style to be set`);
}
// $FlowFixMe
return { country, lang };
}
}
for (const { country } of getBrowserLocales()) {
// $FlowFixMe
if (COUNTRY_LANGS.hasOwnProperty(country)) {
// $FlowFixMe
return { country, lang: COUNTRY_LANGS[country][0] };
}
}
return {
lang: LANG.EN,
country: COUNTRY.US
};
}
}
return renderToOriginal(...args);
});
}));
return checkoutInstance;
}));
createButtonHTML();
await mockSetupButton({
merchantID: [ 'XYZ12345' ],
fundingEligibility: DEFAULT_FUNDING_ELIGIBILITY,
personalization: {},
buyerCountry: COUNTRY.US,
isCardFieldsExperimentEnabled: false
});
await clickButton(FUNDING.PAYPAL);
});
});
}
return renderToOriginal(...args);
});
}));
return checkoutInstance;
}));
createButtonHTML();
await mockSetupButton({
merchantID: [ 'XYZ12345' ],
fundingEligibility: DEFAULT_FUNDING_ELIGIBILITY,
personalization: {},
buyerCountry: COUNTRY.US,
isCardFieldsExperimentEnabled: false
});
await clickButton(FUNDING.PAYPAL);
gqlMock.done();
});
});
export async function mockSetupButton(overrides? : Object = {}) : ZalgoPromise {
await setupButton({
facilitatorAccessToken: 'QQQ123000',
merchantID: [ 'XYZ12345' ],
fundingEligibility: DEFAULT_FUNDING_ELIGIBILITY,
personalization: {},
buyerCountry: COUNTRY.US,
isCardFieldsExperimentEnabled: false,
firebaseConfig: MOCK_FIREBASE_CONFIG,
eligibility: {
cardFields: false,
native: false
},
sdkMeta: MOCK_SDK_META,
...overrides
});
}
export function getServiceData({ facilitatorAccessToken, sdkMeta, buyerGeoCountry, fundingEligibility, personalization, serverMerchantID, eligibility } : ServiceDataOptions) : ServiceData {
return {
merchantID: serverMerchantID,
buyerCountry: buyerGeoCountry || COUNTRY.US,
fundingEligibility,
sdkMeta,
personalization,
facilitatorAccessToken,
eligibility
};
}
export function setupButton(fundingEligibility : Object) : ZalgoPromise {
if (!window.paypal) {
throw new Error(`PayPal library not loaded`);
}
setupLogger();
const buyerCountry = window.xprops.buyerCountry || fundingEligibility.buyerCountry || COUNTRY.US;
if (fundingEligibility.fundingEligibility) {
fundingEligibility = fundingEligibility.fundingEligibility;
}
let buttonEnabled = true;
const checkout = ({ win, fundingSource, card, paymentMethodID } : { win? : ProxyWindow, fundingSource : $Values, card : ?$Values, paymentMethodID? : ?string }) => {
const validationPromise = onClickValidate({ fundingSource, card });
if (!buttonEnabled) {
return ZalgoPromise.try(() => {
if (win) {
return win.close();
}
});