Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getFundingEligibilityParam(req : ExpressRequest) : FundingEligibility {
const encodedFundingEligibility = req.query.fundingEligibility;
if (encodedFundingEligibility && typeof encodedFundingEligibility === 'string') {
return JSON.parse(
Buffer.from(encodedFundingEligibility, 'base64').toString('utf8')
);
}
// $FlowFixMe
return {
[ FUNDING.PAYPAL ]: {
eligible: true
}
};
}
export async function clickButton(fundingSource? : string = FUNDING.PAYPAL, card? : string = CARD.VISA) : ZalgoPromise {
let selector = `button[data-funding-source=${ fundingSource }]`;
if (fundingSource === FUNDING.CARD) {
selector = `${ selector }[data-card=${ card }]`;
}
const button = window.document.querySelector(selector);
button.click();
await button.payPromise;
}
export function enterButton(fundingSource? : string = FUNDING.PAYPAL) {
triggerKeyPress(window.document.querySelector(`button[data-funding-source=${ fundingSource }]`), 13);
}
export const DEFAULT_FUNDING_ELIGIBILITY = {
[ FUNDING.PAYPAL ]: {
eligible: true
}
};
export function createButtonHTML(fundingEligibility? : Object = DEFAULT_FUNDING_ELIGIBILITY) {
const buttons = [];
for (const fundingSource of values(FUNDING)) {
const fundingConfig = fundingEligibility[fundingSource];
if (!fundingConfig || !fundingConfig.eligible) {
continue;
}
buttons.push(`<button data-funding-source="${ fundingSource }">`);
</button>
return await wrapPromise(async ({ expect }) => {
const fundingSource = FUNDING.PAYPAL;
mockFunction(window.paypal, 'Checkout', expect('Checkout', ({ args: [ props ] }) => {
if (props.fundingSource !== fundingSource) {
throw new Error(`Expected fundingSource to be ${ fundingSource }, got ${ props.fundingSource }`);
}
return {
renderTo: promiseNoop
};
}));
createButtonHTML();
await mockSetupButton({ merchantID: [ 'XYZ12345' ], fundingEligibility: DEFAULT_FUNDING_ELIGIBILITY });
await clickButton(fundingSource);
eligible: types.boolean,
vaultable: types.boolean,
vaultedInstruments: getVaultedInstrumentQuery()
};
};
const getCardQuery = () => {
return {
eligible: types.boolean,
branded: types.boolean,
vendors: getVendorQuery()
};
};
const fundingQuery = {
[ FUNDING.PAYPAL ]: getPayPalQuery(),
[ FUNDING.CARD ]: getCardQuery(),
[ FUNDING.VENMO ]: getBasicFundingEligibilityQuery(),
[ FUNDING.ITAU ]: getBasicFundingEligibilityQuery(),
[ FUNDING.CREDIT ]: getBasicFundingEligibilityQuery(),
[ FUNDING.SEPA ]: getBasicFundingEligibilityQuery(),
[ FUNDING.IDEAL ]: getBasicFundingEligibilityQuery(),
[ FUNDING.BANCONTACT ]: getBasicFundingEligibilityQuery(),
[ FUNDING.GIROPAY ]: getBasicFundingEligibilityQuery(),
[ FUNDING.EPS ]: getBasicFundingEligibilityQuery(),
[ FUNDING.SOFORT ]: getBasicFundingEligibilityQuery(),
[ FUNDING.MYBANK ]: getBasicFundingEligibilityQuery(),
[ FUNDING.P24 ]: getBasicFundingEligibilityQuery(),
[ FUNDING.ZIMPLER ]: getBasicFundingEligibilityQuery(),
[ FUNDING.WECHATPAY ]: getBasicFundingEligibilityQuery(),
[ FUNDING.PAYU ]: getBasicFundingEligibilityQuery(),
[ FUNDING.BLIK ]: getBasicFundingEligibilityQuery(),