mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-21 15:54:22 +01:00
pay totalement/partialement reservation by wallet
This commit is contained in:
parent
fc7eaaab94
commit
31d5c6d3b3
@ -132,8 +132,8 @@ Application.Controllers.controller "EventsController", ["$scope", "$state", 'Eve
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Application.Controllers.controller "ShowEventController", ["$scope", "$state", "$stateParams", "Event", '$uibModal', 'Member', 'Reservation', 'Price', 'CustomAsset', 'eventPromise', 'reducedAmountAlert', 'growl', '_t'
|
Application.Controllers.controller "ShowEventController", ["$scope", "$state", "$stateParams", "Event", '$uibModal', 'Member', 'Reservation', 'Price', 'CustomAsset', 'eventPromise', 'reducedAmountAlert', 'growl', '_t', 'Wallet', 'helpers',
|
||||||
($scope, $state, $stateParams, Event, $uibModal, Member, Reservation, Price, CustomAsset, eventPromise, reducedAmountAlert, growl, _t) ->
|
($scope, $state, $stateParams, Event, $uibModal, Member, Reservation, Price, CustomAsset, eventPromise, reducedAmountAlert, growl, _t, Wallet, helpers) ->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -242,10 +242,12 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
|
|||||||
if Object.keys($scope.ctrl.member).length > 0
|
if Object.keys($scope.ctrl.member).length > 0
|
||||||
reservation = mkReservation($scope.ctrl.member, $scope.reserve, $scope.event)
|
reservation = mkReservation($scope.ctrl.member, $scope.reserve, $scope.event)
|
||||||
|
|
||||||
if $scope.currentUser.role isnt 'admin' and $scope.reserve.amountTotal > 0
|
Wallet.getWalletByUser {user_id: $scope.ctrl.member.id}, (wallet) ->
|
||||||
|
amountToPay = helpers.getAmountToPay($scope.reserve.amountTotal, wallet.amount)
|
||||||
|
if $scope.currentUser.role isnt 'admin' and amountToPay > 0
|
||||||
payByStripe(reservation)
|
payByStripe(reservation)
|
||||||
else
|
else
|
||||||
if $scope.currentUser.role is 'admin' or $scope.reserve.amountTotal is 0
|
if $scope.currentUser.role is 'admin' or amountToPay is 0
|
||||||
payOnSite(reservation)
|
payOnSite(reservation)
|
||||||
else
|
else
|
||||||
# otherwise we alert, this error musn't occur when the current user is not admin
|
# otherwise we alert, this error musn't occur when the current user is not admin
|
||||||
@ -461,15 +463,20 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
|
|||||||
reservation
|
reservation
|
||||||
price: ->
|
price: ->
|
||||||
Price.compute({reservation: reservation}).$promise
|
Price.compute({reservation: reservation}).$promise
|
||||||
|
wallet: ->
|
||||||
|
Wallet.getWalletByUser({user_id: reservation.user_id}).$promise
|
||||||
cgv: ->
|
cgv: ->
|
||||||
CustomAsset.get({name: 'cgv-file'}).$promise
|
CustomAsset.get({name: 'cgv-file'}).$promise
|
||||||
objectToPay: ->
|
objectToPay: ->
|
||||||
eventToReserve: $scope.event
|
eventToReserve: $scope.event
|
||||||
reserve: $scope.reserve
|
reserve: $scope.reserve
|
||||||
member: $scope.ctrl.member
|
member: $scope.ctrl.member
|
||||||
controller: ['$scope', '$uibModalInstance', '$state', 'reservation', 'price', 'cgv', 'Auth', 'Reservation', 'growl', ($scope, $uibModalInstance, $state, reservation, price, cgv, Auth, Reservation, growl) ->
|
controller: ['$scope', '$uibModalInstance', '$state', 'reservation', 'price', 'cgv', 'Auth', 'Reservation', 'growl', 'wallet', 'helpers', '$locale', ($scope, $uibModalInstance, $state, reservation, price, cgv, Auth, Reservation, growl, wallet, helpers, $locale) ->
|
||||||
|
# user wallet amount
|
||||||
|
$scope.walletAmount = wallet.amount
|
||||||
|
|
||||||
# Price
|
# Price
|
||||||
$scope.amount = price.price
|
$scope.amount = helpers.getAmountToPay(price.price, wallet.amount)
|
||||||
|
|
||||||
# CGV
|
# CGV
|
||||||
$scope.cgv = cgv.custom_asset
|
$scope.cgv = cgv.custom_asset
|
||||||
@ -477,6 +484,8 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
|
|||||||
# Reservation
|
# Reservation
|
||||||
$scope.reservation = reservation
|
$scope.reservation = reservation
|
||||||
|
|
||||||
|
$scope.currencySymbol = $locale.NUMBER_FORMATS.CURRENCY_SYM
|
||||||
|
|
||||||
# Callback for the stripe payment authorization
|
# Callback for the stripe payment authorization
|
||||||
$scope.payment = (status, response) ->
|
$scope.payment = (status, response) ->
|
||||||
if response.error
|
if response.error
|
||||||
@ -511,13 +520,23 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
|
|||||||
reservation
|
reservation
|
||||||
price: ->
|
price: ->
|
||||||
Price.compute({reservation: reservation}).$promise
|
Price.compute({reservation: reservation}).$promise
|
||||||
controller: ['$scope', '$uibModalInstance', '$state', 'reservation', 'price', 'Auth', 'Reservation', ($scope, $uibModalInstance, $state, reservation, price, Auth, Reservation) ->
|
wallet: ->
|
||||||
|
Wallet.getWalletByUser({user_id: reservation.user_id}).$promise
|
||||||
|
controller: ['$scope', '$uibModalInstance', '$state', 'reservation', 'price', 'Auth', 'Reservation', 'wallet', '$locale', 'helpers', ($scope, $uibModalInstance, $state, reservation, price, Auth, Reservation, wallet, $locale, helpers) ->
|
||||||
|
# user wallet amount
|
||||||
|
$scope.walletAmount = wallet.amount
|
||||||
|
|
||||||
# Price
|
# Price
|
||||||
$scope.amount = price.price
|
$scope.price = price.price
|
||||||
|
|
||||||
|
# price to pay
|
||||||
|
$scope.amount = helpers.getAmountToPay(price.price, wallet.amount)
|
||||||
|
|
||||||
# Reservation
|
# Reservation
|
||||||
$scope.reservation = reservation
|
$scope.reservation = reservation
|
||||||
|
|
||||||
|
$scope.currencySymbol = $locale.NUMBER_FORMATS.CURRENCY_SYM
|
||||||
|
|
||||||
# Button label
|
# Button label
|
||||||
if $scope.amount > 0
|
if $scope.amount > 0
|
||||||
$scope.validButtonName = _t('confirm_(payment_on_site)')
|
$scope.validButtonName = _t('confirm_(payment_on_site)')
|
||||||
|
@ -268,8 +268,8 @@ Application.Controllers.controller "ShowMachineController", ['$scope', '$state',
|
|||||||
# This controller workflow is pretty similar to the trainings reservation controller.
|
# This controller workflow is pretty similar to the trainings reservation controller.
|
||||||
##
|
##
|
||||||
|
|
||||||
Application.Controllers.controller "ReserveMachineController", ["$scope", "$state", '$stateParams', "$uibModal", '_t', "moment", 'Machine', 'Auth', 'dialogs', '$timeout', 'Price', 'Member', 'Availability', 'Slot', 'Setting', 'CustomAsset', 'plansPromise', 'groupsPromise', 'growl', 'settingsPromise', 'uiCalendarConfig', 'CalendarConfig'
|
Application.Controllers.controller "ReserveMachineController", ["$scope", "$state", '$stateParams', "$uibModal", '_t', "moment", 'Machine', 'Auth', 'dialogs', '$timeout', 'Price', 'Member', 'Availability', 'Slot', 'Setting', 'CustomAsset', 'plansPromise', 'groupsPromise', 'growl', 'settingsPromise', 'Wallet', 'helpers', 'uiCalendarConfig', 'CalendarConfig',
|
||||||
($scope, $state, $stateParams, $uibModal, _t, moment, Machine, Auth, dialogs, $timeout, Price, Member, Availability, Slot, Setting, CustomAsset, plansPromise, groupsPromise, growl, settingsPromise, uiCalendarConfig, CalendarConfig) ->
|
($scope, $state, $stateParams, $uibModal, _t, moment, Machine, Auth, dialogs, $timeout, Price, Member, Availability, Slot, Setting, CustomAsset, plansPromise, groupsPromise, growl, settingsPromise, Wallet, helpers, uiCalendarConfig, CalendarConfig) ->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -529,10 +529,12 @@ Application.Controllers.controller "ReserveMachineController", ["$scope", "$stat
|
|||||||
if Object.keys($scope.ctrl.member).length > 0
|
if Object.keys($scope.ctrl.member).length > 0
|
||||||
reservation = mkReservation($scope.ctrl.member, $scope.eventsReserved, $scope.selectedPlan)
|
reservation = mkReservation($scope.ctrl.member, $scope.eventsReserved, $scope.selectedPlan)
|
||||||
|
|
||||||
if $scope.currentUser.role isnt 'admin' and $scope.amountTotal > 0
|
Wallet.getWalletByUser {user_id: $scope.ctrl.member.id}, (wallet) ->
|
||||||
|
amountToPay = helpers.getAmountToPay($scope.amountTotal, wallet.amount)
|
||||||
|
if $scope.currentUser.role isnt 'admin' and amountToPay > 0
|
||||||
payByStripe(reservation)
|
payByStripe(reservation)
|
||||||
else
|
else
|
||||||
if $scope.currentUser.role is 'admin' or $scope.amountTotal is 0
|
if $scope.currentUser.role is 'admin' or amountToPay is 0
|
||||||
payOnSite(reservation)
|
payOnSite(reservation)
|
||||||
else
|
else
|
||||||
# otherwise we alert, this error musn't occur when the current user is not admin
|
# otherwise we alert, this error musn't occur when the current user is not admin
|
||||||
@ -752,11 +754,16 @@ Application.Controllers.controller "ReserveMachineController", ["$scope", "$stat
|
|||||||
reservation
|
reservation
|
||||||
price: ->
|
price: ->
|
||||||
Price.compute({reservation: reservation}).$promise
|
Price.compute({reservation: reservation}).$promise
|
||||||
|
wallet: ->
|
||||||
|
Wallet.getWalletByUser({user_id: reservation.user_id}).$promise
|
||||||
cgv: ->
|
cgv: ->
|
||||||
CustomAsset.get({name: 'cgv-file'}).$promise
|
CustomAsset.get({name: 'cgv-file'}).$promise
|
||||||
controller: ['$scope', '$uibModalInstance', '$state', 'reservation', 'price', 'cgv', 'Auth', 'Reservation', ($scope, $uibModalInstance, $state, reservation, price, cgv, Auth, Reservation) ->
|
controller: ['$scope', '$uibModalInstance', '$state', 'reservation', 'price', 'cgv', 'Auth', 'Reservation', 'wallet', 'helpers', '$locale', ($scope, $uibModalInstance, $state, reservation, price, cgv, Auth, Reservation, wallet, helpers, $locale) ->
|
||||||
|
# user wallet amount
|
||||||
|
$scope.walletAmount = wallet.amount
|
||||||
|
|
||||||
# Price
|
# Price
|
||||||
$scope.amount = price.price
|
$scope.amount = helpers.getAmountToPay(price.price, wallet.amount)
|
||||||
|
|
||||||
# CGV
|
# CGV
|
||||||
$scope.cgv = cgv.custom_asset
|
$scope.cgv = cgv.custom_asset
|
||||||
@ -764,6 +771,8 @@ Application.Controllers.controller "ReserveMachineController", ["$scope", "$stat
|
|||||||
# Reservation
|
# Reservation
|
||||||
$scope.reservation = reservation
|
$scope.reservation = reservation
|
||||||
|
|
||||||
|
$scope.currencySymbol = $locale.NUMBER_FORMATS.CURRENCY_SYM
|
||||||
|
|
||||||
##
|
##
|
||||||
# Callback to process the payment with Stripe, triggered on button click
|
# Callback to process the payment with Stripe, triggered on button click
|
||||||
##
|
##
|
||||||
@ -800,17 +809,29 @@ Application.Controllers.controller "ReserveMachineController", ["$scope", "$stat
|
|||||||
reservation
|
reservation
|
||||||
price: ->
|
price: ->
|
||||||
Price.compute({reservation: reservation}).$promise
|
Price.compute({reservation: reservation}).$promise
|
||||||
controller: ['$scope', '$uibModalInstance', '$state', 'reservation', 'price', 'Auth', 'Reservation', ($scope, $uibModalInstance, $state, reservation, price, Auth, Reservation) ->
|
wallet: ->
|
||||||
|
Wallet.getWalletByUser({user_id: reservation.user_id}).$promise
|
||||||
|
controller: ['$scope', '$uibModalInstance', '$state', 'reservation', 'price', 'Auth', 'Reservation', 'wallet', 'helpers', '$filter', '$locale', ($scope, $uibModalInstance, $state, reservation, price, Auth, Reservation, wallet, helpers, $filter, $locale) ->
|
||||||
|
# user wallet amount
|
||||||
|
$scope.walletAmount = wallet.amount
|
||||||
|
|
||||||
# Price
|
# Price
|
||||||
$scope.amount = price.price
|
$scope.price = price.price
|
||||||
|
|
||||||
|
# price to pay
|
||||||
|
$scope.amount = helpers.getAmountToPay(price.price, wallet.amount)
|
||||||
|
|
||||||
# Reservation
|
# Reservation
|
||||||
$scope.reservation = reservation
|
$scope.reservation = reservation
|
||||||
|
|
||||||
|
$scope.currencySymbol = $locale.NUMBER_FORMATS.CURRENCY_SYM
|
||||||
|
|
||||||
# Button label
|
# Button label
|
||||||
if $scope.amount > 0
|
if $scope.amount > 0
|
||||||
$scope.validButtonName = _t('confirm_(payment_on_site)')
|
$scope.validButtonName = "#{_t('confirm_my_payment_of_')} #{$filter('currency')($scope.amount)}"
|
||||||
|
else
|
||||||
|
if price.price > 0
|
||||||
|
$scope.validButtonName = "#{_t('confirm_my_payment_of_')} #{$filter('currency')(price.price)}"
|
||||||
else
|
else
|
||||||
$scope.validButtonName = _t('confirm')
|
$scope.validButtonName = _t('confirm')
|
||||||
|
|
||||||
|
@ -51,8 +51,8 @@ Application.Controllers.controller "ShowTrainingController", ['$scope', '$state'
|
|||||||
# training can be reserved during the reservation process (the shopping cart may contains only one training and a subscription).
|
# training can be reserved during the reservation process (the shopping cart may contains only one training and a subscription).
|
||||||
##
|
##
|
||||||
|
|
||||||
Application.Controllers.controller "ReserveTrainingController", ["$scope", "$state", '$stateParams', '$filter', '$compile', "$uibModal", 'Auth', 'dialogs', '$timeout', 'Price', 'Availability', 'Slot', 'Member', 'Setting', 'CustomAsset', 'availabilityTrainingsPromise', 'plansPromise', 'groupsPromise', 'growl', 'settingsPromise', 'trainingPromise', '_t', 'uiCalendarConfig', 'CalendarConfig'
|
Application.Controllers.controller "ReserveTrainingController", ["$scope", "$state", '$stateParams', '$filter', '$compile', "$uibModal", 'Auth', 'dialogs', '$timeout', 'Price', 'Availability', 'Slot', 'Member', 'Setting', 'CustomAsset', 'availabilityTrainingsPromise', 'plansPromise', 'groupsPromise', 'growl', 'settingsPromise', 'trainingPromise', '_t', 'Wallet', 'helpers', 'uiCalendarConfig', 'CalendarConfig'
|
||||||
($scope, $state, $stateParams, $filter, $compile, $uibModal, Auth, dialogs, $timeout, Price, Availability, Slot, Member, Setting, CustomAsset, availabilityTrainingsPromise, plansPromise, groupsPromise, growl, settingsPromise, trainingPromise, _t, uiCalendarConfig, CalendarConfig) ->
|
($scope, $state, $stateParams, $filter, $compile, $uibModal, Auth, dialogs, $timeout, Price, Availability, Slot, Member, Setting, CustomAsset, availabilityTrainingsPromise, plansPromise, groupsPromise, growl, settingsPromise, trainingPromise, _t, Wallet, helpers, uiCalendarConfig, CalendarConfig) ->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -188,10 +188,12 @@ Application.Controllers.controller "ReserveTrainingController", ["$scope", "$sta
|
|||||||
if Object.keys($scope.ctrl.member).length > 0
|
if Object.keys($scope.ctrl.member).length > 0
|
||||||
reservation = mkReservation($scope.ctrl.member, $scope.selectedTraining, $scope.selectedPlan)
|
reservation = mkReservation($scope.ctrl.member, $scope.selectedTraining, $scope.selectedPlan)
|
||||||
|
|
||||||
if $scope.currentUser.role isnt 'admin' and $scope.amountTotal > 0
|
Wallet.getWalletByUser {user_id: $scope.ctrl.member.id}, (wallet) ->
|
||||||
|
amountToPay = helpers.getAmountToPay($scope.amountTotal, wallet.amount)
|
||||||
|
if $scope.currentUser.role isnt 'admin' and amountToPay > 0
|
||||||
payByStripe(reservation)
|
payByStripe(reservation)
|
||||||
else
|
else
|
||||||
if $scope.currentUser.role is 'admin' or $scope.amountTotal is 0
|
if $scope.currentUser.role is 'admin' or amountToPay is 0
|
||||||
payOnSite(reservation)
|
payOnSite(reservation)
|
||||||
else
|
else
|
||||||
# otherwise we alert, this error musn't occur when the current user is not admin
|
# otherwise we alert, this error musn't occur when the current user is not admin
|
||||||
@ -474,11 +476,16 @@ Application.Controllers.controller "ReserveTrainingController", ["$scope", "$sta
|
|||||||
reservation
|
reservation
|
||||||
price: ->
|
price: ->
|
||||||
Price.compute({reservation: reservation}).$promise
|
Price.compute({reservation: reservation}).$promise
|
||||||
|
wallet: ->
|
||||||
|
Wallet.getWalletByUser({user_id: reservation.user_id}).$promise
|
||||||
cgv: ->
|
cgv: ->
|
||||||
CustomAsset.get({name: 'cgv-file'}).$promise
|
CustomAsset.get({name: 'cgv-file'}).$promise
|
||||||
controller: ['$scope', '$uibModalInstance', '$state', 'reservation', 'price', 'cgv', 'Auth', 'Reservation', ($scope, $uibModalInstance, $state, reservation, price, cgv, Auth, Reservation) ->
|
controller: ['$scope', '$uibModalInstance', '$state', 'reservation', 'price', 'wallet', 'cgv', 'Auth', 'Reservation', '$locale', 'helpers', ($scope, $uibModalInstance, $state, reservation, price, wallet, cgv, Auth, Reservation, $locale, helpers) ->
|
||||||
|
# user wallet amount
|
||||||
|
$scope.walletAmount = wallet.amount
|
||||||
|
|
||||||
# Price
|
# Price
|
||||||
$scope.amount = price.price
|
$scope.amount = helpers.getAmountToPay(price.price, wallet.amount)
|
||||||
|
|
||||||
# CGV
|
# CGV
|
||||||
$scope.cgv = cgv.custom_asset
|
$scope.cgv = cgv.custom_asset
|
||||||
@ -486,6 +493,8 @@ Application.Controllers.controller "ReserveTrainingController", ["$scope", "$sta
|
|||||||
# Reservation
|
# Reservation
|
||||||
$scope.reservation = reservation
|
$scope.reservation = reservation
|
||||||
|
|
||||||
|
$scope.currencySymbol = $locale.NUMBER_FORMATS.CURRENCY_SYM
|
||||||
|
|
||||||
##
|
##
|
||||||
# Callback to process the payment with Stripe, triggered on button click
|
# Callback to process the payment with Stripe, triggered on button click
|
||||||
##
|
##
|
||||||
@ -525,16 +534,29 @@ Application.Controllers.controller "ReserveTrainingController", ["$scope", "$sta
|
|||||||
reservation
|
reservation
|
||||||
price: ->
|
price: ->
|
||||||
Price.compute({reservation: reservation}).$promise
|
Price.compute({reservation: reservation}).$promise
|
||||||
controller: ['$scope', '$uibModalInstance', '$state', 'reservation', 'price', 'Auth', 'Reservation', ($scope, $uibModalInstance, $state, reservation, price, Auth, Reservation) ->
|
wallet: ->
|
||||||
|
Wallet.getWalletByUser({user_id: reservation.user_id}).$promise
|
||||||
|
controller: ['$scope', '$uibModalInstance', '$state', '$filter', 'reservation', 'price', 'wallet', 'Auth', 'Reservation', '$locale', 'helpers', ($scope, $uibModalInstance, $state, $filter, reservation, price, wallet, Auth, Reservation, $locale, helpers) ->
|
||||||
|
# user wallet amount
|
||||||
|
$scope.walletAmount = wallet.amount
|
||||||
|
|
||||||
# Price
|
# Price
|
||||||
$scope.amount = price.price
|
$scope.price = price.price
|
||||||
|
|
||||||
|
# price to pay
|
||||||
|
$scope.amount = helpers.getAmountToPay(price.price, wallet.amount)
|
||||||
|
|
||||||
# Reservation
|
# Reservation
|
||||||
$scope.reservation = reservation
|
$scope.reservation = reservation
|
||||||
|
|
||||||
|
$scope.currencySymbol = $locale.NUMBER_FORMATS.CURRENCY_SYM
|
||||||
|
|
||||||
# Button label
|
# Button label
|
||||||
if $scope.amount > 0
|
if $scope.amount > 0
|
||||||
$scope.validButtonName = _t('confirm_(payment_on_site)')
|
$scope.validButtonName = "#{_t('confirm_my_payment_of_')} #{$filter('currency')($scope.amount)}"
|
||||||
|
else
|
||||||
|
if price.price > 0
|
||||||
|
$scope.validButtonName = "#{_t('confirm_my_payment_of_')} #{$filter('currency')(price.price)}"
|
||||||
else
|
else
|
||||||
$scope.validButtonName = _t('confirm')
|
$scope.validButtonName = _t('confirm')
|
||||||
|
|
||||||
|
@ -204,8 +204,8 @@ angular.module('application.router', ['ui.router']).
|
|||||||
templateUrl: '<%= asset_path "dashboard/wallet.html" %>'
|
templateUrl: '<%= asset_path "dashboard/wallet.html" %>'
|
||||||
controller: 'WalletController'
|
controller: 'WalletController'
|
||||||
resolve:
|
resolve:
|
||||||
walletPromise: ['Wallet', (Wallet)->
|
walletPromise: ['Wallet', 'currentUser', (Wallet, currentUser)->
|
||||||
Wallet.my().$promise
|
Wallet.getWalletByUser(user_id: currentUser.id).$promise
|
||||||
]
|
]
|
||||||
transactionsPromise: ['Wallet', 'walletPromise', (Wallet, walletPromise)->
|
transactionsPromise: ['Wallet', 'walletPromise', (Wallet, walletPromise)->
|
||||||
Wallet.transactions(id: walletPromise.id).$promise
|
Wallet.transactions(id: walletPromise.id).$promise
|
||||||
@ -363,7 +363,7 @@ angular.module('application.router', ['ui.router']).
|
|||||||
]
|
]
|
||||||
translations: [ 'Translations', (Translations) ->
|
translations: [ 'Translations', (Translations) ->
|
||||||
Translations.query(['app.logged.machines_reserve', 'app.shared.plan_subscribe', 'app.shared.member_select',
|
Translations.query(['app.logged.machines_reserve', 'app.shared.plan_subscribe', 'app.shared.member_select',
|
||||||
'app.shared.stripe', 'app.shared.valid_reservation_modal', 'app.shared.confirm_modify_slot_modal']).$promise
|
'app.shared.stripe', 'app.shared.valid_reservation_modal', 'app.shared.confirm_modify_slot_modal', 'app.shared.wallet']).$promise
|
||||||
]
|
]
|
||||||
.state 'app.admin.machines_edit',
|
.state 'app.admin.machines_edit',
|
||||||
url: '/machines/:id/edit'
|
url: '/machines/:id/edit'
|
||||||
@ -440,7 +440,7 @@ angular.module('application.router', ['ui.router']).
|
|||||||
]
|
]
|
||||||
translations: [ 'Translations', (Translations) ->
|
translations: [ 'Translations', (Translations) ->
|
||||||
Translations.query(['app.logged.trainings_reserve', 'app.shared.plan_subscribe', 'app.shared.member_select',
|
Translations.query(['app.logged.trainings_reserve', 'app.shared.plan_subscribe', 'app.shared.member_select',
|
||||||
'app.shared.stripe', 'app.shared.valid_reservation_modal', 'app.shared.confirm_modify_slot_modal']).$promise
|
'app.shared.stripe', 'app.shared.valid_reservation_modal', 'app.shared.confirm_modify_slot_modal', 'app.shared.wallet']).$promise
|
||||||
]
|
]
|
||||||
# notifications
|
# notifications
|
||||||
.state 'app.logged.notifications',
|
.state 'app.logged.notifications',
|
||||||
@ -510,7 +510,7 @@ angular.module('application.router', ['ui.router']).
|
|||||||
Setting.get(name: 'event_reduced_amount_alert').$promise
|
Setting.get(name: 'event_reduced_amount_alert').$promise
|
||||||
]
|
]
|
||||||
translations: [ 'Translations', (Translations) ->
|
translations: [ 'Translations', (Translations) ->
|
||||||
Translations.query(['app.public.events_show', 'app.shared.member_select', 'app.shared.stripe', 'app.shared.valid_reservation_modal']).$promise
|
Translations.query(['app.public.events_show', 'app.shared.member_select', 'app.shared.stripe', 'app.shared.valid_reservation_modal', 'app.shared.wallet']).$promise
|
||||||
]
|
]
|
||||||
|
|
||||||
# calendar global (trainings, machines and events)
|
# calendar global (trainings, machines and events)
|
||||||
|
6
app/assets/javascripts/services/helpers.coffee
Normal file
6
app/assets/javascripts/services/helpers.coffee
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
Application.Services.factory 'helpers', [()->
|
||||||
|
getAmountToPay: (price, walletAmount)->
|
||||||
|
if walletAmount > price then 0 else price - walletAmount
|
||||||
|
]
|
@ -3,10 +3,6 @@
|
|||||||
Application.Services.factory 'Wallet', ["$resource", ($resource)->
|
Application.Services.factory 'Wallet', ["$resource", ($resource)->
|
||||||
$resource "/api/wallet",
|
$resource "/api/wallet",
|
||||||
{},
|
{},
|
||||||
my:
|
|
||||||
method: 'GET'
|
|
||||||
url: '/api/wallet/my'
|
|
||||||
isArray: false
|
|
||||||
getWalletByUser:
|
getWalletByUser:
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
url: '/api/wallet/by_user/:user_id'
|
url: '/api/wallet/by_user/:user_id'
|
||||||
|
@ -3,6 +3,10 @@
|
|||||||
<h1 translate>{{ 'booking_confirmation' }}</h1>
|
<h1 translate>{{ 'booking_confirmation' }}</h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
<h3 ng-if="walletAmount > 0 && price > 0">{{ 'you_have_amount_in_wallet' | translate:{ amount: walletAmount, currency: currencySymbol } }}</h3>
|
||||||
|
<p ng-if="walletAmount > 0 && price > 0 && amount === 0" class="text-italic">{{'wallet_pay_reservation' | translate}}</p>
|
||||||
|
<p ng-if="walletAmount > 0 && amount !== 0" class="text-italic">{{'credit_amount_for_pay_reservation' | translate:{ amount: amount, currency: currencySymbol } }}</p>
|
||||||
|
|
||||||
<p translate>{{ 'here_is_the_summary_of_the_slots_to_book_for_the_current_user' }}</p>
|
<p translate>{{ 'here_is_the_summary_of_the_slots_to_book_for_the_current_user' }}</p>
|
||||||
<ul ng-repeat="slot in reservation.slots_attributes">
|
<ul ng-repeat="slot in reservation.slots_attributes">
|
||||||
<li><strong>{{slot.start_at | amDateFormat: 'LL'}} : {{slot.start_at | amDateFormat:'LT'}} - {{slot.end_at | amDateFormat:'LT'}}</strong></li>
|
<li><strong>{{slot.start_at | amDateFormat: 'LL'}} : {{slot.start_at | amDateFormat:'LT'}} - {{slot.end_at | amDateFormat:'LT'}}</strong></li>
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<h3 ng-if="walletAmount">{{ 'you_have_amount_in_wallet' | translate:{ amount: walletAmount, currency: currencySymbol } }}</h3>
|
||||||
|
<p ng-if="walletAmount > 0 && amount !== 0" class="text-italic">{{'credit_amount_for_pay_reservation' | translate:{ amount: amount, currency: currencySymbol } }}</p>
|
||||||
|
|
||||||
<div class="form-group" ng-class="{'has-error': stripeForm.number.$dirty && stripeForm.number.$invalid}">
|
<div class="form-group" ng-class="{'has-error': stripeForm.number.$dirty && stripeForm.number.$invalid}">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<input autocomplete="off" class="form-control card-number" placeholder="{{ 'enter_your_card_number' | translate }}" type="text" data-stripe="number" name="number" ng-model="cardNumero" required ng-minlength="14" ng-maxlength="16" ng-pattern="/^\d+$/">
|
<input autocomplete="off" class="form-control card-number" placeholder="{{ 'enter_your_card_number' | translate }}" type="text" data-stripe="number" name="number" ng-model="cardNumero" required ng-minlength="14" ng-maxlength="16" ng-pattern="/^\d+$/">
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
class API::WalletController < API::ApiController
|
class API::WalletController < API::ApiController
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
|
|
||||||
def my
|
|
||||||
@wallet = current_user.wallet
|
|
||||||
render :show
|
|
||||||
end
|
|
||||||
|
|
||||||
def by_user
|
def by_user
|
||||||
authorize Wallet
|
|
||||||
@wallet = Wallet.find_by(user_id: params[:user_id])
|
@wallet = Wallet.find_by(user_id: params[:user_id])
|
||||||
|
authorize @wallet
|
||||||
render :show
|
render :show
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ class Reservation < ActiveRecord::Base
|
|||||||
after_commit :notify_member_create_reservation, on: :create
|
after_commit :notify_member_create_reservation, on: :create
|
||||||
after_commit :notify_admin_member_create_reservation, on: :create
|
after_commit :notify_admin_member_create_reservation, on: :create
|
||||||
after_save :update_event_nb_free_places, if: Proc.new { |reservation| reservation.reservable_type == 'Event' }
|
after_save :update_event_nb_free_places, if: Proc.new { |reservation| reservation.reservable_type == 'Event' }
|
||||||
|
after_save :debit_user_wallet
|
||||||
|
|
||||||
#
|
#
|
||||||
# Generate an array of {Stripe::InvoiceItem} with the elements in the current reservation, price included.
|
# Generate an array of {Stripe::InvoiceItem} with the elements in the current reservation, price included.
|
||||||
@ -124,6 +125,18 @@ class Reservation < ActiveRecord::Base
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
total = invoice_items.map(&:amount).map(&:to_i).reduce(:+) || 0
|
||||||
|
wallet_amount = (user.wallet.amount * 100).to_i
|
||||||
|
@wallet_amount_debit = wallet_amount >= total ? total : wallet_amount
|
||||||
|
if @wallet_amount_debit != 0
|
||||||
|
invoice_items << Stripe::InvoiceItem.create(
|
||||||
|
customer: user.stp_customer_id,
|
||||||
|
amount: -@wallet_amount_debit,
|
||||||
|
currency: Rails.application.secrets.stripe_currency,
|
||||||
|
description: "wallet -#{@wallet_amount_debit / 100.0}"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
# let's return the resulting array of items
|
# let's return the resulting array of items
|
||||||
invoice_items
|
invoice_items
|
||||||
end
|
end
|
||||||
@ -170,49 +183,49 @@ class Reservation < ActiveRecord::Base
|
|||||||
#
|
#
|
||||||
# IMPORTANT NOTE: here, we have to create an invoice manually and pay it to pay all waiting stripe invoice items
|
# IMPORTANT NOTE: here, we have to create an invoice manually and pay it to pay all waiting stripe invoice items
|
||||||
#
|
#
|
||||||
invoice = Stripe::Invoice.create(
|
stp_invoice = Stripe::Invoice.create(
|
||||||
customer: user.stp_customer_id,
|
customer: user.stp_customer_id,
|
||||||
)
|
)
|
||||||
invoice.pay
|
stp_invoice.pay
|
||||||
card.delete if card
|
card.delete if card
|
||||||
self.stp_invoice_id = invoice.id
|
self.stp_invoice_id = stp_invoice.id
|
||||||
self.invoice.stp_invoice_id = invoice.id
|
self.invoice.stp_invoice_id = stp_invoice.id
|
||||||
self.invoice.total = invoice.total
|
self.invoice.total = invoice.invoice_items.map(&:amount).map(&:to_i).reduce(:+)
|
||||||
save!
|
save!
|
||||||
rescue Stripe::CardError => card_error
|
rescue Stripe::CardError => card_error
|
||||||
clear_payment_info(card, invoice, invoice_items)
|
clear_payment_info(card, stp_invoice, invoice_items)
|
||||||
logger.info card_error
|
logger.info card_error
|
||||||
errors[:card] << card_error.message
|
errors[:card] << card_error.message
|
||||||
return false
|
return false
|
||||||
rescue Stripe::InvalidRequestError => e
|
rescue Stripe::InvalidRequestError => e
|
||||||
# Invalid parameters were supplied to Stripe's API
|
# Invalid parameters were supplied to Stripe's API
|
||||||
clear_payment_info(card, invoice, invoice_items)
|
clear_payment_info(card, stp_invoice, invoice_items)
|
||||||
logger.error e
|
logger.error e
|
||||||
errors[:payment] << e.message
|
errors[:payment] << e.message
|
||||||
return false
|
return false
|
||||||
rescue Stripe::AuthenticationError => e
|
rescue Stripe::AuthenticationError => e
|
||||||
# Authentication with Stripe's API failed
|
# Authentication with Stripe's API failed
|
||||||
# (maybe you changed API keys recently)
|
# (maybe you changed API keys recently)
|
||||||
clear_payment_info(card, invoice, invoice_items)
|
clear_payment_info(card, stp_invoice, invoice_items)
|
||||||
logger.error e
|
logger.error e
|
||||||
errors[:payment] << e.message
|
errors[:payment] << e.message
|
||||||
return false
|
return false
|
||||||
rescue Stripe::APIConnectionError => e
|
rescue Stripe::APIConnectionError => e
|
||||||
# Network communication with Stripe failed
|
# Network communication with Stripe failed
|
||||||
clear_payment_info(card, invoice, invoice_items)
|
clear_payment_info(card, stp_invoice, invoice_items)
|
||||||
logger.error e
|
logger.error e
|
||||||
errors[:payment] << e.message
|
errors[:payment] << e.message
|
||||||
return false
|
return false
|
||||||
rescue Stripe::StripeError => e
|
rescue Stripe::StripeError => e
|
||||||
# Display a very generic error to the user, and maybe send
|
# Display a very generic error to the user, and maybe send
|
||||||
# yourself an email
|
# yourself an email
|
||||||
clear_payment_info(card, invoice, invoice_items)
|
clear_payment_info(card, stp_invoice, invoice_items)
|
||||||
logger.error e
|
logger.error e
|
||||||
errors[:payment] << e.message
|
errors[:payment] << e.message
|
||||||
return false
|
return false
|
||||||
rescue => e
|
rescue => e
|
||||||
# Something else happened, completely unrelated to Stripe
|
# Something else happened, completely unrelated to Stripe
|
||||||
clear_payment_info(card, invoice, invoice_items)
|
clear_payment_info(card, stp_invoice, invoice_items)
|
||||||
logger.error e
|
logger.error e
|
||||||
errors[:payment] << e.message
|
errors[:payment] << e.message
|
||||||
return false
|
return false
|
||||||
@ -332,4 +345,11 @@ class Reservation < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
reservable.update_columns(nb_free_places: nb_free_places)
|
reservable.update_columns(nb_free_places: nb_free_places)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def debit_user_wallet
|
||||||
|
if @wallet_amount_debit.present? and @wallet_amount_debit != 0
|
||||||
|
amount = @wallet_amount_debit / 100.0
|
||||||
|
WalletService.new(user: user, wallet: user.wallet).debit(amount, self)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
class WalletPolicy < ApplicationPolicy
|
class WalletPolicy < ApplicationPolicy
|
||||||
def by_user?
|
def by_user?
|
||||||
user.is_admin?
|
user.is_admin? or user == record.user
|
||||||
end
|
end
|
||||||
|
|
||||||
def transactions?
|
def transactions?
|
||||||
|
@ -16,5 +16,14 @@ class WalletService
|
|||||||
attached_object: transaction
|
attached_object: transaction
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
def debit(amount, transactable)
|
||||||
|
if @wallet.debit(amount)
|
||||||
|
WalletTransaction.create(user: @user, wallet: @wallet, transaction_type: 'debit', amount: amount, transactable: transactable)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -48,8 +48,7 @@ Rails.application.routes.draw do
|
|||||||
resources :notifications, only: [:index, :show, :update] do
|
resources :notifications, only: [:index, :show, :update] do
|
||||||
match :update_all, path: '/', via: [:put, :patch], on: :collection
|
match :update_all, path: '/', via: [:put, :patch], on: :collection
|
||||||
end
|
end
|
||||||
resources :wallet do
|
resources :wallet, only: [] do
|
||||||
get :my, on: :collection
|
|
||||||
get '/by_user/:user_id', action: 'by_user', on: :collection
|
get '/by_user/:user_id', action: 'by_user', on: :collection
|
||||||
get :transactions, on: :member
|
get :transactions, on: :member
|
||||||
put :credit, on: :member
|
put :credit, on: :member
|
||||||
|
@ -15,7 +15,7 @@ class WalletsTest < ActionDispatch::IntegrationTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
test 'get my wallet' do
|
test 'get my wallet' do
|
||||||
get '/api/wallet/my'
|
get "/api/wallet/by_user/#{@kdumas.id}"
|
||||||
assert_equal 200, response.status
|
assert_equal 200, response.status
|
||||||
assert_equal Mime::JSON, response.content_type
|
assert_equal Mime::JSON, response.content_type
|
||||||
wallet = json_response(response.body)
|
wallet = json_response(response.body)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user