tpv working

parent 114d280f
...@@ -26,7 +26,7 @@ module.exports = { ...@@ -26,7 +26,7 @@ module.exports = {
}, },
/** /**
* Create a new Instruction, which is associated to the given method * Create a new License, which is associated to the given method
* @param {request} req * @param {request} req
* { * {
* duration (number of months) * duration (number of months)
......
...@@ -21,77 +21,87 @@ module.exports = { ...@@ -21,77 +21,87 @@ module.exports = {
return res.badRequest(); return res.badRequest();
// //
// Submit data // Generate new license and use ID for order
// //
new Promise((resolve, reject) => {
var amount = sails.config.pictogram.tpv.prices.oneYearEuro; License.genLicenseNumber((number) => {
if (params.type == 'forever') if (number)
amount = sails.config.pictogram.tpv.prices.foreverEuro; resolve(number);
else
var tpvdata = reject();
{ });
DS_MERCHANT_PAYMETHODS: 'C', // Payment managed by RedSys })
DS_MERCHANT_MERCHANTCODE: sails.config.pictogram.tpv.merchantCode, // Number of commerce (Yotta) .then((number) => {
DS_MERCHANT_TERMINAL: '001', // Terminal number return License.create({
DS_MERCHANT_CURRENCY: '978', // Terminal currency number: number,
DS_MERCHANT_TRANSACTIONTYPE: "0", // Type of the transaction (0: authorized) duration: params.type == 'forever' ? 1200 : 12,
DS_MERCHANT_AMOUNT: amount + "00", // Amount creator: req.token.email
DS_MERCHANT_ORDER: moment().format('YYMMDD') + params.id_stu, });
DS_MERCHANT_MERCHANTURL: sails.getBaseUrl() + "/tpv/notify", })
DS_MERCHANT_URLOK: sails.getBaseUrl() + '/app/#/student/' + params.id_stu + "/setup/renewed/1", // Returning URL (success) .then((license) => {
DS_MERCHANT_URLKO: sails.getBaseUrl() + '/app/#/student/' + params.id_stu + "/setup/renewed/0" // Returning URL (error)
}; if (!license)
throw new Error("Unable to create license");
// //
// Sign data // Prepare submit data
// //
// Base64 encoding of parameters var amount = sails.config.pictogram.tpv.prices.oneYearEuro;
var merchantWordArray = cryptojs.enc.Utf8.parse(JSON.stringify(tpvdata)); if (params.type == 'forever')
var merchantBase64 = merchantWordArray.toString(cryptojs.enc.Base64); amount = sails.config.pictogram.tpv.prices.foreverEuro;
// Decode key var tpvdata =
var keyWordArray = cryptojs.enc.Base64.parse(sails.config.pictogram.tpv.key); {
DS_MERCHANT_PAYMETHODS: 'C', // Payment managed by RedSys
// Generate transction key DS_MERCHANT_MERCHANTCODE: sails.config.pictogram.tpv.merchantCode, // Number of commerce (Yotta)
var iv = cryptojs.enc.Hex.parse("00000000"); DS_MERCHANT_TERMINAL: '001', // Terminal number
var cipher = cryptojs.TripleDES.encrypt(tpvdata.DS_MERCHANT_ORDER, keyWordArray, { DS_MERCHANT_CURRENCY: '978', // Terminal currency
iv:iv, DS_MERCHANT_TRANSACTIONTYPE: "0", // Type of the transaction (0: authorized)
mode: cryptojs.mode.CBC, DS_MERCHANT_AMOUNT: amount + "00", // Amount
padding: cryptojs.pad.NoPadding DS_MERCHANT_ORDER: moment().format('YYMMDD') + license.id.toString().slice(-6), // hast to be from 4 to 12 characters long
}); DS_MERCHANT_MERCHANTURL: sails.getBaseUrl() + "/tpv/notify", // not used
DS_MERCHANT_URLOK: sails.getBaseUrl() + '/app/#/student/' + params.id_stu + "/setup/renewed/" + license.number, // Returning URL (success)
// Sign DS_MERCHANT_URLKO: sails.getBaseUrl() + '/app/#/student/' + params.id_stu + "/setup/renewed/0" // Returning URL (error)
var signature = cryptojs.HmacSHA256(merchantBase64, cipher.ciphertext); };
var signatureBase64 = signature.toString(cryptojs.enc.Base64);
console.log("Data: " + JSON.stringify(tpvdata));
// Done, we can return response //
var response = { // Sign submit data
signatureVersion: "HMAC_SHA256_V1", //
merchantParameters: merchantBase64,
signature: signatureBase64 // Base64 encoding of parameters
}; var merchantWordArray = cryptojs.enc.Utf8.parse(JSON.stringify(tpvdata));
var merchantBase64 = merchantWordArray.toString(cryptojs.enc.Base64);
sails.log.debug(JSON.stringify(response));
res.ok(response); // Decode key
var keyWordArray = cryptojs.enc.Base64.parse(sails.config.pictogram.tpv.key);
// Generate transaction key
var iv = cryptojs.enc.Hex.parse("0000000000000000");
var cipher = cryptojs.TripleDES.encrypt(tpvdata.DS_MERCHANT_ORDER, keyWordArray, {
iv:iv,
mode: cryptojs.mode.CBC,
padding: cryptojs.pad.ZeroPadding
});
// Sign
var signature = cryptojs.HmacSHA256(merchantBase64, cipher.ciphertext);
var signatureBase64 = signature.toString(cryptojs.enc.Base64);
// Done, we can return response
var response = {
signatureVersion: "HMAC_SHA256_V1",
merchantParameters: merchantBase64,
signature: signatureBase64
};
sails.log.debug(JSON.stringify(response));
res.ok(response);
})
.catch((err) => {return res.serverError(err)});
}, },
notify: function(res, req) {
/** return res.ok();
* Notification of transaction from RedSys
*/
notify: function(req, res) {
var params = req.allParams();
var received_signature = params.Ds_Signature;
var calculated_signature = nacl_util.encodeBase64(sha256.hmac(sails.config.pictogram.tpv.key, params.Ds_MerchantParameters));
if (received_signature == calculated_signature) {
console.log("OK");
// TBD: CREAR NUEVA LICENCIA
}
else
console.log("ERROR");
console.log(JSON.stringify(params));
} }
}; };
...@@ -151,7 +151,7 @@ module.exports = { ...@@ -151,7 +151,7 @@ module.exports = {
return found; return found;
}, },
function () { function () {
callback(license); return callback(license);
} }
); );
}, },
......
...@@ -207,6 +207,7 @@ ...@@ -207,6 +207,7 @@
"license_expired_official": "PRO license expired. To maintain access to therapeutical functionalities you can", "license_expired_official": "PRO license expired. To maintain access to therapeutical functionalities you can",
"license_expired_trial": "Trial license expired. To keep the account you should", "license_expired_trial": "Trial license expired. To keep the account you should",
"license_expired_buy": "buy one license", "license_expired_buy": "buy one license",
"license_trial_buy": "Buy an official one",
"license_expired_renew": "renew it", "license_expired_renew": "renew it",
"license_expires_official": "PRO license expires on ", "license_expires_official": "PRO license expires on ",
"license_expires_trial": "Trial license expires on ", "license_expires_trial": "Trial license expires on ",
...@@ -349,6 +350,7 @@ ...@@ -349,6 +350,7 @@
"reloading_pictos": "Reloading pictograms", "reloading_pictos": "Reloading pictograms",
"reload_scene": "Reloading scene", "reload_scene": "Reloading scene",
"remember": "Remember me", "remember": "Remember me",
"renew": "renew license",
"reports": "Reports", "reports": "Reports",
"request_change_password": "Request change password", "request_change_password": "Request change password",
"resume": "Resume", "resume": "Resume",
...@@ -461,6 +463,7 @@ ...@@ -461,6 +463,7 @@
"tpl_date_frame": "de {{ begin | date:'dd-MM-yyyy' }} a {{ end | date:'dd-MM-yyyy' }}", "tpl_date_frame": "de {{ begin | date:'dd-MM-yyyy' }} a {{ end | date:'dd-MM-yyyy' }}",
"tpl_day": "{{ day | date:'yyyy-MM-dd' }}", "tpl_day": "{{ day | date:'yyyy-MM-dd' }}",
"tpl_hours_frame": "from {{ begin | date:'HH:mm:ss' }} to {{ end | date:'HH:mm:ss' }}", "tpl_hours_frame": "from {{ begin | date:'HH:mm:ss' }} to {{ end | date:'HH:mm:ss' }}",
"tpv_error": "The acquisition of a new license has not been successful",
"tpv_init_error": "Unable to initiate payment process", "tpv_init_error": "Unable to initiate payment process",
"tpv_success": "The new license is now active", "tpv_success": "The new license is now active",
"tpv_title": "Select license type", "tpv_title": "Select license type",
......
...@@ -218,6 +218,7 @@ ...@@ -218,6 +218,7 @@
"license_warning": "Sólo disponible para licencias profesionales (Pictogram Pro).", "license_warning": "Sólo disponible para licencias profesionales (Pictogram Pro).",
"license_missing_official": "La licencia PRO expiró. El acceso a las funcionalidades terapéuticas queda restringido, aunque puede seguir gestionando pictogramas y dispositivos.", "license_missing_official": "La licencia PRO expiró. El acceso a las funcionalidades terapéuticas queda restringido, aunque puede seguir gestionando pictogramas y dispositivos.",
"license_missing_trial": "La licencia de prueba expiró. Adquiera una licencia oficial para mantener esta cuenta (puede hacerlo en Configuración).", "license_missing_trial": "La licencia de prueba expiró. Adquiera una licencia oficial para mantener esta cuenta (puede hacerlo en Configuración).",
"license_trial_buy": "Adquirir licencia oficial",
"licenses_created": "Licencias creadas", "licenses_created": "Licencias creadas",
"light_up": "Iluminar", "light_up": "Iluminar",
"link": "Vincular", "link": "Vincular",
...@@ -347,6 +348,7 @@ ...@@ -347,6 +348,7 @@
"reload_scene": "Recargando escena", "reload_scene": "Recargando escena",
"reloading_pictos": "Recargando pictogramas", "reloading_pictos": "Recargando pictogramas",
"remember": "No cerrar sesión", "remember": "No cerrar sesión",
"renew": "renovar licencia",
"reports": "Informes", "reports": "Informes",
"request_change_password": "Solicitar cambio de contraseña", "request_change_password": "Solicitar cambio de contraseña",
"resume": "Continuar", "resume": "Continuar",
...@@ -459,6 +461,7 @@ ...@@ -459,6 +461,7 @@
"tpl_date_frame": "de {{ begin | date:'dd-MM-yyyy' }} a {{ end | date:'dd-MM-yyyy' }}", "tpl_date_frame": "de {{ begin | date:'dd-MM-yyyy' }} a {{ end | date:'dd-MM-yyyy' }}",
"tpl_day": "{{ day | date:'dd-MM-yyyy' }}", "tpl_day": "{{ day | date:'dd-MM-yyyy' }}",
"tpl_hours_frame": "de {{ begin | date:'HH:mm:ss' }} a {{ end | date:'HH:mm:ss' }}", "tpl_hours_frame": "de {{ begin | date:'HH:mm:ss' }} a {{ end | date:'HH:mm:ss' }}",
"tpv_error": "La adquisición de una nueva licencia no se ha completado con éxito",
"tpv_init_error": "No se pudo iniciar el proceso de compra", "tpv_init_error": "No se pudo iniciar el proceso de compra",
"tpv_success": "La nueva licencia ha sido activada", "tpv_success": "La nueva licencia ha sido activada",
"tpv_title": "Seleccione el tipo de licencia", "tpv_title": "Seleccione el tipo de licencia",
......
...@@ -167,6 +167,12 @@ dashboardApp.config(function ($stateProvider, $urlRouterProvider) { ...@@ -167,6 +167,12 @@ dashboardApp.config(function ($stateProvider, $urlRouterProvider) {
templateUrl: 'modules/student/views/setup.html', templateUrl: 'modules/student/views/setup.html',
controller: 'StudentSetupCtrl', controller: 'StudentSetupCtrl',
}) })
.state('student_renew', {
url: '/student/:idStudent/setup/renewed/:serial',
parent: 'student',
templateUrl: 'modules/student/views/setup.html',
controller: 'StudentSetupCtrl',
})
// Abstract page for admin // Abstract page for admin
.state('admin', { .state('admin', {
templateUrl: 'modules/admin/views/admin.html', templateUrl: 'modules/admin/views/admin.html',
......
...@@ -21,13 +21,7 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl( ...@@ -21,13 +21,7 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl(
// For tab navigation (here too, if the user refresh the page...) // For tab navigation (here too, if the user refresh the page...)
$scope.nav.tab = 'setup'; $scope.nav.tab = 'setup';
// If we get with this parameter, we're back from a TPV transaction! //
if ($stateParams.renewed && $stateParams.renewed == 1)
ngToast.success($translate.instant('tpv_success'));
if ($stateParams.renewed && $stateParams.renewed == 0)
ngToast.success($translate.instant('tpv_error'));
//
// Student setup // Student setup
// //
...@@ -265,8 +259,21 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl( ...@@ -265,8 +259,21 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl(
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// TPV modal window // TPV interaction
// // ---------------------------------------------------------------------------
// If we get with this parameter, we're back from a TPV transaction!
console.log(JSON.stringify($stateParams));
if ($stateParams.serial && $stateParams.serial == 0)
ngToast.danger($translate.instant('tpv_error'));
else {
$scope.formUser.license_number = $stateParams.serial;
$scope.updateStudent();
}
/**
* Opens the modal window to select and buy license
*/
$scope.openBuyModal = function() { $scope.openBuyModal = function() {
var modalInstance = $modal.open({ var modalInstance = $modal.open({
animation: true, animation: true,
......
...@@ -69,7 +69,8 @@ ...@@ -69,7 +69,8 @@
<div class="row"> <div class="row">
<div class="col-xs-2"><i class="fa fa-flask fa-lg" aria-hidden="true"></i></div> <div class="col-xs-2"><i class="fa fa-flask fa-lg" aria-hidden="true"></i></div>
<div class="col-xs-10"> <div class="col-xs-10">
{{ 'license_expires_trial' | translate }} <b>{{ studentData.expiration_date }}</b> {{ 'license_expires_trial' | translate }} <b>{{ studentData.expiration_date }}</b><br>
<a ng-click="openBuyModal()">{{ 'license_trial_buy' | translate }}</a>
</div> </div>
</div> </div>
</div> </div>
...@@ -79,7 +80,7 @@ ...@@ -79,7 +80,7 @@
<div class="row"> <div class="row">
<div class="col-xs-2"><i class="fa fa-certificate fa-lg text-danger" aria-hidden="true"></i></div> <div class="col-xs-2"><i class="fa fa-certificate fa-lg text-danger" aria-hidden="true"></i></div>
<div class="col-xs-10"> <div class="col-xs-10">
{{ 'license_expired_official' | translate }} <a href="http://pictogramweb.com/caracteristicas-de-pictogram/">{{ 'license_expired_renew' | translate }}</a>. {{ 'license_expired_official' | translate }} <a ng-click="openBuyModal()">{{ 'license_expired_renew' | translate }}</a>.
</div> </div>
</div> </div>
</div> </div>
...@@ -89,7 +90,8 @@ ...@@ -89,7 +90,8 @@
<div class="row"> <div class="row">
<div class="col-xs-2"><i class="fa fa-flask fa-lg text-danger" aria-hidden="true"></i></div> <div class="col-xs-2"><i class="fa fa-flask fa-lg text-danger" aria-hidden="true"></i></div>
<div class="col-xs-10"> <div class="col-xs-10">
{{ 'license_expired_trial' | translate }} <a href="http://pictogramweb.com/caracteristicas-de-pictogram/">{{ 'license_expired_buy' | translate }}</a>. {{ 'license_expired_trial' | translate }} <a ng-click="openBuyModal()">{{ 'license_expired_buy' | translate }}
</a>
</div> </div>
</div> </div>
</div> </div>
...@@ -101,14 +103,12 @@ ...@@ -101,14 +103,12 @@
<div class="col-xs-10"> <div class="col-xs-10">
<h4 class="alert-heading"> {{ 'license_missing' | translate }} </h4> <h4 class="alert-heading"> {{ 'license_missing' | translate }} </h4>
<p> <p>
<a href="http://pictogramweb.com/caracteristicas-de-pictogram/">{{ 'more_info' | translate }}</a> <a ng-click="openBuyModal()">{{ 'license_expired_buy' | translate }}</a>
</p> </p>
</div> </div>
</div> </div>
</div> </div>
<button type="submit" class="btn btn-primary" ng-click="openBuyModal()" translate>renew</button>
</div> </div>
</fieldset> </fieldset>
......
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