diff --git a/app/controllers/registrar/payments_controller.rb b/app/controllers/registrar/payments_controller.rb index c1944767f..598d13446 100644 --- a/app/controllers/registrar/payments_controller.rb +++ b/app/controllers/registrar/payments_controller.rb @@ -12,13 +12,15 @@ class Registrar invoice = Invoice.find(params[:invoice_id]) channel = params[:bank] - @payment_order = PaymentOrder.create_with_type(type: channel, invoice: invoice) - @payment_order.save && @payment_order.reload + @payment_order = PaymentOrder.new_with_type(type: channel, invoice: invoice) + @payment_order.save + @payment_order.reload @payment_order.return_url = registrar_return_payment_with_url(@payment_order) @payment_order.response_url = registrar_response_payment_with_url(@payment_order) - @payment_order.save && @payment_order.reload + @payment_order.save + @payment_order.reload end def back diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index 105f7d14f..ca41e8840 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -53,7 +53,7 @@ class BankTransaction < ApplicationRecord return end - payment_order = PaymentOrder.create_with_type(type: channel, invoice: invoice) + payment_order = PaymentOrder.new_with_type(type: channel, invoice: invoice) payment_order.save! if create_activity(registrar, invoice) diff --git a/app/models/payment_order.rb b/app/models/payment_order.rb index 3d788913b..4317abb38 100644 --- a/app/models/payment_order.rb +++ b/app/models/payment_order.rb @@ -32,7 +32,7 @@ class PaymentOrder < ApplicationRecord supported end - def self.create_with_type(type:, invoice:) + def self.new_with_type(type:, invoice:) channel = ('PaymentOrders::' + type.camelize).constantize PaymentOrder.new(type: channel, invoice: invoice) diff --git a/test/models/payment_orders_test.rb b/test/models/payment_orders_test.rb index 67267fec0..43996c6bc 100644 --- a/test/models/payment_orders_test.rb +++ b/test/models/payment_orders_test.rb @@ -44,34 +44,34 @@ class PaymentOrdersTest < ActiveSupport::TestCase end def test_correct_channel_is_assigned - everypay_channel = PaymentOrder.create_with_type(type: 'every_pay', invoice: @invoice) + everypay_channel = PaymentOrder.new_with_type(type: 'every_pay', invoice: @invoice) assert_equal everypay_channel.channel, 'EveryPay' assert_equal everypay_channel.class.config_namespace_name, 'every_pay' - swed_channel = PaymentOrder.create_with_type(type: 'swed', invoice: @invoice) + swed_channel = PaymentOrder.new_with_type(type: 'swed', invoice: @invoice) assert_equal swed_channel.channel, 'Swed' assert_equal swed_channel.class.config_namespace_name, 'swed' - seb_channel = PaymentOrder.create_with_type(type: 'seb', invoice: @invoice) + seb_channel = PaymentOrder.new_with_type(type: 'seb', invoice: @invoice) assert_equal seb_channel.channel, 'Seb' assert_equal seb_channel.class.config_namespace_name, 'seb' - lhv_channel = PaymentOrder.create_with_type(type: 'lhv', invoice: @invoice) + lhv_channel = PaymentOrder.new_with_type(type: 'lhv', invoice: @invoice) assert_equal lhv_channel.channel, 'Lhv' assert_equal lhv_channel.class.config_namespace_name, 'lhv' - admin_channel = PaymentOrder.create_with_type(type: 'admin_payment', invoice: @invoice) + admin_channel = PaymentOrder.new_with_type(type: 'admin_payment', invoice: @invoice) assert_equal admin_channel.channel, 'AdminPayment' assert_equal admin_channel.class.config_namespace_name, 'admin_payment' - system_channel = PaymentOrder.create_with_type(type: 'system_payment', invoice: @invoice) + system_channel = PaymentOrder.new_with_type(type: 'system_payment', invoice: @invoice) assert_equal system_channel.channel, 'SystemPayment' assert_equal system_channel.class.config_namespace_name, 'system_payment' end def test_can_not_create_order_for_paid_invoice invoice = invoices(:one) - payment_order = PaymentOrder.create_with_type(type: 'every_pay', invoice: invoice) + payment_order = PaymentOrder.new_with_type(type: 'every_pay', invoice: invoice) assert payment_order.invalid? assert_includes payment_order.errors[:invoice], 'is already paid' end @@ -84,7 +84,7 @@ class PaymentOrdersTest < ActiveSupport::TestCase def test_can_not_create_order_with_invalid_type assert_raise NameError do - PaymentOrder.create_with_type(type: 'not_implemented', invoice: Invoice.new) + PaymentOrder.new_with_type(type: 'not_implemented', invoice: Invoice.new) end end @@ -97,7 +97,7 @@ class PaymentOrdersTest < ActiveSupport::TestCase end def test_can_create_with_correct_subclass - payment = PaymentOrder.create_with_type(type: 'seb', invoice: Invoice.new) + payment = PaymentOrder.new_with_type(type: 'seb', invoice: Invoice.new) assert_equal PaymentOrders::Seb, payment.class end end