1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-29 18:52:22 +01:00

fix test Reservations::CreateAsAdminTest

create subscription from POST api/reservation if the parameter subscription.plan_id is provided
+ cart_items are not wrapped in a reservation object
This commit is contained in:
Sylvain 2021-04-26 18:27:35 +02:00
parent d5f7bd7abd
commit 1bf091081b
2 changed files with 8 additions and 6 deletions

View File

@ -68,7 +68,7 @@ class API::PaymentsController < API::ApiController
payment_details: details,
payment_id: gateway_item_id,
payment_type: gateway_item_type,
schedule: params[:cart_items][:reservation][:payment_schedule],
schedule: params[:cart_items][:payment_schedule],
payment_method: payment_method)
post_reservation_save(gateway_item_id, gateway_item_type)

View File

@ -34,11 +34,13 @@ class API::ReservationsController < API::ApiController
authorize ReservationContext.new(Reservation, price[:amount], user_id)
@reservation = Reservation.new(reservation_params)
@reservation.plan_id = params[:subscription][:plan_id] if params[:subscription] && params[:subscription][:plan_id]
is_reserve = Reservations::Reserve.new(user_id, current_user.invoicing_profile.id)
.pay_and_save(@reservation,
payment_details: price[:price_details],
schedule: params[:reservation][:payment_schedule],
payment_method: params[:reservation][:payment_method])
schedule: params[:payment_schedule],
payment_method: params[:payment_method])
if is_reserve
SubscriptionExtensionAfterReservation.new(@reservation).extend_subscription_if_eligible
@ -67,11 +69,11 @@ class API::ReservationsController < API::ApiController
cs = CartService.new(current_user)
cart = cs.from_hash(customer_id: user_id,
subscription: {
plan_id: reservation_params[:plan_id]
plan_id: params[:subscription] ? params[:subscription][:plan_id] : nil
},
reservation: reservation_params,
coupon_code: coupon_params[:coupon_code],
payment_schedule: reservation_params[:payment_schedule])
payment_schedule: params[:payment_schedule])
price_details = cart.total
# Subtract wallet amount from total
@ -91,7 +93,7 @@ class API::ReservationsController < API::ApiController
end
def reservation_params
params.require(:reservation).permit(:message, :reservable_id, :reservable_type, :plan_id, :nb_reserve_places,
params.require(:reservation).permit(:message, :reservable_id, :reservable_type, :nb_reserve_places,
tickets_attributes: %i[event_price_category_id booked],
slots_attributes: %i[id start_at end_at availability_id offered])
end