Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

bug fixes

  • Loading branch information...
commit dabb46dca37472b06e895927c5b63e6363a99d14 1 parent 8df5fd5
@robrighter authored
View
1  .gitignore
@@ -0,0 +1 @@
+config.js
View
4 example-config.js
@@ -0,0 +1,4 @@
+module.exports = {
+ AWS_ACCESS_KEY_ID: 'YOUR ACCESS KEY HERE',
+ AWS_SECRET_ACCESS_KEY: 'YOUR SECRET HERE'
+};
View
12 example.js
@@ -0,0 +1,12 @@
+var PipeLine = require('./lib/amazon-fps-cbui-pipeline');
+var config = require('./config.js');
+
+var singleUse = new PipeLine('SingleUse', config.AWS_ACCESS_KEY_ID, config.AWS_SECRET_ACCESS_KEY);
+
+singleUse.addParameter("callerReference","callerReferenceSingleUse");
+singleUse.addParameter("returnURL","http://www.mysite.com/call_back.jsp");
+singleUse.addParameter("transactionAmount","5");
+singleUse.addParameter("currencyCode", "USD");
+singleUse.addParameter("paymentReason", "HarryPotter 1-5 DVD set");
+
+console.log("Sample CBUI url for SingleUse pipeline : " + singleUse.getURL());
View
57 lib/amazon-fps-cbui-pipeline.js
@@ -36,13 +36,29 @@
parameters["signatureVersion"] = SIGNATURE_VERSION;
parameters["signatureMethod"] = SIGNATURE_METHOD;
- this.addParameter = function(key, value){ parameters[key] };
+ this.addParameter = function(key, value){
+ parameters[key] = value;
+ };
this.addOptionalParameters = function(params) {
Object.keys(params).forEach(function(key){
parameters[key] = params[key];
});
}
+
+ /**
+ * Constructs the query string for the parameters added to this class
+ *
+ * This function also calculates the signature of the all the name value pairs
+ * added to the class.
+ *
+ * @return string URL
+ */
+ this.getURL = function() {
+ validateParameters('all',parameters);
+ validateParameters(parameters.pipelineName,parameters);
+ return constructUrl(parameters);
+ }
/**
* Computes RFC 2104-compliant HMAC signature for request parameters
@@ -72,9 +88,9 @@
* Pairs of parameter and values are separated by the '&' character (ASCII code 38).
*
*/
- this.signParameters = function(parameters, httpMethod, host, requestURI){
- signatureVersion = parameters[SIGNATURE_VERSION_KEYNAME];
- algorithm HMAC_SHA1_ALGORITHM;
+ signParameters = function(parameters, httpMethod, host, requestURI){
+ var signatureVersion = parameters[SIGNATURE_VERSION_KEYNAME];
+ var algorithm = HMAC_SHA1_ALGORITHM;
var stringToSign = null;
if (2 === signatureVersion) {
algorithm = parameters[SIGNATURE_METHOD_KEYNAME];
@@ -91,8 +107,8 @@
* @return String to Sign
*/
var calculateStringToSignV1 = function(parameters) {
- data = '';
- parameters = makeSortedObject(parameters,false);
+ var data = '';
+ var parameters = makeSortedObject(parameters,false);
parameters.forEach(function(param){
data += (param['key'] + param['value']);
});
@@ -123,8 +139,6 @@
var uriencoded = requestURI.split('/').map(escape).join('/');
- var uriencoded = implode("/", array_map(array("Amazon_FPS_CBUIPipeline", "_urlencode"), explode("/", $requestURI)));
-
data += uriencoded;
data += "\n";
@@ -166,7 +180,7 @@
}
var hostHeader = getHostHeader(CBUI_URL);
var requestURI = getRequestURI(CBUI_URL);
- var signature = this.signParameters(parameters, HTTP_GET_METHOD, hostHeader, requestURI);
+ var signature = signParameters(parameters, HTTP_GET_METHOD, hostHeader, requestURI);
parameters["signature"] = signature;
return CBUI_URL + "?" + buildQueryString(parameters);
}
@@ -215,28 +229,19 @@
});
}
- /**
- * Constructs the query string for the parameters added to this class
- *
- * This function also calculates the signature of the all the name value pairs
- * added to the class.
- *
- * @return string URL
- */
- this.getURL = function() {
- validateParameters('all',parameters);
- validateParameters(parameters.pipelineName,parameters);
- return constructUrl(parameters);
- }
//////////////////////////////////////////////
// UTILS //
//////////////////////////////////////////////
+ function urlEncode(toencode){
+ return escape(toencode).replace(/\//g,'%2F');
+ }
+
function buildQueryString(params){
- Object.keys(params).map(function(p){
- return escape(p) + "=" + escape(params[p]) + '&';
- });
+ return Object.keys(params).map(function(p){
+ return escape(p) + "=" + urlEncode(params[p]);
+ }).join('&');
}
/**
@@ -244,7 +249,7 @@
*/
function getParametersAsString(parameters) {
return parameters.map(function(param){
- return (param.key + '=' + escape(param.value));
+ return (param.key + '=' + urlEncode(param.value));
}).join('&');
}

0 comments on commit dabb46d

Please sign in to comment.
Something went wrong with that request. Please try again.