diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 5efbed895..b0e2cfa21 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -22,7 +22,6 @@ class Invoice < PaymentDocument has_one :avoir, class_name: 'Invoice', foreign_key: :invoice_id, dependent: :destroy has_one :payment_schedule_item has_one :payment_gateway_object, as: :item - accepts_nested_attributes_for :payment_gateway_object belongs_to :operator_profile, foreign_key: :operator_profile_id, class_name: 'InvoicingProfile' before_create :add_environment diff --git a/app/services/invoices_service.rb b/app/services/invoices_service.rb index 5bf0ba7cf..397ab8626 100644 --- a/app/services/invoices_service.rb +++ b/app/services/invoices_service.rb @@ -75,18 +75,19 @@ class InvoicesService method = if payment_method payment_method else - operator&.admin? || (operator&.manager? && operator != user) ? nil : Setting.get('payment_gateway') + operator&.admin? || (operator&.manager? && operator != user) ? nil : 'card' end - pgo = payment_id.nil? ? {} : { gateway_object_id: payment_id, gateway_object_type: payment_type } invoice = Invoice.new( invoiced: subscription || reservation, invoicing_profile: user.invoicing_profile, statistic_profile: user.statistic_profile, operator_profile_id: operator_profile_id, - payment_gateway_object_attributes: pgo, payment_method: method ) + unless payment_id.nil? + invoice.payment_gateway_object = PaymentGatewayObject.new(gateway_object_id: payment_id, gateway_object_type: payment_type) + end InvoicesService.generate_invoice_items(invoice, payment_details, reservation: reservation, subscription: subscription) InvoicesService.set_total_and_coupon(invoice, user, payment_details[:coupon]) diff --git a/app/services/payment_schedule_service.rb b/app/services/payment_schedule_service.rb index 13fd5ae1c..75c68ff7b 100644 --- a/app/services/payment_schedule_service.rb +++ b/app/services/payment_schedule_service.rb @@ -91,12 +91,11 @@ class PaymentScheduleService invoicing_profile: payment_schedule_item.payment_schedule.invoicing_profile, statistic_profile: payment_schedule_item.payment_schedule.statistic_profile, operator_profile_id: payment_schedule_item.payment_schedule.operator_profile_id, - payment_gateway_object_attributes: { - gateway_object_id: payment_id, - gateway_object_type: payment_type - }, payment_method: payment_method ) + unless payment_id.nil? + invoice.payment_gateway_object = PaymentGatewayObject.new(gateway_object_id: payment_id, gateway_object_type: payment_type) + end # complete the invoice with some InvoiceItem if payment_schedule_item.first? complete_first_invoice(payment_schedule_item, invoice)