Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epic: game data and purchase URL from JSON API #130

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
eg: try to wait for response confirm-order instead of text on empty page
vogler committed May 11, 2023
commit 32922571720e400fde592cc61253bce478652333
12 changes: 11 additions & 1 deletion epic-games.js
Original file line number Diff line number Diff line change
@@ -193,6 +193,9 @@ try {
continue;
}

// After successful order using the `purchaseURL`-method, the page is just empty, without any 'Thanks for your order', so we wait for the response of their API. Note: no await, and start waiting before final click to 'Place Order'.
const r = page.waitForResponse(r => r.url().startsWith('https://payment-website-pci.ol.epicgames.com/purchase/confirm-order'));

// Playwright clicked before button was ready to handle event, https://github.com/vogler/free-games-claimer/issues/84#issuecomment-1474346591
await page.locator('button:has-text("Place Order"):not(:has(.payment-loading--loading))').click({ delay: 11 });

@@ -214,7 +217,14 @@ try {
// console.info(' Saved a screenshot of hcaptcha challenge to', p);
// console.error(' Got hcaptcha challenge. To avoid it, get a link from https://www.hcaptcha.com/accessibility'); // TODO save this link in config and visit it daily to set accessibility cookie to avoid captcha challenge?
}).catch(_ => { }); // may time out if not shown
await page.waitForSelector('text=Thanks for your order!');
// await page.waitForSelector('text=Thanks for your order!'); // not shown for order via `purchaseURL`
const rt = await (await r).text(); // TODO blocks if not claimed?
const rj = JSON.parse(rt);
if (rj?.receiptResponse?.orderStatus != 'COMPLETED') {
console.error('Unexpected confirm-order response. Message:', rj.message);
console.log(rj);
continue;
}
db.data[user][game_id].status = 'claimed';
db.data[user][game_id].time = datetime(); // claimed time overwrites failed/dryrun time
console.log(' Claimed successfully!');