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

added redeemWalletCode method #5

Merged
merged 1 commit into from
Apr 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,14 @@ Gets information about products that your account owns, ignores, wants, or is re

Sends a Steam gift in your inventory to another user. The gift will remain in your inventory until the recipient accepts it.
You can re-send a gift which you've already sent. Gifts don't have to be tradable in order to be sent.

### redeemWalletCode(walletCode[, callback])
- `walletCode` - The Steam wallet code you want to redeem
- `callback` - Optional. Called when the request completes.
- `err` - An `Error` object if the request fails (http error, or response malformed)
- `result` - The result of the request. An object containing two keys: `EResult` containing a value from `SteamStore.EResult` enums and `EPurchaseResult` containing a value from `SteamStore.EPurchaseResult` enums
- `redeemed` - A boolean, true if the wallet code was successfully redeemed

**v1.4.2 or later is required to use this method**

Attempts to redeem a Steam Wallet code.
38 changes: 38 additions & 0 deletions components/account.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
var SteamStore = require('../index.js');
var Cheerio = require('cheerio');

var EPurchaseResult = require('../resources/EPurchaseResult.js')
SteamStore.prototype.EPurchaseResult = EPurchaseResult

var EResult = require('../resources/EResult.js')
SteamStore.prototype.EResult = EResult

SteamStore.prototype.addPhoneNumber = function(number, bypassConfirmation, callback) {
if(typeof bypassConfirmation === 'function') {
callback = bypassConfirmation;
Expand Down Expand Up @@ -242,4 +248,36 @@ SteamStore.prototype.setDisplayLanguages = function(prim_language, sec_languages

callback(null);
});
};

SteamStore.prototype.redeemWalletCode = function(code, callback) {
var self = this;
this.request.post({
"uri": "https://store.steampowered.com/account/validatewalletcode/",
"form": {
"wallet_code": code
},
"json": true
}, function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}

if(!callback){
return;
}

if(!body.success && !body.detail){
callback(new Error("Malformed response"));
return;
}

// arguments: request error, status, wallet code successfully redeemed
callback(null, {
EResult: body.success,
EPurchaseResult: body.detail
}, body.success == EResult.OK && body.detail == EPurchaseResult.NoDetail)
// ^ I have not tested this, but I believe if the above two conditions are
// true then it means the code has been successfully redeemed
});
};
83 changes: 83 additions & 0 deletions resources/EPurchaseResult.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* @enum EPurchaseResult
*/
module.exports = {
"NoDetail": 0,
"AVSFailure": 1,
"InsufficientFunds": 2,
"ContactSupport": 3,
"Timeout": 4,
"InvalidPackage": 5,
"InvalidPaymentMethod": 6,
"InvalidData": 7,
"OthersInProgress": 8,
"AlreadyPurchased": 9,
"WrongPrice": 10,
"FraudCheckFailed": 11,
"CancelledByUser": 12,
"RestrictedCountry": 13,
"BadActivationCode": 14,
"DuplicateActivationCode": 15,
"UseOtherPaymentMethod": 16,
"UseOtherFundingSource": 17,
"InvalidShippingAddress": 18,
"RegionNotSupported": 19,
"AcctIsBlocked": 20,
"AcctNotVerified": 21,
"InvalidAccount": 22,
"StoreBillingCountryMismatch": 23,
"DoesNotOwnRequiredApp": 24,
"CanceledByNewTransaction": 25,
"ForceCanceledPending": 26,
"FailCurrencyTransProvider": 27,
"FailedCyberCafe": 28,
"NeedsPreApproval": 29,
"PreApprovalDenied": 30,
"WalletCurrencyMismatch": 31,
"EmailNotValidated": 32,
"ExpiredCard": 33,
"TransactionExpired": 34,
"WouldExceedMaxWallet": 35,
"MustLoginPS3AppForPurchase": 36,
"CannotShipToPOBox": 37,

// Value-to-name mapping for convenience
"0": "NoDetail",
"1": "AVSFailure",
"2": "InsufficientFunds",
"3": "ContactSupport",
"4": "Timeout",
"5": "InvalidPackage",
"6": "InvalidPaymentMethod",
"7": "InvalidData",
"8": "OthersInProgress",
"9": "AlreadyPurchased",
"10": "WrongPrice",
"11": "FraudCheckFailed",
"12": "CancelledByUser",
"13": "RestrictedCountry",
"14": "BadActivationCode",
"15": "DuplicateActivationCode",
"16": "UseOtherPaymentMethod",
"17": "UseOtherFundingSource",
"18": "InvalidShippingAddress",
"19": "RegionNotSupported",
"20": "AcctIsBlocked",
"21": "AcctNotVerified",
"22": "InvalidAccount",
"23": "StoreBillingCountryMismatch",
"24": "DoesNotOwnRequiredApp",
"25": "CanceledByNewTransaction",
"26": "ForceCanceledPending",
"27": "FailCurrencyTransProvider",
"28": "FailedCyberCafe",
"29": "NeedsPreApproval",
"30": "PreApprovalDenied",
"31": "WalletCurrencyMismatch",
"32": "EmailNotValidated",
"33": "ExpiredCard",
"34": "TransactionExpired",
"35": "WouldExceedMaxWallet",
"36": "MustLoginPS3AppForPurchase",
"37": "CannotShipToPOBox",
}
226 changes: 226 additions & 0 deletions resources/EResult.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
/**
* @enum EResult
*/
module.exports = {
"Invalid": 0,
"OK": 1,
"Fail": 2,
"NoConnection": 3,
"InvalidPassword": 5,
"LoggedInElsewhere": 6,
"InvalidProtocolVer": 7,
"InvalidParam": 8,
"FileNotFound": 9,
"Busy": 10,
"InvalidState": 11,
"InvalidName": 12,
"InvalidEmail": 13,
"DuplicateName": 14,
"AccessDenied": 15,
"Timeout": 16,
"Banned": 17,
"AccountNotFound": 18,
"InvalidSteamID": 19,
"ServiceUnavailable": 20,
"NotLoggedOn": 21,
"Pending": 22,
"EncryptionFailure": 23,
"InsufficientPrivilege": 24,
"LimitExceeded": 25,
"Revoked": 26,
"Expired": 27,
"AlreadyRedeemed": 28,
"DuplicateRequest": 29,
"AlreadyOwned": 30,
"IPNotFound": 31,
"PersistFailed": 32,
"LockingFailed": 33,
"LogonSessionReplaced": 34,
"ConnectFailed": 35,
"HandshakeFailed": 36,
"IOFailure": 37,
"RemoteDisconnect": 38,
"ShoppingCartNotFound": 39,
"Blocked": 40,
"Ignored": 41,
"NoMatch": 42,
"AccountDisabled": 43,
"ServiceReadOnly": 44,
"AccountNotFeatured": 45,
"AdministratorOK": 46,
"ContentVersion": 47,
"TryAnotherCM": 48,
"PasswordRequiredToKickSession": 49,
"AlreadyLoggedInElsewhere": 50,
"Suspended": 51,
"Cancelled": 52,
"DataCorruption": 53,
"DiskFull": 54,
"RemoteCallFailed": 55,
"PasswordNotSet": 56, // obsolete "renamed to PasswordUnset"
"PasswordUnset": 56,
"ExternalAccountUnlinked": 57,
"PSNTicketInvalid": 58,
"ExternalAccountAlreadyLinked": 59,
"RemoteFileConflict": 60,
"IllegalPassword": 61,
"SameAsPreviousValue": 62,
"AccountLogonDenied": 63,
"CannotUseOldPassword": 64,
"InvalidLoginAuthCode": 65,
"AccountLogonDeniedNoMailSent": 66, // obsolete "renamed to AccountLogonDeniedNoMail"
"AccountLogonDeniedNoMail": 66,
"HardwareNotCapableOfIPT": 67,
"IPTInitError": 68,
"ParentalControlRestricted": 69,
"FacebookQueryError": 70,
"ExpiredLoginAuthCode": 71,
"IPLoginRestrictionFailed": 72,
"AccountLocked": 73, // obsolete "renamed to AccountLockedDown"
"AccountLockedDown": 73,
"AccountLogonDeniedVerifiedEmailRequired": 74,
"NoMatchingURL": 75,
"BadResponse": 76,
"RequirePasswordReEntry": 77,
"ValueOutOfRange": 78,
"UnexpectedError": 79,
"Disabled": 80,
"InvalidCEGSubmission": 81,
"RestrictedDevice": 82,
"RegionLocked": 83,
"RateLimitExceeded": 84,
"AccountLogonDeniedNeedTwoFactorCode": 85, // obsolete "renamed to AccountLoginDeniedNeedTwoFactor"
"AccountLoginDeniedNeedTwoFactor": 85,
"ItemOrEntryHasBeenDeleted": 86, // obsolete "renamed to ItemDeleted"
"ItemDeleted": 86,
"AccountLoginDeniedThrottle": 87,
"TwoFactorCodeMismatch": 88,
"TwoFactorActivationCodeMismatch": 89,
"AccountAssociatedToMultiplePlayers": 90, // obsolete "renamed to AccountAssociatedToMultiplePartners"
"AccountAssociatedToMultiplePartners": 90,
"NotModified": 91,
"NoMobileDeviceAvailable": 92, // obsolete "renamed to NoMobileDevice"
"NoMobileDevice": 92,
"TimeIsOutOfSync": 93, // obsolete "renamed to TimeNotSynced"
"TimeNotSynced": 93,
"SMSCodeFailed": 94,
"TooManyAccountsAccessThisResource": 95, // obsolete "renamed to AccountLimitExceeded"
"AccountLimitExceeded": 95,
"AccountActivityLimitExceeded": 96,
"PhoneActivityLimitExceeded": 97,
"RefundToWallet": 98,
"EmailSendFailure": 99,
"NotSettled": 100,
"NeedCaptcha": 101,
"GSLTDenied": 102,
"GSOwnerDenied": 103,
"InvalidItemType": 104,
"IPBanned": 105,

// Value-to-name mapping for convenience
"0": "Invalid",
"1": "OK",
"2": "Fail",
"3": "NoConnection",
"5": "InvalidPassword",
"6": "LoggedInElsewhere",
"7": "InvalidProtocolVer",
"8": "InvalidParam",
"9": "FileNotFound",
"10": "Busy",
"11": "InvalidState",
"12": "InvalidName",
"13": "InvalidEmail",
"14": "DuplicateName",
"15": "AccessDenied",
"16": "Timeout",
"17": "Banned",
"18": "AccountNotFound",
"19": "InvalidSteamID",
"20": "ServiceUnavailable",
"21": "NotLoggedOn",
"22": "Pending",
"23": "EncryptionFailure",
"24": "InsufficientPrivilege",
"25": "LimitExceeded",
"26": "Revoked",
"27": "Expired",
"28": "AlreadyRedeemed",
"29": "DuplicateRequest",
"30": "AlreadyOwned",
"31": "IPNotFound",
"32": "PersistFailed",
"33": "LockingFailed",
"34": "LogonSessionReplaced",
"35": "ConnectFailed",
"36": "HandshakeFailed",
"37": "IOFailure",
"38": "RemoteDisconnect",
"39": "ShoppingCartNotFound",
"40": "Blocked",
"41": "Ignored",
"42": "NoMatch",
"43": "AccountDisabled",
"44": "ServiceReadOnly",
"45": "AccountNotFeatured",
"46": "AdministratorOK",
"47": "ContentVersion",
"48": "TryAnotherCM",
"49": "PasswordRequiredToKickSession",
"50": "AlreadyLoggedInElsewhere",
"51": "Suspended",
"52": "Cancelled",
"53": "DataCorruption",
"54": "DiskFull",
"55": "RemoteCallFailed",
"56": "PasswordUnset",
"57": "ExternalAccountUnlinked",
"58": "PSNTicketInvalid",
"59": "ExternalAccountAlreadyLinked",
"60": "RemoteFileConflict",
"61": "IllegalPassword",
"62": "SameAsPreviousValue",
"63": "AccountLogonDenied",
"64": "CannotUseOldPassword",
"65": "InvalidLoginAuthCode",
"66": "AccountLogonDeniedNoMail",
"67": "HardwareNotCapableOfIPT",
"68": "IPTInitError",
"69": "ParentalControlRestricted",
"70": "FacebookQueryError",
"71": "ExpiredLoginAuthCode",
"72": "IPLoginRestrictionFailed",
"73": "AccountLockedDown",
"74": "AccountLogonDeniedVerifiedEmailRequired",
"75": "NoMatchingURL",
"76": "BadResponse",
"77": "RequirePasswordReEntry",
"78": "ValueOutOfRange",
"79": "UnexpectedError",
"80": "Disabled",
"81": "InvalidCEGSubmission",
"82": "RestrictedDevice",
"83": "RegionLocked",
"84": "RateLimitExceeded",
"85": "AccountLoginDeniedNeedTwoFactor",
"86": "ItemDeleted",
"87": "AccountLoginDeniedThrottle",
"88": "TwoFactorCodeMismatch",
"89": "TwoFactorActivationCodeMismatch",
"90": "AccountAssociatedToMultiplePartners",
"91": "NotModified",
"92": "NoMobileDevice",
"93": "TimeNotSynced",
"94": "SMSCodeFailed",
"95": "AccountLimitExceeded",
"96": "AccountActivityLimitExceeded",
"97": "PhoneActivityLimitExceeded",
"98": "RefundToWallet",
"99": "EmailSendFailure",
"100": "NotSettled",
"101": "NeedCaptcha",
"102": "GSLTDenied",
"103": "GSOwnerDenied",
"104": "InvalidItemType",
"105": "IPBanned",
};