@@ -155,6 +155,7 @@ try {
155
155
// await (await card.$('text=Claim')).click(); // goes to URL of game, no need to wait
156
156
external_info . push ( { title, url } ) ;
157
157
}
158
+ // external_info = [ { title: 'Fallout 76 (XBOX)', url: 'https://gaming.amazon.com/fallout-76-xbox-fgwp/dp/amzn1.pg.item.9fe17d7b-b6c2-4f58-b494-cc4e79528d0b?ingress=amzn&ref_=SM_Fallout76XBOX_S01_FGWP_CRWN' } ];
158
159
for ( const { title, url } of external_info ) {
159
160
console . log ( 'Current free game:' , title ) ; // , url);
160
161
await page . goto ( url , { waitUntil : 'domcontentloaded' } ) ;
@@ -185,7 +186,8 @@ try {
185
186
const redeem = {
186
187
// 'origin': 'https://www.origin.com/redeem', // TODO still needed or now only via account linking?
187
188
'gog.com' : 'https://www.gog.com/redeem' ,
188
- 'microsoft games' : 'https://redeem.microsoft.com' ,
189
+ 'microsoft store' : 'https://account.microsoft.com/billing/redeem' ,
190
+ xbox : 'https://account.microsoft.com/billing/redeem' ,
189
191
'legacy games' : 'https://www.legacygames.com/primedeal' ,
190
192
} ;
191
193
if ( store in redeem ) { // did not work for linked origin: && !await page.locator('div:has-text("Successfully Claimed")').count()
@@ -240,27 +242,44 @@ try {
240
242
console . log ( ' Unknown Response 2 - please report in https://github.com/vogler/free-games-claimer/issues/5' ) ;
241
243
}
242
244
}
243
- } else if ( store == 'microsoft games' ) {
244
- console . error ( ` Redeem on ${ store } not yet implemented!` ) ;
245
+ } else if ( store == 'microsoft store' || store == 'xbox' ) {
246
+ console . error ( ` Redeem on ${ store } is experimental!` ) ;
247
+ // await page2.pause();
245
248
if ( page2 . url ( ) . startsWith ( 'https://login.' ) ) {
246
- console . error ( ' Not logged in! Use the browser to login manually.' ) ;
249
+ console . error ( ' Not logged in! Use the browser to login manually. Waiting for 60s.' ) ;
250
+ await page2 . waitForTimeout ( 60 * 1000 ) ;
247
251
redeem_action = 'redeem (login)' ;
248
252
} else {
249
- const r = page2 . waitForResponse ( r => r . url ( ) . startsWith ( 'https://purchase.mp.microsoft.com/' ) ) ;
250
- await page2 . fill ( '[name=tokenString]' , code ) ;
253
+ const iframe = page2 . frameLocator ( '#redeem-iframe' ) ;
254
+ const input = iframe . locator ( '[name=tokenString]' ) ;
255
+ await input . waitFor ( ) ;
256
+ await input . fill ( code ) ;
257
+ const r = page2 . waitForResponse ( r => r . url ( ) . startsWith ( 'https://cart.production.store-web.dynamics.com/v1.0/Redeem/PrepareRedeem' ) ) ;
251
258
// console.log(await page2.locator('.redeem_code_error').innerText());
252
259
const rt = await ( await r ) . text ( ) ;
253
- console . debug ( ` Response: ${ rt } ` ) ;
254
260
// {"code":"NotFound","data":[],"details":[],"innererror":{"code":"TokenNotFound",...
255
- const reason = JSON . parse ( rt ) . code ;
256
- if ( reason == 'NotFound' ) {
261
+ const j = JSON . parse ( rt ) ;
262
+ const reason = j ?. events ?. cart . length && j . events . cart [ 0 ] ?. data ?. reason ;
263
+ if ( reason == 'TokenNotFound' ) {
257
264
redeem_action = 'redeem (not found)' ;
258
265
console . error ( ' Code was not found!' ) ;
266
+ } else if ( j ?. productInfos ?. length && j . productInfos [ 0 ] ?. redeemable ) {
267
+ await iframe . locator ( 'button:has-text("Next")' ) . click ( ) ;
268
+ await iframe . locator ( 'button:has-text("Confirm")' ) . click ( ) ;
269
+ const r = page2 . waitForResponse ( r => r . url ( ) . startsWith ( 'https://cart.production.store-web.dynamics.com/v1.0/Redeem/RedeemToken' ) ) ;
270
+ const j = JSON . parse ( await ( await r ) . text ( ) ) ;
271
+ if ( j ?. events ?. cart . length && j . events . cart [ 0 ] ?. data ?. reason == 'UserAlreadyOwnsContent' ) {
272
+ redeem_action = 'already redeemed' ;
273
+ console . error ( ' error: UserAlreadyOwnsContent' ) ;
274
+ } else if ( true ) { // TODO what's returned on success?
275
+ redeem_action = 'redeemed' ;
276
+ db . data [ user ] [ title ] . status = 'claimed and redeemed?' ;
277
+ console . log ( ' Redeemed successfully? Please report if not in https://github.com/vogler/free-games-claimer/issues/5' ) ;
278
+ }
259
279
} else { // TODO find out other responses
260
- await page2 . click ( '#nextButton' ) ;
261
- redeem_action = 'redeemed?' ;
280
+ redeem_action = 'unknown' ;
281
+ console . debug ( ` Response: ${ rt } ` ) ;
262
282
console . log ( ' Redeemed successfully? Please report your Response from above (if it is new) in https://github.com/vogler/free-games-claimer/issues/5' ) ;
263
- db . data [ user ] [ title ] . status = 'claimed and redeemed?' ;
264
283
}
265
284
}
266
285
} else if ( store == 'legacy games' ) {
0 commit comments