diff --git a/app/services/invoices_service.rb b/app/services/invoices_service.rb index 52f28a411..bda6c5fa1 100644 --- a/app/services/invoices_service.rb +++ b/app/services/invoices_service.rb @@ -61,7 +61,7 @@ class InvoicesService end ## - # Create a Stripe::Invoice with an associated array of Stripe::InvoiceItem matching the given parameters + # Create an Invoice with an associated array of InvoiceItem matching the given parameters # @param payment_details {Hash} as generated by Price.compute # @param operator_profile_id {Number} ID of the user that operates the invoice generation (may be an admin, a manager or the customer himself) # @param reservation {Reservation} the booking reservation, if any @@ -88,7 +88,7 @@ class InvoicesService end ## - # Generate an array of {Stripe::InvoiceItem} with the elements in provided reservation, price included. + # Generate an array of {InvoiceItem} with the elements in provided reservation, price included. # @param invoice {Invoice} the parent invoice # @param payment_details {Hash} as generated by Price.compute ## @@ -111,7 +111,7 @@ class InvoicesService end ## - # Generate Stripe::InvoiceItem for each slot in the given reservation and save them in invoice.invoice_items. + # Generate an InvoiceItem for each slot in the given reservation and save them in invoice.invoice_items. # This method must be called if reservation.reservable is an Event ## def self.generate_event_item(invoice, reservation, payment_details) @@ -140,7 +140,7 @@ class InvoicesService end ## - # Generate Stripe::InvoiceItem for each slot in the given reservation and save them in invoice.invoice_items. + # Generate an InvoiceItem for each slot in the given reservation and save them in invoice.invoice_items. # This method must be called if reservation.reservable is a Space, a Machine or a Training ## def self.generate_generic_item(invoice, reservation, payment_details) @@ -159,7 +159,7 @@ class InvoicesService end ## - # Generate a Stripe::InvoiceItem for the given subscription and save it in invoice.invoice_items. + # Generate an InvoiceItem for the given subscription and save it in invoice.invoice_items. # This method must be called only with a valid subscription ## def self.generate_subscription_item(invoice, subscription, payment_details) diff --git a/app/services/payment_schedule_service.rb b/app/services/payment_schedule_service.rb index aa299e114..7f704b101 100644 --- a/app/services/payment_schedule_service.rb +++ b/app/services/payment_schedule_service.rb @@ -47,7 +47,9 @@ class PaymentScheduleService end def create(subscription, total, coupon: nil, operator: nil, payment_method: nil, reservation: nil, user: nil) - schedule = compute(reservation ? reservation.subscription.plan : subscription.plan, total, coupon) + subscription = reservation.generate_subscription if !subscription && reservation.plan_id + + schedule = compute(subscription.plan, total, coupon) ps = schedule[:payment_schedule] items = schedule[:items] diff --git a/app/services/reservations/reserve.rb b/app/services/reservations/reserve.rb index 6b942f14b..77599952b 100644 --- a/app/services/reservations/reserve.rb +++ b/app/services/reservations/reserve.rb @@ -31,6 +31,7 @@ class Reservations::Reserve payment.save debit_user_wallet(payment, user, reservation) reservation.post_save + true end ##