tpv uri decode fix

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