Jump to content
McKay Development

Add game to cart and buy it ?


SENPAY98K

Recommended Posts

Hi,
is it posible to add games to cart and buy with steam balance ?
Tried it, but not sure if im skipping/missung other requests.

// Add games to cart
for (let i = 0; i < arrayGames.length; i++) {
	var gameID = Number(arrayGames[i]);
	logINFO(`gameID: ` + gameID);

	await addToCart(Steam, Community, sessionID, gameID);
	await SLEEP(5000);
}
// Get transaction id
let purchaseId = await scrapTransactionID(Community);
logINFO(purchaseId);
// Buy games in cart
await purchaseGames(Community, purchaseId);

function addToCart(Steam, Community, sessionID, subid) {
	return new Promise((resolve) => {
		Community.httpRequestPost(
			`https://store.steampowered.com/cart/`,
			{
				form: {
					snr: "1_5_9__403",
					originating_snr: "1_direct-navigation__",
					action: "add_to_cart",
					sessionid: sessionID,
					subid: subid,
				},
				headers: {
					Host: "store.steampowered.com",
					Origin: "https://store.steampowered.com",
				},
				json: true,
			},
			(err, res, body) => {
				if (!err && res.resposeCode == 200) {
					logINFO(`Success`);
				} else {
					logERROR(`Failed`);
				}
			}
		);
		resolve();
	});
} // func()

function scrapTransactionID(Community) {
	return new Promise((resolve) => {
		Community.httpRequestPost(
			`https://store.steampowered.com/cart`,
			(err, res, body) => {
				if (!err) {
					let pattern = /https:\/\/store.steampowered.com\/checkout\/\?purchasetype=gift&cart=(\d+)&/;
					let match = body.match(pattern);
					if (match) {
						logINFO(`Matched: ` + match[1]);
						resolve(match[1]);
					}
				}
			}
		);
	});
} //func()

function purchaseGames(Community, purchaseId) {
	return new Promise((resolve) => {
		Community.httpRequestPost(
			`https://store.steampowered.com/checkout/finalizetransaction/`,
			{
				form: {
					transid: purchaseId,
					CardCVV2: "",
					browserInfo: {
						language: "en-US",
						javaEnabled: "false",
						colorDepth: 24,
						screenHeight: 600,
						screenWidth: 800,
					},
				},
				headers: {
					Host: "store.steampowered.com",
					Origin: "https://store.steampowered.com",
					Referer: `https://store.steampowered.com/checkout/?purchasetype=self&cart=${purchaseId}&snr=1_8_4__503`,
				},
				json: true,
			},
			(err, res, body) => {
				if (!err) {
					logINFO("success");
				}
			}
		);
		resolve();
	});
} //func()

 

Link to comment
Share on other sites

  • 1 year later...
Just now, vlk_pro said:

heelo, did you handle this script ? im trying to add any game to cart and buy, but i can't ?

so much things changed on steam backend, but you can use ASF + ASFEnahanced plugin for less hassle

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...