mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Refactor openPaypalPopup options, add fundingSource
This commit is contained in:
parent
2c0b436510
commit
39b5673435
1 changed files with 13 additions and 5 deletions
|
@ -8,16 +8,24 @@ const {
|
|||
/**
|
||||
* Opens the PayPal popup by pressing the button, and returns the popup object.
|
||||
* @param page
|
||||
* @param {{timeout: ?int, fundingSource: ?string}} options
|
||||
* @param {boolean} retry Retries the button click if the popup did not appear after timeout.
|
||||
* @param {int} timeout
|
||||
*/
|
||||
export const openPaypalPopup = async (page, retry = true, timeout = 5000) => {
|
||||
export const openPaypalPopup = async (page, options = {}, retry = true) => {
|
||||
options = {
|
||||
...{
|
||||
timeout: 5000,
|
||||
fundingSource: 'paypal',
|
||||
},
|
||||
...options
|
||||
};
|
||||
|
||||
try {
|
||||
await page.locator('.component-frame').scrollIntoViewIfNeeded();
|
||||
|
||||
const [popup] = await Promise.all([
|
||||
page.waitForEvent('popup', {timeout}),
|
||||
page.frameLocator('.component-frame').locator('[data-funding-source="paypal"]').click(),
|
||||
page.waitForEvent('popup', {timeout: options.timeout}),
|
||||
page.frameLocator('.component-frame').locator(`[data-funding-source="${options.fundingSource}"]`).click(),
|
||||
]);
|
||||
|
||||
await popup.waitForLoadState();
|
||||
|
@ -41,7 +49,7 @@ export const openPaypalPopup = async (page, retry = true, timeout = 5000) => {
|
|||
}
|
||||
|
||||
if (retry) {
|
||||
return openPaypalPopup(page, false);
|
||||
return openPaypalPopup(page, options, false);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue