working on TPV integration

parent 30176d00
......@@ -126,3 +126,5 @@ ALTER TABLE stu_sup
ADD CONSTRAINT `stu_sup_ibfk_2` FOREIGN KEY (`id_sup`) REFERENCES `supervisor` (`id`);
DROP TABLE office;
source triggers-enrolments-integrity-constraints.sql;
......@@ -30,7 +30,9 @@
"ngMask": "angular-mask#~3.1.1",
"angular-recaptcha": "^4.0.1",
"ui-bootstrap": "~2.5.0",
"ngInfiniteScroll": "^1.3.4"
"ngInfiniteScroll": "^1.3.4",
"fast-sha256": "^1.0.0",
"tweetnacl-util": "^0.15.0"
},
"resolutions": {
"angular": ">=1 <1.3.0",
......
......@@ -27,7 +27,10 @@ var dashboardApp = angular.module('dashboardApp', [
dashboardApp.constant('CONSTANTS', {
appName: 'Pictogram Dashboard',
appVersion: 0.1,
password_minlength: 8
password_minlength: 8,
tpvKey: 'sq7HjrUOBfKmC576ILgskD5srU870gJ7',
tpvPriceOneYearEuros: 70,
tpvPriceForeverEuros: 120,
});
......
......@@ -19,11 +19,9 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl(
// For tab navigation (here too, if the user refresh the page...)
$scope.nav.tab = 'setup';
// Set upload button to filestyle
/*$(":file").filestyle({
buttonText: "&nbsp;" + $translate.instant('change_picture'),
input: false
});*/
//
// Student setup
//
$scope.supsForm = {};
$scope.section = {val: 'account'};
......@@ -128,9 +126,9 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl(
$scope.formUser.country = data.country;
$scope.formUser.gender = data.gender;
$scope.formUser.lang = data.lang;
$scope.formUser.name = data.name;
$scope.studentData.name = data.name;
$scope.studentData.surname = data.surname;
$scope.formUser.name = data.name;
$scope.studentData.name = data.name;
$scope.studentData.surname = data.surname;
$scope.formUser.notes = data.notes;
$scope.formUser.surname = data.surname;
$scope.formUser.username = data.username;
......@@ -256,4 +254,63 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl(
ngToast.danger($translate.instant('attributes_not_updated'));
});
}, 300);
// ---------------------------------------------------------------------------
// TPV modal window
//
var modalInstance = $modal.open({
animation: true,
templateUrl: 'modules/student/views/tpvmodal.html',
controller: 'TPVModalCtrl',
size: 'lg',
resolve: {
student: function () {
return $scope.studentData;
},
supervisor: function () {
return $rootScope.user;
}
}
});
// Returned data from the modal window
modalInstance.result.then(function (pictoId) {
if(!pictoId)
return;
// Send the picto to the server
$http.post(config.backend + '/stu/' + $scope.studentData.id + '/picto/' + pictoId, {
attributes: {
id_cat: ($scope.showFreeCategory || mainCatGrid) ? null : $scope.getCategoryId($scope.selectedCategory),
coord_x: $scope.showFreeCategory ? null : col,
coord_y: $scope.showFreeCategory ? null : row,
status: 'enabled',
free_category_coord_x: $scope.showFreeCategory ? col : null,
free_category_coord_y: $scope.showFreeCategory ? row : null
},
id_scene: $scope.viewingScene.id
})
.success(function (studentPicto) {
placePicto(studentPicto);
io.socket.post('/stu/vocabulary', {
action: 'add',
attributes: {
id_stu: $scope.studentData.id,
id_scene: $scope.viewingScene.id,
stu_picto: studentPicto
}
}, function () {});
})
.error(function (err) {
if (err.code && err.code == 1) // codes are in sails/config/pictogram.js
ngToast.danger({ content: $translate.instant('error_duplicated_picto') });
else
ngToast.danger({ content: $translate.instant('error_adding_picto') });
});
});
});
'use strict';
// Please note that $modalInstance represents a modal window (instance) dependency.
// It is not the same as the $modal service used above.
dashboardControllers.controller('TPVModalCtrl', function ($scope, $modalInstance, $http, CONSTANTS, config, supervisor, student) {
$scope.foreverPrice = CONSTANTS.tpvForeverPriceEuros;
$scope.oneYearPrice = CONSTANTS.tpvOneYearPriceEuros;
var tpvdata =
{
Ds_Merchant_PayMethods: 'O', // Payment managed by RedSys
Ds_Merchant_MerchantCode: '152038485', // Number of commerce (Yotta)
Ds_Merchant_Terminal: '001', // Terminal number
Ds_Merchant_Currency: '000 ("978")', // Terminal currency
Ds_Merchant_Amount: CONSTANTS.tpvAnualPrice, // Amount
Ds_Merchant_MerchantUrl: config.backend + "/stu/buypro",
Ds_Merchant_UrlOk: config.backend + '/app/#/student' + student.id + "/setup", // Returning URL
};
// HMAC SHA256 encryption in Base64
var merchantParameters = nacl.util.encodeBase64(sha256.hmac(CONSTANTS.tpvKey, JSON.stringify(tpvdata)));
// Save expression
$scope.sendToRedSys = function () {
$http
.post('https://sis-t.redsys.es:25443/sis/realizarPago',
{
'Ds_SignatureVersion': "HMAC_SHA256_V1",
'Ds_MerchantParameters': merchantParameters,
'Ds_Signature': signature,
})
.success(function(data, status, headers, config) {
console.log("Expression changed: " + JSON.stringify(data));
// Close the modal instance
$modalInstance.close(data);
})
.error(function(data, status, headers, config) {
console.log("Error from API: " + data.error);
});
};
$scope.close = function () {
$modalInstance.dismiss('cancel');
};
});
<div id="tpvmodal">
<div class="modal-header">
<button type="button" class="close" ng-click="close()">
<span aria-hidden="true">&times;</span><span class="sr-only" translate>close</span>
</button>
<h4 class="modal-title" translate>tpv_title</h4>
</div>
<div class="modal-body">
<form name="tpvForm">
<div class="row">
<div class="md-col-6">
<h4 translate>one_year_license</h4>
<h1 class="tpv-price">{{ oneYearPrice }} €</h1>
</div>
<div class="md-col-6">
<h4 translate>forever_license</h4>
<h1 class="tpv-price">{{ foreverPrice }} €</h1>
</div>
</div>
<div class="row">
<div class="md-col-6">
<span class="input-group-btn">
<button class="btn btn-success" ng-click="sendToRedSys('oneYear')" translate><span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span> buy</button>
</span>
</div>
<div class="md-col-6">
<span class="input-group-btn">
<button class="btn btn-success" ng-click="sendToRedSys('forever')" translate><span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span> buy</button>
</span>
</div>
</div>
</form>
</div>
</div>
<!-- End modal-body -->
</div>
......@@ -1205,3 +1205,9 @@ input.editable.scene-name {
.navbar-default .navbar-nav > .active > a{
border-radius: .4em;
}
/* Estilos TPV */
.tpv-price {
font-size: xx-large;
}
......@@ -31,6 +31,8 @@ module.exports = function (grunt) {
'assets/app/bower_components/ngImgCrop/compile/minified/ng-img-crop.js',
'assets/app/bower_components/bootstrap-filestyle/src/bootstrap-filestyle.min.js',
'assets/app/bower_components/ngMask/dist/ngMask.min.js',
'assets/app/bower_components/fast-sha256/sha256.min.js',
'assets/app/bower_components/tweetnacl-util/nacl-util.min.js',
'assets/scripts/lib/sails.io.js'
];
......
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