tpv uri decode fix

parent ffaf5090
Showing with 2 additions and 18 deletions
......@@ -34,8 +34,8 @@ function encodeMerchantParams(object) {
function decodeMerchantParams(string) {
// Base64 encoding of parameters
var merchantWordArray = cryptojs.enc.Base64.parse(string);
return JSON.parse(merchantWordArray.toString(cryptojs.enc.Utf8));
var merchantWordArray = decodeURI(cryptojs.enc.Base64.parse(string));
return JSON.parse(decodeURIComponent(merchantWordArray.toString(cryptojs.enc.Utf8)));
}
function signMerchantParams(params, key) {
......@@ -117,12 +117,9 @@ module.exports = {
*/
notify: function(req, res) {
console.log("starting notify method");
var params = req.allParams();
if (!params.Ds_Signature || !params.Ds_MerchantParameters){
console.log("bad request");
return res.badRequest();
}
......@@ -134,19 +131,13 @@ module.exports = {
var key = cipherMerchantKey(decodedParams.Ds_Order, sails.config.pictogram.tpv.key);
var signatureBase64 = signMerchantParams(postParams, key);
if (postSignature != signatureBase64) {
console.log("postSignature != signatureBase64 (1)");
// Try again if some URLSafe replacement has been done
signatureBase64 = signatureBase64.replace(/\+/gi, "-"); // Change any plus (+) characters to dashes (-)
signatureBase64 = signatureBase64.replace(/\//gi, "_"); // Change any slashes (/) characters to underscores (_)
if (postSignature != signatureBase64) {
console.log("postSignature != signatureBase64 (2)");
sails.log.debug("tpv/notify: Signature verification on TPV operation failed");
return res.badRequest("Invalid signature");
}
......@@ -159,7 +150,6 @@ module.exports = {
// Generate new license and use ID for order
//
new Promise((resolve, reject) => {
console.log("new promise");
License.genLicenseNumber((number) => {
if (number)
resolve(number);
......@@ -168,7 +158,6 @@ module.exports = {
});
})
.then((number) => {
console.log("then number");
return License.create({
number: number,
duration: ownParams.type == 'forever' ? 1200 : 12,
......@@ -176,19 +165,14 @@ module.exports = {
});
})
.then((license) => {
console.log("then license");
if (!license){
console.log("not license");
throw new Error("Unable to create license");
}
License.activate(license.number, parseInt(ownParams.id_stu), function(err, license) {
if (err){
console.log("activate license err");
return res.badRequest(err);
}
console.log("res ok license");
sails.log.debug("New license sold! " + license.number);
return res.ok(license);
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment