diff --git a/README.md b/README.md index 9126dae..69c2032 100644 --- a/README.md +++ b/README.md @@ -160,3 +160,15 @@ redeemable, the callback will be invoked with an `Error` passed as the first par **v1.5.0 or later is required to use this method** Updates your account's display languages for the Steam store. + +### redeemGameKey(gameKey[, callback]) +- `gameKey` - The Steam game key you want to redeem +- `callback` - Optional. Called when the request completes. + - `err` - An `Error` object if the request fails, or `null` on success + - `eresult` - An `EResult` value from `SteamStore.EResult` + - `ekeyactivationresult` - A value from `SteamStore.EKeyActivationResult` + - `purchase_receipt_info` - Info about the redeemed key + +**v1.6.0 or later is required to use this method** + +Attempts to redeem a Steam game key on your account. \ No newline at end of file diff --git a/components/account.js b/components/account.js index d08c649..5714b69 100644 --- a/components/account.js +++ b/components/account.js @@ -7,6 +7,9 @@ SteamStore.prototype.EPurchaseResult = EPurchaseResult; var EResult = require('../resources/EResult.js'); SteamStore.prototype.EResult = EResult; +var EKeyActivationResult = require('../resources/EKeyActivationResult.js'); +SteamStore.prototype.EKeyActivationResult = EKeyActivationResult; + SteamStore.prototype.addPhoneNumber = function(number, bypassConfirmation, callback) { if(typeof bypassConfirmation === 'function') { callback = bypassConfirmation; @@ -318,3 +321,30 @@ SteamStore.prototype.redeemWalletCode = function(code, callback) { }); }); }; + +SteamStore.prototype.redeemGameKey = function(code, callback) { + var self = this; + self.request.post({ + "uri": "https://store.steampowered.com/account/ajaxregisterkey/", + "form": { + "product_key": code, + "sessionid": this.getSessionID() + }, + "json": true + }, function(err, response, body) { + if (!callback) { + return; + } + + if (self._checkHttpError(err, response, callback)) { + return; + } + + if (!body.success && !body.purchase_receipt_info) { + callback(new Error("Malformed response")); + return; + } + + callback(null, body.success, body.purchase_result_details, body.purchase_receipt_info); + }); +}; diff --git a/resources/EKeyActivationResult.js b/resources/EKeyActivationResult.js new file mode 100644 index 0000000..dbc5da1 --- /dev/null +++ b/resources/EKeyActivationResult.js @@ -0,0 +1,27 @@ +/** + * @enum EKeyActivationResult + */ +module.exports = { + "Success": 0, // Key redeemed successfully + "UnexpectedError": 4, // Unexpected Error + "AlreadyInAccount": 9, // Account already has the product + "CountryRestriction": 13, // Product key not available in country + "InvalidProductKey": 14, // Invalid product key + "UsedProductKey": 15, // Product key already used + "GameRequired": 24, // Activating the product key requires another product in account + "PlayOnPS3": 36, // Game can only activated when played on PS3 + "AccountBalanceKey": 50, // Key is a balance card + "TooManyActivations": 53, // Too many activations from account or IP + + // Value-to-name mapping for convenience + "0": "Success", + "4": "UnexpectedError", + "9": "AlreadyInAccount", + "13": "CountryRestriction", + "14": "InvalidProductKey", + "15": "UsedProductKey", + "24": "GameRequired", + "36": "PlayOnPS3", + "50": "AccountBalanceKey", + "53": "TooManyActivations", +};