-
-
Save claytonzaugg/55fcb7494a88c8251c32483c61fdc4c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'click .reorder-item-button': function() { | |
var Service = 'Service=AWSECommerceService', | |
AWSAccessKeyId = 'AWSAccessKeyId=#####', | |
AssociateTag = 'AssociateTag=#####', | |
Operation = 'Operation=CartCreate', | |
Item1OfferListingId = 'Item.1.OfferListingId=B000062TU1', | |
Item1ASIN = 'Item.1.ASIN=' + this.ASIN, | |
Item1Quantity = 'Item.1.Quantity=2', | |
today = new Date(), | |
Timestamp = 'Timestamp=' + today.toISOString(), | |
Signature = 'Signature=', | |
ResponseGroup = 'ResponseGroup=Cart'; | |
var rawUriParameters = Service + '&' + AWSAccessKeyId + '&' + AssociateTag + '&' + Operation + '&' + Item1ASIN + '&' + Item1Quantity + '&' + ResponseGroup + '&' + Timestamp; | |
console.log('rawUriParameters: \n' + rawUriParameters); | |
function encodeUriParameters(str) { | |
return encodeURIComponent(str).replace(/[!'()*]/g, function(c) { | |
return '%' + c.charCodeAt(0).toString(16); | |
}); | |
} | |
var encodedUriParameters = encodeUriParameters(rawUriParameters); | |
console.log('encodedUriParameters: \n' + encodedUriParameters); | |
function addLineBreaksToEncodedURI(str) { | |
var paramaterArray = str.split("%26"); | |
paramaterArray.sort(); | |
var parameterStringified = ''; | |
for (var i = 0; i < paramaterArray.length; i++) { | |
if (i < paramaterArray.length - 1) { | |
parameterStringified += paramaterArray[i] + "\n"; | |
} else { | |
parameterStringified += paramaterArray[i]; | |
} | |
} | |
return parameterStringified.replace(/%3D/g, "="); | |
} | |
var uriWithLineBreaks = addLineBreaksToEncodedURI(encodedUriParameters); | |
console.log('uriWithLineBreaks: \n' + uriWithLineBreaks); | |
function reconstructUriWithAmpersands(str) { | |
return str.replace(/\n/g, "&"); | |
} | |
var uriReconstructedWithAmpersands = reconstructUriWithAmpersands(uriWithLineBreaks); | |
console.log('uriReconstructedWithAmpersands: \n' + uriReconstructedWithAmpersands); | |
function addRequiredLinesBeforeSigning(str) { | |
return 'GET\n' + 'webservices.amazon.com\n' + '/onca/xml\n' + str; | |
} | |
console.log('addRequiredLinesBeforeSigning: ' + '\n' + addRequiredLinesBeforeSigning(uriReconstructedWithAmpersands)); | |
var rawHash = CryptoJS.HmacSHA256(addRequiredLinesBeforeSigning(uriReconstructedWithAmpersands), '#####').toString(); | |
console.log('rawHash: \n' + rawHash); | |
var encodedHash = encodeUriParameters(rawHash); | |
console.log('encodedHash: \n' + encodedHash + '\n'); | |
console.log('http://webservices.amazon.com/onca/xml?' + uriReconstructedWithAmpersands + '&' + Signature + encodedHash); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment