1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00

quick coding rules checking with rubocop

This commit is contained in:
Sylvain 2019-09-09 18:04:31 +02:00
parent e94cf46fa4
commit e9e27663cd
8 changed files with 34 additions and 42 deletions

View File

@ -350,11 +350,7 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
if ($scope.isAdmin()) { return true; }
const slotStart = moment(slot.start);
const now = moment();
if (slot.can_modify && $scope.enableBookingMove && (slotStart.diff(now, 'hours') >= $scope.moveBookingDelay)) {
return true;
} else {
return false;
}
return (slot.can_modify && $scope.enableBookingMove && (slotStart.diff(now, 'hours') >= $scope.moveBookingDelay));
};
/**
@ -365,11 +361,7 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
if ($scope.isAdmin()) { return true; }
const slotStart = moment(slot.start);
const now = moment();
if (slot.can_modify && $scope.enableBookingCancel && (slotStart.diff(now, 'hours') >= $scope.cancelBookingDelay)) {
return true;
} else {
return false;
}
return (slot.can_modify && $scope.enableBookingCancel && (slotStart.diff(now, 'hours') >= $scope.cancelBookingDelay));
};
/**
@ -448,7 +440,7 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
slots_attributes: [],
plan_id: ((plan ? plan.id : undefined))
};
angular.forEach(slots, function (slot, key) {
angular.forEach(slots, function (slot) {
reservation.slots_attributes.push({
start_at: slot.start,
end_at: slot.end,
@ -608,7 +600,7 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
}
, function (response) {
$scope.alerts = [];
$scope.alerts.push({ msg: _t('cart.a_problem_occured_during_the_payment_process_please_try_again_later'), type: 'danger' });
$scope.alerts.push({ msg: _t('cart.a_problem_occurred_during_the_payment_process_please_try_again_later'), type: 'danger' });
return $scope.attempting = false;
});
};
@ -618,7 +610,7 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
}).result['finally'](null).then(function (reservation) { afterPayment(reservation); });
};
/**
* Actions to run after the payment was successfull
* Actions to run after the payment was successful
*/
var afterPayment = function (reservation) {
// we set the cart content as 'paid' to display a summary of the transaction

View File

@ -5,51 +5,51 @@ class API::PaymentsController < API::ApiController
before_action :authenticate_user!
def confirm_payment
begin
if params[:payment_method_id].present?
# Create the PaymentIntent
# TODO the client has to provide the reservation details. Then, we use Price.compute - user.walletAmount to get the amount
# currency is set in Rails.secrets
reservable = cart_items_params[:reservable_type].constantize.find(cart_items_params[:reservable_id])
price_details = Price.compute(false,
current_user,
reservable,
cart_items_params[:slots_attributes] || [],
cart_items_params[:plan_id],
cart_items_params[:nb_reserve_places],
cart_items_params[:tickets_attributes],
coupon_params[:coupon_code])
current_user,
reservable,
cart_items_params[:slots_attributes] || [],
cart_items_params[:plan_id],
cart_items_params[:nb_reserve_places],
cart_items_params[:tickets_attributes],
coupon_params[:coupon_code])
intent = Stripe::PaymentIntent.create(
payment_method: params[:payment_method_id],
amount: price_details[:total],
currency: 'eur',
currency: 'eur',
confirmation_method: 'manual',
confirm: true
)
elsif params[:payment_intent_id].present?
intent = Stripe::PaymentIntent.confirm(params[:payment_intent_id])
end
rescue Stripe::CardError => e
# Display error on client
render status: 200, json: { error: e.message }
end
if intent.status == 'succeeded'
# TODO extract in subroutine
if intent.status == 'succeeded'
begin
user_id = params[:cart_items][:reservation][:user_id]
user_id = params[:cart_items][:reservation][:user_id]
@reservation = Reservation.new(reservation_params)
is_reserve = Reservations::Reserve.new(user_id, current_user.invoicing_profile.id)
.pay_and_save(@reservation, :stripe, coupon_params[:coupon_code])
if is_reserve
SubscriptionExtensionAfterReservation.new(@reservation).extend_subscription_if_eligible
render('api/reservations/show', status: :created, location: @reservation) and return
else
render(json: @reservation.errors, status: :unprocessable_entity) and return
@ -75,7 +75,7 @@ class API::PaymentsController < API::ApiController
}
}
elsif intent.status == 'succeeded'
# The payment didnt need any additional actions and is completed!
# The payment didn't need any additional actions and is completed!
# Handle post-payment fulfillment
{ status: 200, json: { success: true } }
else
@ -86,17 +86,17 @@ class API::PaymentsController < API::ApiController
def reservation_params
params[:cart_items].require(:reservation).permit(:reservable_id, :reservable_type, :plan_id, :nb_reserve_places,
tickets_attributes: %i[event_price_category_id booked],
slots_attributes: %i[id start_at end_at availability_id offered])
tickets_attributes: %i[event_price_category_id booked],
slots_attributes: %i[id start_at end_at availability_id offered])
end
def cart_items_params
params[:cart_items].require(:reservation).permit(:reservable_id, :reservable_type, :plan_id, :user_id, :nb_reserve_places,
tickets_attributes: %i[event_price_category_id booked],
slots_attributes: %i[id start_at end_at availability_id offered])
tickets_attributes: %i[event_price_category_id booked],
slots_attributes: %i[id start_at end_at availability_id offered])
end
def coupon_params
params.require(:cart_items).permit(:coupon_code)
end
end
end

View File

@ -23,8 +23,8 @@ class API::ReservationsController < API::ApiController
def create
authorize Reservation
user_id = params[:reservation][:user_id]
user_id = params[:reservation][:user_id]
@reservation = Reservation.new(reservation_params)
is_reserve = Reservations::Reserve.new(user_id, current_user.invoicing_profile.id)

View File

@ -203,7 +203,7 @@ class Reservation < ActiveRecord::Base
#
else
# error handling
# errors[:card] << subscription.errors[:card].join
# errors[:payment] << subscription.errors[:payment].join if subscription.errors[:payment]

View File

@ -461,5 +461,5 @@ en:
reservation_was_cancelled_successfully: "Reservation was cancelled successfully."
cancellation_failed: "Cancellation failed."
confirm_payment_of_html: "{ROLE, select, admin{Payment on site} other{Pay}}: {AMOUNT}" # messageFormat interpolation (context: confirm my payment of $20.00)
a_problem_occured_during_the_payment_process_please_try_again_later: "A problem occurred during the payment process. Please try again later."
a_problem_occurred_during_the_payment_process_please_try_again_later: "A problem occurred during the payment process. Please try again later."
none: "None"

View File

@ -461,5 +461,5 @@ es:
reservation_was_cancelled_successfully: "La reserva se ha cancelado con éxito."
cancellation_failed: "Cancelación fallida."
confirm_payment_of_html: "{ROLE, select, admin{Payment on site} other{Pay}}: {AMOUNT}" # messageFormat interpolation (context: confirm my payment of $20.00)
a_problem_occured_during_the_payment_process_please_try_again_later: "A problem occurred during the payment process. Please try again later."
a_problem_occurred_during_the_payment_process_please_try_again_later: "A problem occurred during the payment process. Please try again later."
none: "Ninguno"

View File

@ -461,5 +461,5 @@ fr:
reservation_was_cancelled_successfully: "La réservation a bien été annulée."
cancellation_failed: "L'annulation a échouée."
confirm_payment_of_html: "{ROLE, select, admin{Paiement sur place} other{Payer}} : {AMOUNT}" # messageFormat interpolation (contexte : valider mon paiement de 20,00 €)
a_problem_occured_during_the_payment_process_please_try_again_later: "Il y a eu un problème lors de la procédure de paiement. Veuillez réessayer plus tard."
a_problem_occurred_during_the_payment_process_please_try_again_later: "Il y a eu un problème lors de la procédure de paiement. Veuillez réessayer plus tard."
none: "Aucune"

View File

@ -461,5 +461,5 @@ pt:
reservation_was_cancelled_successfully: "Reserva a foi cancelada com sucesso."
cancellation_failed: "Cancelamento falhou."
confirm_payment_of_html: "{ROLE, select, admin{Pagamento pelo site} other{Pagar}}: {AMOUNT}" # messageFormat interpolation (context: confirm my payment of $20.00)
a_problem_occured_during_the_payment_process_please_try_again_later: "Um problema ocorreu durante o processo de pagamento. Por favor tente novamente mais tarde."
a_problem_occurred_during_the_payment_process_please_try_again_later: "Um problema ocorreu durante o processo de pagamento. Por favor tente novamente mais tarde."
none: "Vazio"