diff --git a/lib/ioki/model.rb b/lib/ioki/model.rb index 94bcb61e..928807c0 100644 --- a/lib/ioki/model.rb +++ b/lib/ioki/model.rb @@ -7,8 +7,9 @@ require 'ioki/model/platform/base' require 'ioki/model/webhooks/base' -Dir[File.join(__dir__, 'model', 'platform', '*')].reject do |filename| - filename == File.join(__dir__, 'model', 'platform', 'base.rb') +Dir[File.join(__dir__, 'model', 'platform', '**', '*')].reject do |filename| + filename == File.join(__dir__, 'model', 'platform', 'base.rb') || + !File.file?(filename) end.sort.each { |file| require file } Dir[File.join(__dir__, 'model', 'passenger', '**', '*')].reject do |filename| filename == File.join(__dir__, 'model', 'passenger', 'base.rb') || @@ -18,7 +19,8 @@ filename == File.join(__dir__, 'model', 'driver', 'base.rb') end.sort.each { |file| require file } Dir[File.join(__dir__, 'model', 'operator', '**', '*')].reject do |filename| - filename == File.join(__dir__, 'model', 'operator', 'base.rb') || File.directory?(filename) + filename == File.join(__dir__, 'model', 'operator', 'base.rb') || + !File.file?(filename) end.sort.each { |file| require file } Dir[File.join(__dir__, 'model', 'webhooks', '*')].reject do |filename| filename == File.join(__dir__, 'model', 'webhooks', 'base.rb') diff --git a/lib/ioki/model/base.rb b/lib/ioki/model/base.rb index b1cdc735..1834556f 100644 --- a/lib/ioki/model/base.rb +++ b/lib/ioki/model/base.rb @@ -257,6 +257,15 @@ def class_name_from_value_type(class_name, value) return class_name_from_value_type if class_name.include?(class_name_from_value_type) + # The above behavior only considers the last part of the type (split by + # `/`). To keep backwards compatibility, the following implementation + # using the whole type (to support deeply nested models) is added as a + # fallback only. + type_string = value_type(value) + class_name_from_value_type = Support.camelize(type_string) + + return class_name_from_value_type if class_name.include?(class_name_from_value_type) + nil end diff --git a/lib/ioki/model/operator/payment_service_provider/logpay.rb b/lib/ioki/model/operator/payment_service_provider/logpay.rb new file mode 100644 index 00000000..68c037bd --- /dev/null +++ b/lib/ioki/model/operator/payment_service_provider/logpay.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Operator + module PaymentServiceProvider + class Logpay < Base + attribute :type, + on: :read, + type: :string + + attribute :logpay_payment_method_types, + on: :read, + type: :array + end + end + end + end +end diff --git a/lib/ioki/model/operator/payment_service_provider/stripe.rb b/lib/ioki/model/operator/payment_service_provider/stripe.rb new file mode 100644 index 00000000..d1d48556 --- /dev/null +++ b/lib/ioki/model/operator/payment_service_provider/stripe.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Operator + module PaymentServiceProvider + class Stripe < Base + attribute :type, + on: :read, + type: :string + + attribute :google_pay_supported, + on: :read, + type: :boolean + + attribute :stripe_payment_method_types, + on: :read, + type: :array + end + end + end + end +end diff --git a/lib/ioki/model/operator/provider.rb b/lib/ioki/model/operator/provider.rb index 80202b70..18f000b5 100644 --- a/lib/ioki/model/operator/provider.rb +++ b/lib/ioki/model/operator/provider.rb @@ -66,6 +66,14 @@ class Provider < Base on: :read, type: :string + attribute :payment_service_provider, + on: :read, + type: :object, + class_name: [ + 'PaymentServiceProvider::Stripe', + 'PaymentServiceProvider::Logpay' + ] + attribute :products, on: :read, type: :array, diff --git a/lib/ioki/model/passenger/payment_method.rb b/lib/ioki/model/passenger/payment_method.rb index 9710ff6d..ede1e327 100644 --- a/lib/ioki/model/passenger/payment_method.rb +++ b/lib/ioki/model/passenger/payment_method.rb @@ -9,6 +9,7 @@ class PaymentMethod < Base attribute :created_at, on: :read, type: :date_time attribute :updated_at, on: :read, type: :date_time attribute :payment_method_type, on: :create, type: :string + attribute :requires_paypal_secure_element, on: :read, type: :boolean attribute :attached, on: :read, type: :boolean attribute :summary, on: :read, type: :object, class_name: 'PaymentMethodSummary' diff --git a/lib/ioki/model/passenger/payment_service_provider/logpay.rb b/lib/ioki/model/passenger/payment_service_provider/logpay.rb new file mode 100644 index 00000000..ffa81092 --- /dev/null +++ b/lib/ioki/model/passenger/payment_service_provider/logpay.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Passenger + module PaymentServiceProvider + class Logpay < Base + attribute :type, + on: :read, + type: :string + + attribute :logpay_payment_method_types, + on: :read, + type: :array + + attribute :use_legacy_paypal_flow, + on: :read, + type: :boolean + end + end + end + end +end diff --git a/lib/ioki/model/passenger/payment_service_provider/stripe.rb b/lib/ioki/model/passenger/payment_service_provider/stripe.rb new file mode 100644 index 00000000..fd4519ba --- /dev/null +++ b/lib/ioki/model/passenger/payment_service_provider/stripe.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Passenger + module PaymentServiceProvider + class Stripe < Base + attribute :type, + on: :read, + type: :string + + attribute :google_pay_supported, + on: :read, + type: :boolean + + attribute :stripe_account_id, + on: :read, + type: :string + + attribute :stripe_payment_method_types, + on: :read, + type: :array + end + end + end + end +end diff --git a/lib/ioki/model/passenger/provider.rb b/lib/ioki/model/passenger/provider.rb index ac1d3e9e..ec8e0219 100644 --- a/lib/ioki/model/passenger/provider.rb +++ b/lib/ioki/model/passenger/provider.rb @@ -20,6 +20,13 @@ class Provider < Base attribute :name, on: :read, type: :string attribute :personal_discount_payment_method_types, on: :read, type: :array attribute :postal_code, on: :read, type: :string + attribute :payment_service_provider, + on: :read, + type: :object, + class_name: [ + 'PaymentServiceProvider::Stripe', + 'PaymentServiceProvider::Logpay' + ] attribute :psp, on: :read, type: :string attribute :retry_payment_method_types, on: :read, type: :array deprecated_attribute :ride_payment_method_types, on: :read, type: :array diff --git a/lib/ioki/model/platform/payment_service_provider/logpay.rb b/lib/ioki/model/platform/payment_service_provider/logpay.rb new file mode 100644 index 00000000..6d5a952e --- /dev/null +++ b/lib/ioki/model/platform/payment_service_provider/logpay.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Platform + module PaymentServiceProvider + class Logpay < Base + attribute :type, + on: :read, + type: :string + + attribute :logpay_payment_method_types, + on: :read, + type: :array + + attribute :use_legacy_paypal_flow, + on: :read, + type: :boolean + end + end + end + end +end diff --git a/lib/ioki/model/platform/payment_service_provider/stripe.rb b/lib/ioki/model/platform/payment_service_provider/stripe.rb new file mode 100644 index 00000000..b6f93943 --- /dev/null +++ b/lib/ioki/model/platform/payment_service_provider/stripe.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Platform + module PaymentServiceProvider + class Stripe < Base + attribute :type, + on: :read, + type: :string + + attribute :google_pay_supported, + on: :read, + type: :boolean + + attribute :stripe_account_id, + on: :read, + type: :string + + attribute :stripe_payment_method_types, + on: :read, + type: :array + end + end + end + end +end diff --git a/lib/ioki/model/platform/provider.rb b/lib/ioki/model/platform/provider.rb index 344e5185..665fec31 100644 --- a/lib/ioki/model/platform/provider.rb +++ b/lib/ioki/model/platform/provider.rb @@ -76,6 +76,14 @@ class Provider < Base on: :read, type: :string + attribute :payment_service_provider, + on: :read, + type: :object, + class_name: [ + 'PaymentServiceProvider::Stripe', + 'PaymentServiceProvider::Logpay' + ] + attribute :privacy_policy_url, on: :read, type: :string diff --git a/spec/ioki/model/base_spec.rb b/spec/ioki/model/base_spec.rb index 9b209e80..0b3b5f67 100644 --- a/spec/ioki/model/base_spec.rb +++ b/spec/ioki/model/base_spec.rb @@ -156,6 +156,41 @@ end end + describe 'for an attribute of type :object with nested class_name' do + let(:example_referenced_class) do + Class.new(Ioki::Model::Base) do + attribute :bar, type: :integer, on: :read + end + end + let(:example_other_class) do + Class.new(Ioki::Model::Base) do + attribute :bar, type: :integer, on: :read + end + end + + let(:example_class) do + Class.new(Ioki::Model::Base) do + attribute :foo, type: :object, class_name: ['Example::ReferencedClass', 'Example::OtherClass'], on: :read + end + end + + before do + stub_const('Ioki::Model::Example::ReferencedClass', example_referenced_class) + stub_const('Ioki::Model::Example::OtherClass', example_other_class) + stub_const('Ioki::Model::ExampleObjectClassName', example_class) + end + + it 'parses the class correctly' do + model = example_class.new({ foo: { type: 'example/referenced_class', bar: 42 } }) + expect(model.foo).to be_a(example_referenced_class) + expect(model.foo.bar).to eq(42) + + model = example_class.new({ foo: { type: 'example/other_class', bar: 42 } }) + expect(model.foo).to be_a(example_other_class) + expect(model.foo.bar).to eq(42) + end + end + describe 'for an attribute of type :array with a class_name' do let(:example_referenced_class) do Class.new(Ioki::Model::Base) do