Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/ioki/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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') ||
Expand All @@ -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')
Expand Down
9 changes: 9 additions & 0 deletions lib/ioki/model/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions lib/ioki/model/operator/payment_service_provider/logpay.rb
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions lib/ioki/model/operator/payment_service_provider/stripe.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions lib/ioki/model/operator/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lib/ioki/model/passenger/payment_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
23 changes: 23 additions & 0 deletions lib/ioki/model/passenger/payment_service_provider/logpay.rb
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions lib/ioki/model/passenger/payment_service_provider/stripe.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions lib/ioki/model/passenger/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions lib/ioki/model/platform/payment_service_provider/logpay.rb
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions lib/ioki/model/platform/payment_service_provider/stripe.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions lib/ioki/model/platform/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions spec/ioki/model/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down