= ({ currentUser, cart, price, wallet }) => {
return (
-
+
);
}
-Application.Components.component('walletInfo', react2angular(WalletInfoWrapper, ['currentUser', 'price', 'cartItems', 'wallet']));
+Application.Components.component('walletInfo', react2angular(WalletInfoWrapper, ['currentUser', 'price', 'cart', 'wallet']));
diff --git a/app/frontend/src/javascript/controllers/admin/events.js b/app/frontend/src/javascript/controllers/admin/events.js
index b2036f7a4..ecd75667d 100644
--- a/app/frontend/src/javascript/controllers/admin/events.js
+++ b/app/frontend/src/javascript/controllers/admin/events.js
@@ -548,7 +548,7 @@ Application.Controllers.controller('ShowEventReservationsController', ['$scope',
* @returns {boolean}
*/
$scope.isCancelled = function (reservation) {
- return !!(reservation.slots[0].canceled_at);
+ return !!(reservation.slots_attributes[0].canceled_at);
};
}]);
diff --git a/app/frontend/src/javascript/controllers/admin/invoices.js b/app/frontend/src/javascript/controllers/admin/invoices.js
index 0d57b9a16..f2c099a4d 100644
--- a/app/frontend/src/javascript/controllers/admin/invoices.js
+++ b/app/frontend/src/javascript/controllers/admin/invoices.js
@@ -206,6 +206,9 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
// Placeholding date for the reservation end
$scope.inOneWeekAndOneHour = moment().add(1, 'week').add(1, 'hour').startOf('hour');
+ // Is shown the modal dialog to select a payment gateway
+ $scope.openSelectGatewayModal = false;
+
/**
* Change the invoices ordering criterion to the one provided
* @param orderBy {string} ordering criterion
@@ -646,39 +649,87 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
};
/**
- * Open a modal dialog which ask for the stripe keys
+ * Open a modal dialog which ask the user to select the payment gateway to use
* @param onlinePaymentModule {{name: String, value: String}} setting that defines the next status of the online payment module
- * @return {boolean} false if the keys were not provided
*/
- $scope.requireStripeKeys = function (onlinePaymentModule) {
+ $scope.selectPaymentGateway = function (onlinePaymentModule) {
// if the online payment is about to be disabled, accept the change without any further question
if (onlinePaymentModule.value === false) return true;
- // otherwise, open a modal to ask for the stripe keys
- const modalInstance = $uibModal.open({
- templateUrl: '/admin/invoices/settings/stripeKeys.html',
- controller: 'StripeKeysModalController',
- resolve: {
- stripeKeys: ['Setting', function (Setting) { return Setting.query({ names: "['stripe_public_key', 'stripe_secret_key']" }).$promise; }]
- }
- });
+ // otherwise, open a modal to ask for the selection of a payment gateway
+ setTimeout(() => {
+ $scope.openSelectGatewayModal = true;
+ $scope.$apply();
+ }, 50);
+ return new Promise(function (resolve, reject) {
+ gatewayHandlers.resolve = resolve;
+ gatewayHandlers.reject = reject;
+ }).catch(() => { /* WORKAROUND: it seems we can't catch the rejection from the boolean-setting directive */ });
+ };
- modalInstance.result.then(function (success) {
- if (success) {
- Setting.get({ name: 'stripe_public_key' }, function (res) {
- $scope.allSettings.stripe_public_key = res.setting.value;
- });
- Setting.isPresent({ name: 'stripe_secret_key' }, function (res) {
- $scope.stripeSecretKey = (res.isPresent ? STRIPE_SK_HIDDEN : '');
- });
- Payment.onlinePaymentStatus(function (res) {
- $scope.onlinePaymentStatus = res.status;
- });
+ /**
+ * This will open/close the gateway selection modal
+ */
+ $scope.toggleSelectGatewayModal = function () {
+ setTimeout(() => {
+ $scope.openSelectGatewayModal = !$scope.openSelectGatewayModal;
+ $scope.$apply();
+ if (!$scope.openSelectGatewayModal && gatewayHandlers.reject) {
+ gatewayHandlers.reject();
+ resetPromiseHandlers();
}
- });
+ }, 50);
+ };
- // return the promise
- return modalInstance.result;
+ /**
+ * Callback triggered after the gateway was successfully configured in the dedicated modal
+ */
+ $scope.onGatewayModalSuccess = function (updatedSettings) {
+ if (gatewayHandlers.resolve) {
+ gatewayHandlers.resolve(true);
+ resetPromiseHandlers();
+ }
+
+ $scope.toggleSelectGatewayModal();
+ $scope.allSettings.payment_gateway = updatedSettings.get('payment_gateway').value;
+ if ($scope.allSettings.payment_gateway === 'stripe') {
+ $scope.allSettings.stripe_public_key = updatedSettings.get('stripe_public_key').value;
+ Setting.isPresent({ name: 'stripe_secret_key' }, function (res) {
+ $scope.stripeSecretKey = (res.isPresent ? STRIPE_SK_HIDDEN : '');
+ });
+ Payment.onlinePaymentStatus(function (res) {
+ $scope.onlinePaymentStatus = res.status;
+ });
+ }
+ };
+
+ /**
+ * Callback used in PaymentScheduleList, in case of error
+ */
+ $scope.onError = function (message) {
+ growl.error(message);
+ };
+
+ /**
+ * Callback triggered when the user has successfully updated his card
+ */
+ $scope.onCardUpdateSuccess = function (message) {
+ growl.success(message);
+ };
+
+ /**
+ * Callback triggered after the gateway failed to be configured
+ */
+ $scope.onGatewayModalError = function (errors) {
+ growl.error(_t('app.admin.invoices.payment.gateway_configuration_error'));
+ console.error(errors);
+ };
+
+ /**
+ * Callback triggered when the PayZen currency was successfully updated
+ */
+ $scope.alertPayZenCurrencyUpdated = function (currency) {
+ growl.success(_t('app.admin.invoices.payment.payzen.currency_updated', { CURRENCY: currency }));
};
/**
@@ -879,12 +930,30 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
);
}
});
+
+ // Clean before the controller is destroyed
+ $scope.$on('$destroy', function () {
+ if (gatewayHandlers.reject) {
+ gatewayHandlers.reject();
+ resetPromiseHandlers();
+ }
+ });
};
/**
* Will temporize the search query to prevent overloading the API
*/
- var searchTimeout = null;
+ let searchTimeout = null;
+
+ /**
+ * We must delay the save of the 'payment gateway' parameter, until the gateway is configured.
+ * To do so, we use a promise, with the resolve/reject callback stored here
+ * @see https://stackoverflow.com/q/26150232
+ */
+ const gatewayHandlers = {
+ resolve: null,
+ reject: null
+ };
/**
* Output the given integer with leading zeros. If the given value is longer than the given
@@ -892,7 +961,16 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
* @param value {number} the integer to pad
* @param length {number} the length of the resulting string.
*/
- var padWithZeros = function (value, length) { return (1e15 + value + '').slice(-length); };
+ const padWithZeros = function (value, length) { return (1e15 + value + '').slice(-length); };
+
+ /**
+ * Reset the promise handlers (reject/resolve) to their initial value.
+ * This will prevent an already resolved promise to be triggered again.
+ */
+ const resetPromiseHandlers = function () {
+ gatewayHandlers.resolve = null;
+ gatewayHandlers.reject = null;
+ };
/**
* Remove every unsupported html tag from the given html text (like , , ...).
@@ -900,7 +978,7 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
* @param html {string} single line html text
* @return {string} multi line simplified html text
*/
- var parseHtml = function (html) {
+ const parseHtml = function (html) {
return html.replace(/<\/?(\w+)((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/g, function (match, p1, offset, string) {
if (['b', 'u', 'i', 'br'].includes(p1)) {
return match;
@@ -913,7 +991,7 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
/**
* Reinitialize the context of invoices' search to display new results set
*/
- var resetSearchInvoice = function () {
+ const resetSearchInvoice = function () {
$scope.page = 1;
return $scope.noMoreResults = false;
};
@@ -923,7 +1001,7 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
* to $scope.invoices
* @param [concat] {boolean} if true, the result will be append to $scope.invoices instead of being affected
*/
- var invoiceSearch = function (concat) {
+ const invoiceSearch = function (concat) {
Invoice.list({
query: {
number: $scope.searchInvoice.reference,
@@ -1061,7 +1139,7 @@ Application.Controllers.controller('AvoirModalController', ['$scope', '$uibModal
* Kind of constructor: these actions will be realized first when the controller is loaded
*/
const initialize = function () {
- // if the invoice was payed with stripe, allow to refund through stripe
+ // if the invoice was paid with stripe, allow refunding through stripe
Invoice.get({ id: invoice.id }, function (data) {
$scope.invoice = data;
// default : all elements of the invoice are refund
@@ -1070,8 +1148,8 @@ Application.Controllers.controller('AvoirModalController', ['$scope', '$uibModal
});
});
- if (invoice.stripe) {
- return $scope.avoirModes.push({ name: _t('app.admin.invoices.online_payment'), value: 'stripe' });
+ if (invoice.online_payment) {
+ return $scope.avoirModes.push({ name: _t('app.admin.invoices.online_payment'), value: 'card' });
}
};
@@ -1295,7 +1373,7 @@ Application.Controllers.controller('AccountingExportModalController', ['$scope',
* Kind of constructor: these actions will be realized first when the controller is loaded
*/
const initialize = function () {
- // if the invoice was payed with stripe, allow to refund through stripe
+ // Get info about the very first invoice on the system
Invoice.first(function (data) {
$scope.firstInvoice = data.date;
$scope.exportTarget.startDate = data.date;
@@ -1329,126 +1407,3 @@ Application.Controllers.controller('AccountingExportModalController', ['$scope',
// !!! MUST BE CALLED AT THE END of the controller
return initialize();
}]);
-
-/**
- * Controller used in the modal window allowing an admin to close an accounting period
- */
-Application.Controllers.controller('StripeKeysModalController', ['$scope', '$uibModalInstance', '$http', '$httpParamSerializerJQLike', 'stripeKeys', 'Setting', 'growl', '_t',
- function ($scope, $uibModalInstance, $http, $httpParamSerializerJQLike, stripeKeys, Setting, growl, _t) {
- /* PUBLIC SCOPE */
-
- // public key
- $scope.publicKey = stripeKeys.stripe_public_key || '';
-
- // test status of the public key
- $scope.publicKeyStatus = undefined;
-
- // secret key
- $scope.secretKey = stripeKeys.stripe_secret_key || '';
-
- // test status of the secret key
- $scope.secretKeyStatus = undefined;
-
- /**
- * Trigger the test of the secret key and set the result in $scope.secretKeyStatus
- */
- $scope.testSecretKey = function () {
- if (!$scope.secretKey.match(/^sk_/)) {
- $scope.secretKeyStatus = false;
- return;
- }
- $http({
- method: 'GET',
- url: 'https://api.stripe.com/v1/charges',
- headers: {
- Authorization: `Bearer ${$scope.secretKey}`
- }
- }).then(function () {
- $scope.secretKeyStatus = true;
- }, function (err) {
- if (err.status === 401) $scope.secretKeyStatus = false;
- });
- };
-
- /**
- * Trigger the test of the secret key and set the result in $scope.secretKeyStatus
- */
- $scope.testPublicKey = function () {
- if (!$scope.publicKey.match(/^pk_/)) {
- $scope.publicKeyStatus = false;
- return;
- }
- $http({
- method: 'POST',
- url: 'https://api.stripe.com/v1/tokens',
- headers: {
- Authorization: `Bearer ${$scope.publicKey}`,
- 'Content-Type': 'application/x-www-form-urlencoded'
- },
- data: $httpParamSerializerJQLike({
- 'pii[id_number]': 'test'
- })
- }).then(function () {
- $scope.publicKeyStatus = true;
- }, function (err) {
- if (err.status === 401) $scope.publicKeyStatus = false;
- });
- };
-
- /**
- * Validate the keys
- */
- $scope.ok = function () {
- if ($scope.secretKeyStatus && $scope.publicKeyStatus) {
- Setting.bulkUpdate(
- {
- settings: [
- {
- name: 'stripe_public_key',
- value: $scope.publicKey
- },
- {
- name: 'stripe_secret_key',
- value: $scope.secretKey
- }
- ]
- },
- function () {
- growl.success(_t('app.admin.invoices.payment.stripe_keys_saved'));
- $uibModalInstance.close(true);
- },
- function (error) {
- growl.error('app.admin.invoices.payment.error_saving_stripe_keys');
- console.error(error);
- }
- );
- } else {
- growl.error(_t('app.admin.invoices.payment.error_check_keys'));
- }
- };
-
- /**
- * Just dismiss the modal window
- */
- $scope.cancel = function () {
- $uibModalInstance.dismiss('cancel');
- };
-
- /* PRIVATE SCOPE */
-
- /**
- * Kind of constructor: these actions will be realized first when the controller is loaded
- */
- const initialize = function () {
- if (stripeKeys.stripe_public_key) {
- $scope.testPublicKey();
- }
- if (stripeKeys.stripe_secret_key) {
- $scope.testSecretKey();
- }
- };
-
- // !!! MUST BE CALLED AT THE END of the controller!
- return initialize();
- }
-]);
diff --git a/app/frontend/src/javascript/controllers/admin/members.js b/app/frontend/src/javascript/controllers/admin/members.js
index ad5e718db..1ad5f24b4 100644
--- a/app/frontend/src/javascript/controllers/admin/members.js
+++ b/app/frontend/src/javascript/controllers/admin/members.js
@@ -158,7 +158,7 @@ Application.Controllers.controller('AdminMembersController', ['$scope', '$sce',
};
// admins list
- $scope.admins = adminsPromise.admins.filter(function (m) { return m.id !== Fablab.superadminId; });
+ $scope.admins = adminsPromise.admins.filter(function (m) { return m.id !== Fablab.adminSysId; });
// Admins ordering/sorting. Default: not sorted
$scope.orderAdmin = null;
diff --git a/app/frontend/src/javascript/controllers/dashboard.js b/app/frontend/src/javascript/controllers/dashboard.js
index aa908849c..f589b4cf8 100644
--- a/app/frontend/src/javascript/controllers/dashboard.js
+++ b/app/frontend/src/javascript/controllers/dashboard.js
@@ -62,6 +62,20 @@ Application.Controllers.controller('DashboardController', ['$scope', 'memberProm
return networks;
};
+ /**
+ * Callback used in PaymentScheduleDashboard, in case of error
+ */
+ $scope.onError = function (message) {
+ growl.error(message);
+ };
+
+ /**
+ * Callback triggered when the user has successfully updated his card
+ */
+ $scope.onCardUpdateSuccess = function (message) {
+ growl.success(message);
+ };
+
// !!! MUST BE CALLED AT THE END of the controller
return initialize();
}
diff --git a/app/frontend/src/javascript/controllers/events.js.erb b/app/frontend/src/javascript/controllers/events.js.erb
index 562bd4163..3f9d0a54d 100644
--- a/app/frontend/src/javascript/controllers/events.js.erb
+++ b/app/frontend/src/javascript/controllers/events.js.erb
@@ -13,8 +13,8 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
-Application.Controllers.controller('EventsController', ['$scope', '$state', 'Event', 'categoriesPromise', 'themesPromise', 'ageRangesPromise', 'settingsPromise',
- function ($scope, $state, Event, categoriesPromise, themesPromise, ageRangesPromise, settingsPromise) {
+Application.Controllers.controller('EventsController', ['$scope', '$state', 'Event', 'categoriesPromise', 'themesPromise', 'ageRangesPromise',
+ function ($scope, $state, Event, categoriesPromise, themesPromise, ageRangesPromise) {
/* PUBLIC SCOPE */
// The events displayed on the page
@@ -178,11 +178,16 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
// Message displayed to the end user about rules that applies to events reservations
$scope.eventExplicationsAlert = settingsPromise.event_explications_alert;
+ // online payments (by card)
+ $scope.onlinePayment = {
+ showModal: false,
+ cartItems: undefined
+ };
+
/**
* Callback to delete the provided event (admins only)
- * @param event {$resource} angular's Event $resource
*/
- $scope.deleteEvent = function (event) {
+ $scope.deleteEvent = function () {
// open a confirmation dialog
const modalInstance = $uibModal.open({
animation: true,
@@ -195,7 +200,7 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
});
// once the dialog was closed, do things depending on the result
modalInstance.result.then(function (res) {
- if (res.status == 'success') {
+ if (res.status === 'success') {
$state.go('app.public.events_list');
}
});
@@ -205,7 +210,7 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
* Callback to call when the number of tickets to book changes in the current booking
*/
$scope.changeNbPlaces = function () {
- // compute the total remaning places
+ // compute the total remaining places
let remain = $scope.event.nb_free_places - $scope.reserve.nbReservePlaces;
for (let ticket in $scope.reserve.tickets) {
remain -= $scope.reserve.tickets[ticket];
@@ -299,7 +304,7 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
$scope.payEvent = function () {
// first, we check that a user was selected
if (Object.keys($scope.ctrl.member).length > 0) {
- const reservation = mkReservation($scope.ctrl.member, $scope.reserve, $scope.event);
+ const reservation = mkReservation($scope.reserve, $scope.event);
return Wallet.getWalletByUser({ user_id: $scope.ctrl.member.id }, function (wallet) {
const amountToPay = helpers.getAmountToPay($scope.reserve.amountTotal, wallet.amount);
@@ -308,7 +313,7 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
if (settingsPromise.online_payment_module !== 'true') {
growl.error(_t('app.public.events_show.online_payment_disabled'));
} else {
- return payByStripe(reservation);
+ return payOnline(reservation);
}
} else {
if (AuthService.isAuthorized('admin')
@@ -328,33 +333,41 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
* Callback to validate the booking of a free event
*/
$scope.validReserveEvent = function () {
- const reservation = {
- user_id: $scope.ctrl.member.id,
- reservable_id: $scope.event.id,
- reservable_type: 'Event',
- slots_attributes: [],
- nb_reserve_places: $scope.reserve.nbReservePlaces,
- tickets_attributes: []
- };
+ const cartItems = {
+ customer_id: $scope.ctrl.member.id,
+ items: [
+ {
+ reservation: {
+ reservable_id: $scope.event.id,
+ reservable_type: 'Event',
+ slots_attributes: [],
+ nb_reserve_places: $scope.reserve.nbReservePlaces,
+ tickets_attributes: []
+ }
+ }
+ ]
+ }
// a single slot is used for events
- reservation.slots_attributes.push({
+ cartItems.items[0].reservation.slots_attributes.push({
start_at: $scope.event.start_date,
end_at: $scope.event.end_date,
availability_id: $scope.event.availability.id
});
// iterate over reservations per prices
for (let price_id in $scope.reserve.tickets) {
- const seats = $scope.reserve.tickets[price_id];
- reservation.tickets_attributes.push({
- event_price_category_id: price_id,
- booked: seats
- });
+ if (Object.prototype.hasOwnProperty.call($scope.reserve.tickets, price_id)) {
+ const seats = $scope.reserve.tickets[price_id];
+ cartItems.items[0].reservation.tickets_attributes.push({
+ event_price_category_id: price_id,
+ booked: seats
+ });
+ }
}
// set the attempting marker
$scope.attempting = true;
// save the reservation to the API
- return Reservation.save({ reservation }, function (reservation) {
- // reservation successfull
+ return Reservation.save(cartItems, function (reservation) {
+ // reservation successful
afterPayment(reservation);
return $scope.attempting = false;
}
@@ -372,7 +385,7 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
/**
* Callback to cancel a reservation
- * @param reservation {{id:number, reservable_id:number, nb_reserve_places:number}}
+ * @param reservation {{id:number, reservable_id:number, nb_reserve_places:number, slots_attributes:[{id: number, canceled_at: string}], total_booked_seats: number}}
*/
$scope.cancelReservation = function(reservation) {
dialogs.confirm({
@@ -386,13 +399,13 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
}
}, function() { // cancel confirmed
Slot.cancel({
- id: reservation.slots[0].id
+ id: reservation.slots_attributes[0].id
}, function() { // successfully canceled
let index;
growl.success(_t('app.public.events_show.reservation_was_successfully_cancelled'));
index = $scope.reservations.indexOf(reservation);
$scope.event.nb_free_places = $scope.event.nb_free_places + reservation.total_booked_seats;
- $scope.reservations[index].slots[0].canceled_at = new Date();
+ $scope.reservations[index].slots_attributes[0].canceled_at = new Date();
}, function(error) {
growl.warning(_t('app.public.events_show.cancellation_failed'));
});
@@ -401,11 +414,11 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
/**
* Test if the provided reservation has been cancelled
- * @param reservation {Reservation}
+ * @param reservation {{slots_attributes: [{canceled_at: string}]}}
* @returns {boolean}
*/
$scope.isCancelled = function(reservation) {
- return !!(reservation.slots[0].canceled_at);
+ return !!(reservation.slots_attributes[0].canceled_at);
}
/**
@@ -442,10 +455,9 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
return eventToPlace = e;
}
});
- $scope.reservation.slots[0].start_at = eventToPlace.start_date;
- $scope.reservation.slots[0].end_at = eventToPlace.end_date;
- $scope.reservation.slots[0].availability_id = eventToPlace.availability_id;
- $scope.reservation.slots_attributes = $scope.reservation.slots;
+ $scope.reservation.slots_attributes[0].start_at = eventToPlace.start_date;
+ $scope.reservation.slots_attributes[0].end_at = eventToPlace.end_date;
+ $scope.reservation.slots_attributes[0].availability_id = eventToPlace.availability_id;
$scope.attempting = true;
Reservation.update({ id: reservation.id }, { reservation: $scope.reservation }, function (reservation) {
$uibModalInstance.close(reservation);
@@ -482,10 +494,10 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
/**
* Checks if the provided reservation is able to be moved (date change)
- * @param reservation {{slots:[], total_booked_seats:number}}
+ * @param reservation {{slots_attributes:[], total_booked_seats:number}}
*/
$scope.reservationCanModify = function (reservation) {
- const slotStart = moment(reservation.slots[0].start_at);
+ const slotStart = moment(reservation.slots_attributes[0].start_at);
const now = moment();
let isAble = false;
@@ -497,12 +509,11 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
/**
* Checks if the provided reservation is able to be cancelled
- * @param reservation {{slots:[]}}
+ * @param reservation {{slots_attributes:[]}}
*/
$scope.reservationCanCancel = function(reservation) {
- var now, slotStart;
- slotStart = moment(reservation.slots[0].start_at);
- now = moment();
+ const slotStart = moment(reservation.slots_attributes[0].start_at);
+ const now = moment();
return $scope.enableBookingCancel && slotStart.diff(now, "hours") >= $scope.cancelBookingDelay;
};
@@ -513,8 +524,8 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
$scope.computeEventAmount = function () {
// first we check that a user was selected
if (Object.keys($scope.ctrl.member).length > 0) {
- const r = mkReservation($scope.ctrl.member, $scope.reserve, $scope.event);
- return Price.compute(mkRequestParams(r, $scope.coupon.applied), function (res) {
+ const r = mkReservation($scope.reserve, $scope.event);
+ return Price.compute(mkCartItems(r, $scope.coupon.applied), function (res) {
$scope.reserve.amountTotal = res.price;
return $scope.reserve.totalNoCoupon = res.price_without_coupon;
});
@@ -545,6 +556,36 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
}
};
+ /**
+ * This will open/close the online payment modal
+ */
+ $scope.toggleOnlinePaymentModal = (beforeApply) => {
+ setTimeout(() => {
+ $scope.onlinePayment.showModal = !$scope.onlinePayment.showModal;
+ if (typeof beforeApply === 'function') {
+ beforeApply();
+ }
+ $scope.$apply();
+ }, 50);
+ };
+
+ /**
+ * Invoked atfer a successful card payment
+ * @param invoice {*} the invoice
+ */
+ $scope.afterOnlinePaymentSuccess = (invoice) => {
+ $scope.toggleOnlinePaymentModal();
+ afterPayment(invoice);
+ };
+
+ /**
+ * Invoked when something wrong occurred during the payment dialog initialization
+ * @param message {string}
+ */
+ $scope.onOnlinePaymentError = (message) => {
+ growl.error(message);
+ };
+
/* PRIVATE SCOPE */
/**
@@ -561,7 +602,7 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
// initialize the "reserve" object with the event's data
resetEventReserve();
- // if non-admin, get the current user's reservations into $scope.reservations
+ // get the current user's reservations into $scope.reservations
if ($scope.currentUser) {
getReservations($scope.event.id, 'Event', $scope.currentUser.id);
}
@@ -589,15 +630,13 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
};
/**
- * Create an hash map implementing the Reservation specs
- * @param member {Object} User as retreived from the API: current user / selected user if current is admin
+ * Create a hash map implementing the Reservation specs
* @param reserve {Object} Reservation parameters (places...)
* @param event {Object} Current event
- * @return {{user_id:number, reservable_id:number, reservable_type:string, slots_attributes:Array