Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
yotta
/
pictogram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
60
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
24d5e770
authored
Sep 18, 2017
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
working on tpv issues
parent
70486bdc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
12 deletions
sails/src/api/controllers/TPVController.js
sails/src/api/controllers/TPVController.js
View file @
24d5e770
...
...
@@ -80,12 +80,12 @@ module.exports = {
DS_MERCHANT_CURRENCY
:
'978'
,
// Terminal currency
DS_MERCHANT_TRANSACTIONTYPE
:
"0"
,
// Type of the transaction (0: authorized)
DS_MERCHANT_AMOUNT
:
amount
+
"00"
,
// Amount
DS_MERCHANT_ORDER
:
moment
().
format
(
'YYMM
DD
'
)
+
params
.
id_stu
.
toString
().
slice
(
-
6
),
// hast to be from 4 to 12 characters long
DS_MERCHANT_MERCHANTURL
:
'https://'
+
req
.
headers
.
host
+
"/tpv/notify
/"
+
params
.
id_stu
,
// notification to activate
DS_MERCHANT_ORDER
:
moment
().
format
(
'YYMM
mm
'
)
+
params
.
id_stu
.
toString
().
slice
(
-
6
),
// hast to be from 4 to 12 characters long
DS_MERCHANT_MERCHANTURL
:
'https://'
+
req
.
headers
.
host
+
"/tpv/notify
"
,
// notification to activate
DS_MERCHANT_URLOK
:
'https://'
+
req
.
headers
.
host
+
'/app/#/student/'
+
params
.
id_stu
+
"/setup/renewed/1"
,
// Returning URL (success)
DS_MERCHANT_URLKO
:
'https://'
+
req
.
headers
.
host
+
'/app/#/student/'
+
params
.
id_stu
+
"/setup/renewed/0"
,
// Returning URL (error)
DS_MERCHANT_PRODUCTDESCRIPTION
:
product_desc
,
DS_MERCHANT_MERCHANTDATA
:
JSON
.
stringify
({
DS_MERCHANT_MERCHANTDATA
:
encodeMerchantParams
({
type
:
params
.
type
,
creator
:
req
.
token
.
email
,
id_stu
:
params
.
id_stu
...
...
@@ -118,19 +118,34 @@ module.exports = {
notify
:
function
(
res
,
req
)
{
var
params
=
res
.
allParams
();
if
(
!
params
.
DS_SIGNATURE
||
!
params
.
DS_MERCHANTPARAMETERS
)
console
.
log
(
"params: "
+
JSON
.
stringify
(
params
));
if
(
!
params
.
Ds_Signature
||
!
params
.
Ds_MerchantParameters
)
return
res
.
badRequest
();
var
postSignature
=
params
.
D
S_SIGNATURE
;
var
postParams
=
params
.
DS_MERCHANTPARAMETERS
;
var
postSignature
=
params
.
D
s_Signature
;
var
postParams
=
params
.
Ds_MerchantParameters
;
var
params
=
decodeMerchantParams
(
postParams
);
var
ownParams
=
JSON
.
parse
(
params
.
DS_MERCHANT_MERCHANTDATA
);
var
key
=
cipherMerchantKey
(
params
.
DS_MERCHANT_ORDER
,
sails
.
config
.
pictogram
.
tpv
.
key
);
var
decodedParams
=
decodeMerchantParams
(
postParams
);
console
.
log
(
"Posted merchant params:"
+
JSON
.
stringify
(
decodedParams
));
var
ownParams
=
decodeMerchantParams
(
decodedParams
.
Ds_MerchantData
);
console
.
log
(
"Posted own merchant params:"
+
JSON
.
stringify
(
ownParams
));
var
key
=
cipherMerchantKey
(
decodedParams
.
Ds_Order
,
sails
.
config
.
pictogram
.
tpv
.
key
);
var
signatureBase64
=
signMerchantParams
(
postParams
,
key
);
console
.
log
(
"postSignature: "
+
postSignature
+
"\nsignatureBase64: "
+
signatureBase64
);
if
(
postSignature
!=
signatureBase64
)
{
// 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
(
"tpv/notify: Signature verification on TPV operation failed"
);
return
res
.
badRequest
(
"Invalid signature"
);
}
}
if
(
postSignature
!=
signatureBase64
)
return
res
.
badRequest
(
"Invalid signature"
);
// Everything is correct: generate serial number and activate it
...
...
@@ -157,7 +172,7 @@ module.exports = {
if
(
!
license
)
throw
new
Error
(
"Unable to create license"
);
License
.
activate
(
license
.
number
,
ownParams
.
id_stu
,
function
(
err
,
license
)
{
License
.
activate
(
license
.
number
,
parseInt
(
ownParams
.
id_stu
)
,
function
(
err
,
license
)
{
if
(
err
)
return
res
.
badRequest
(
err
);
return
res
.
ok
(
license
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment