From c3c881d2a8d3c1933764a5c935bb2a3d291615cd Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 9 Dec 2020 16:47:51 +0100 Subject: [PATCH] process the schedule to the stripe subscription - only for subscriptions for now - TODO: reservations (see app/services/reservations/reserv.rb:13) --- app/controllers/api/payments_controller.rb | 15 +++++++++++++-- .../src/javascript/components/stripe-modal.tsx | 6 +++--- app/frontend/src/javascript/directives/cart.js | 3 ++- .../src/stylesheets/modules/stripe-modal.scss | 1 + app/services/reservations/reserve.rb | 3 ++- config/locales/app.shared.en.yml | 2 +- config/locales/app.shared.fr.yml | 2 +- 7 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/payments_controller.rb b/app/controllers/api/payments_controller.rb index 2bfe19502..6732ebddb 100644 --- a/app/controllers/api/payments_controller.rb +++ b/app/controllers/api/payments_controller.rb @@ -97,7 +97,12 @@ class API::PaymentsController < API::ApiController def on_reservation_success(intent, details) @reservation = Reservation.new(reservation_params) - is_reserve = Reservations::Reserve.new(current_user.id, current_user.invoicing_profile.id) + user_id = if current_user.admin? || current_user.manager? + params[:cart_items][:reservation][:user_id] + else + current_user.id + end + is_reserve = Reservations::Reserve.new(user_id, current_user.invoicing_profile.id) .pay_and_save(@reservation, payment_details: details, payment_intent_id: intent.id) if intent.class == Stripe::PaymentIntent Stripe::PaymentIntent.update( @@ -118,11 +123,17 @@ class API::PaymentsController < API::ApiController def on_subscription_success(intent) @subscription = Subscription.new(subscription_params) - is_subscribe = Subscriptions::Subscribe.new(current_user.invoicing_profile.id, current_user.id) + user_id = if current_user.admin? || current_user.manager? + params[:cart_items][:subscription][:user_id] + else + current_user.id + end + is_subscribe = Subscriptions::Subscribe.new(current_user.invoicing_profile.id, user_id) .pay_and_save(@subscription, coupon: coupon_params[:coupon_code], invoice: true, payment_intent_id: intent.id, + schedule: params[:cart_items][:subscription][:payment_schedule], payment_method: 'stripe') if intent.class == Stripe::PaymentIntent Stripe::PaymentIntent.update( diff --git a/app/frontend/src/javascript/components/stripe-modal.tsx b/app/frontend/src/javascript/components/stripe-modal.tsx index e5ac1dc3b..f106aebcd 100644 --- a/app/frontend/src/javascript/components/stripe-modal.tsx +++ b/app/frontend/src/javascript/components/stripe-modal.tsx @@ -185,6 +185,9 @@ const StripeModal: React.FC = ({ isOpen, toggleModal, afterSuc {hasErrors() &&
{errors}
} + {isPaymentSchedule() &&
+ +
} {hasCgv() &&
} - {isPaymentSchedule() &&
- -
} {!submitState &&