diff --git a/lib/ioki/apis/passenger_api.rb b/lib/ioki/apis/passenger_api.rb index a7186fa1..64019b8e 100644 --- a/lib/ioki/apis/passenger_api.rb +++ b/lib/ioki/apis/passenger_api.rb @@ -290,6 +290,26 @@ class PassengerApi base_path: [API_BASE_PATH, 'geocoding', 'session', :id], path: 'details', model_class: Ioki::Model::Passenger::GeocodingSearchDetails + ), + Endpoints.crud_endpoints( + :purchase, + base_path: [API_BASE_PATH], + model_class: Ioki::Model::Passenger::Purchase, + only: [:index, :show] + ), + Endpoints::UpdateSingular.new( + :reserve_debit, + path: 'reserve_debit', + base_path: [API_BASE_PATH, 'purchases', :id], + model_class: Ioki::Model::Passenger::Purchase, + outgoing_model_class: Ioki::Model::Passenger::ReserveDebit + ), + Endpoints::UpdateSingular.new( + :settle_debit, + path: 'settle_debit', + base_path: [API_BASE_PATH, 'purchases', :id], + model_class: Ioki::Model::Passenger::Purchase, + outgoing_model_class: Ioki::Model::Passenger::SettleDebit ) ].freeze end diff --git a/lib/ioki/model/passenger/booking.rb b/lib/ioki/model/passenger/booking.rb index f887f01f..d36bcf06 100644 --- a/lib/ioki/model/passenger/booking.rb +++ b/lib/ioki/model/passenger/booking.rb @@ -41,6 +41,8 @@ class Booking < Base omit_if_nil_on: :create attribute :paypal_secure_element, type: :string, on: :create, omit_if_nil_on: :create + attribute :on_session, on: :create, type: :boolean, omit_if_nil_on: :create + attribute :async, on: :create, type: :boolean, omit_if_nil_on: :create end end end diff --git a/lib/ioki/model/passenger/invoice.rb b/lib/ioki/model/passenger/invoice.rb new file mode 100644 index 00000000..25e96d4a --- /dev/null +++ b/lib/ioki/model/passenger/invoice.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Passenger + class Invoice < Base + attribute :type, + on: :read, + type: :string + + attribute :id, + on: :read, + type: :string + + attribute :created_at, + on: :read, + type: :date_time + + attribute :updated_at, + on: :read, + type: :date_time + + attribute :attachment_url, + on: :read, + type: :string + + attribute :user_id, + on: :read, + type: :string + + attribute :purchase_id, + on: :read, + type: :string + end + end + end +end diff --git a/lib/ioki/model/passenger/nested_charge.rb b/lib/ioki/model/passenger/nested_charge.rb new file mode 100644 index 00000000..65725a87 --- /dev/null +++ b/lib/ioki/model/passenger/nested_charge.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Passenger + class NestedCharge < Base + attribute :type, + on: :read, + type: :string + + attribute :id, + on: :read, + type: :string + + attribute :created_at, + on: :read, + type: :date_time + + attribute :updated_at, + on: :read, + type: :date_time + + attribute :amount, + on: :read, + type: :object, + class_name: 'Money' + + attribute :charge_type, + on: :read, + type: :string + + attribute :payment_charge_id, + on: :read, + type: :string + + attribute :payment_method, + on: :read, + type: :object, + class_name: 'PaymentMethod' + + attribute :pending_action, + on: :read, + type: :object, + class_name: 'Payment::ChargeChallenge' + + attribute :purchase_ids, + on: :read, + type: :array + + attribute :receipt, + on: :read, + type: :object, + class_name: 'Receipt' + + attribute :reservation, + on: :read, + type: :boolean + + attribute :state, + on: :read, + type: :string + + attribute :user_id, + on: :read, + type: :string + end + end + end +end diff --git a/lib/ioki/model/passenger/nested_charge_split.rb b/lib/ioki/model/passenger/nested_charge_split.rb new file mode 100644 index 00000000..6eace158 --- /dev/null +++ b/lib/ioki/model/passenger/nested_charge_split.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Passenger + class NestedChargeSplit < Base + attribute :amount, + on: :read, + type: :object, + class_name: 'Money' + + attribute :purchase_id, + on: :read, + type: :string + + attribute :charge, + on: :read, + type: :object, + class_name: 'NestedCharge' + end + end + end +end diff --git a/lib/ioki/model/passenger/payment/charge_challenge.rb b/lib/ioki/model/passenger/payment/charge_challenge.rb new file mode 100644 index 00000000..738412e3 --- /dev/null +++ b/lib/ioki/model/passenger/payment/charge_challenge.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Passenger + module Payment + class ChargeChallenge < Base + attribute :type, + on: :read, + type: :string + + attribute :action, + on: :read, + type: :object, + class_name: ['OpenUrl'] + end + end + end + end +end diff --git a/lib/ioki/model/passenger/payment/open_url.rb b/lib/ioki/model/passenger/payment/open_url.rb new file mode 100644 index 00000000..8198b01a --- /dev/null +++ b/lib/ioki/model/passenger/payment/open_url.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Passenger + module Payment + class OpenUrl < Base + attribute :type, + on: :read, + type: :string + + attribute :url, + on: :read, + type: :string + end + end + end + end +end diff --git a/lib/ioki/model/passenger/payment_method.rb b/lib/ioki/model/passenger/payment_method.rb index ede1e327..f437517f 100644 --- a/lib/ioki/model/passenger/payment_method.rb +++ b/lib/ioki/model/passenger/payment_method.rb @@ -5,10 +5,10 @@ module Model module Passenger class PaymentMethod < Base attribute :type, on: :read, type: :string - attribute :id, on: [:read, :create], type: :string, omit_if_blank_on: :create + attribute :id, on: [:read, :create, :update], type: :string, omit_if_blank_on: :create 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 :payment_method_type, on: [:create, :update], 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/personal_discount.rb b/lib/ioki/model/passenger/personal_discount.rb index 00103ea2..5651b9d3 100644 --- a/lib/ioki/model/passenger/personal_discount.rb +++ b/lib/ioki/model/passenger/personal_discount.rb @@ -27,6 +27,8 @@ class PersonalDiscount < Base attribute :personal_discount_type_id, on: :create, type: :string attribute :paypal_secure_element, on: :create, type: :string, omit_if_nil_on: :create + attribute :on_session, on: :create, type: :boolean, omit_if_nil_on: :create + attribute :async, on: :create, type: :boolean, omit_if_nil_on: :create end end end diff --git a/lib/ioki/model/passenger/purchase.rb b/lib/ioki/model/passenger/purchase.rb new file mode 100644 index 00000000..0c1383d5 --- /dev/null +++ b/lib/ioki/model/passenger/purchase.rb @@ -0,0 +1,120 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Passenger + class Purchase < Base + attribute :type, + on: :read, + type: :string + + attribute :id, + on: :read, + type: :string + + attribute :created_at, + on: :read, + type: :date_time + + attribute :updated_at, + on: :read, + type: :date_time + + attribute :amount, + on: :read, + type: :object, + class_name: 'Money' + + attribute :purchase_type, + on: :read, + type: :string + + attribute :charge_splits, + on: :read, + type: :array, + force_type: true, + class_name: 'NestedChargeSplit' + + attribute :claimable_at, + on: :read, + type: :date_time + + attribute :creator_type, + on: :read, + type: :string + + attribute :creator_id, + on: :read, + type: :string + + attribute :debit_purchase_id, + on: :read, + type: :string + + attribute :forfeited_at, + on: :read, + type: :date_time + + attribute :gifted_amount, + on: :read, + type: :object, + class_name: 'Money' + + attribute :invoices, + on: :read, + type: :array, + class_name: 'Invoice' + + attribute :invoice, + on: :read, + type: :object, + class_name: 'Invoice' + + attribute :payment_action, + on: :read, + type: :string + + attribute :payment_method, + on: :read, + type: :object, + class_name: 'PaymentMethod' + + attribute :purchasable_description, + on: :read, + type: :string + + attribute :purchasable_title, + on: :read, + type: :string + + attribute :purchasable_id, + on: :read, + type: :string + + attribute :purchasable_type, + on: :read, + type: :string + + attribute :ride_id, + on: :read, + type: :string + + attribute :reason, + on: :read, + type: :string + + attribute :state, + on: :read, + type: :string + + attribute :succeeded_at, + on: :read, + type: :date_time + + attribute :user_id, + on: :read, + type: :string + end + end + end +end diff --git a/lib/ioki/model/passenger/receipt.rb b/lib/ioki/model/passenger/receipt.rb index b7c560a4..dd38ecd7 100644 --- a/lib/ioki/model/passenger/receipt.rb +++ b/lib/ioki/model/passenger/receipt.rb @@ -10,6 +10,7 @@ class Receipt < Base attribute :updated_at, on: :read, type: :date_time attribute :attachment_url, on: :read, type: :string attribute :receipt_type, on: :read, type: :string + attribute :charge_id, on: :read, type: :string end end end diff --git a/lib/ioki/model/passenger/reserve_debit.rb b/lib/ioki/model/passenger/reserve_debit.rb new file mode 100644 index 00000000..a3d2cdec --- /dev/null +++ b/lib/ioki/model/passenger/reserve_debit.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Passenger + class ReserveDebit < Base + attribute :paypal_secure_element, + on: :update, + type: :string + end + end + end +end diff --git a/lib/ioki/model/passenger/service_credit_create.rb b/lib/ioki/model/passenger/service_credit_create.rb index 78be3b6a..02a1efdb 100644 --- a/lib/ioki/model/passenger/service_credit_create.rb +++ b/lib/ioki/model/passenger/service_credit_create.rb @@ -12,6 +12,8 @@ def self.schema_path attribute :value, type: :integer, on: :create attribute :payment_method, type: :object, on: :create, class_name: 'PaymentMethod' attribute :paypal_secure_element, type: :string, on: :create, omit_if_nil_on: :create + attribute :on_session, on: :create, type: :boolean, omit_if_nil_on: :create + attribute :async, on: :create, type: :boolean, omit_if_nil_on: :create end end end diff --git a/lib/ioki/model/passenger/settle_debit.rb b/lib/ioki/model/passenger/settle_debit.rb new file mode 100644 index 00000000..64cf8285 --- /dev/null +++ b/lib/ioki/model/passenger/settle_debit.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Passenger + class SettleDebit < Base + attribute :payment_method, + on: :update, + type: :object, + class_name: 'PaymentMethod' + + attribute :paypal_secure_element, + on: :update, + type: :string + end + end + end +end diff --git a/lib/ioki/model/passenger/ticketing/product_purchase.rb b/lib/ioki/model/passenger/ticketing/product_purchase.rb index 3d387b6e..02f7a342 100644 --- a/lib/ioki/model/passenger/ticketing/product_purchase.rb +++ b/lib/ioki/model/passenger/ticketing/product_purchase.rb @@ -13,6 +13,8 @@ def self.schema_path attribute :ride_id, on: :create, type: :string attribute :payment_method, on: :create, type: :object, class_name: 'Ioki::Model::Passenger::PaymentMethod' attribute :paypal_secure_element, on: :create, type: :string + attribute :on_session, on: :create, type: :boolean, omit_if_nil_on: :create + attribute :async, on: :create, type: :boolean, omit_if_nil_on: :create end end end diff --git a/lib/ioki/model/passenger/ticketing/voucher_renewal.rb b/lib/ioki/model/passenger/ticketing/voucher_renewal.rb index 98142d0f..028aef59 100644 --- a/lib/ioki/model/passenger/ticketing/voucher_renewal.rb +++ b/lib/ioki/model/passenger/ticketing/voucher_renewal.rb @@ -11,6 +11,8 @@ def self.schema_path attribute :payment_method, on: :create, type: :object, class_name: 'Ioki::Model::Passenger::PaymentMethod' attribute :paypal_secure_element, on: :create, type: :string + attribute :on_session, on: :create, type: :boolean, omit_if_nil_on: :create + attribute :async, on: :create, type: :boolean, omit_if_nil_on: :create end end end diff --git a/lib/ioki/model/passenger/tip_create.rb b/lib/ioki/model/passenger/tip_create.rb index f35deac9..9c9c6ef7 100644 --- a/lib/ioki/model/passenger/tip_create.rb +++ b/lib/ioki/model/passenger/tip_create.rb @@ -10,6 +10,8 @@ def self.schema_path attribute :amount, on: :create, type: :integer attribute :payment_method, on: :create, type: :object, class_name: 'PaymentMethod' + attribute :on_session, on: :create, type: :boolean, omit_if_nil_on: :create + attribute :async, on: :create, type: :boolean, omit_if_nil_on: :create end end end diff --git a/spec/ioki/passenger_api_spec.rb b/spec/ioki/passenger_api_spec.rb index 8e853f07..80d3e562 100644 --- a/spec/ioki/passenger_api_spec.rb +++ b/spec/ioki/passenger_api_spec.rb @@ -695,4 +695,69 @@ .to be_a(Ioki::Model::Passenger::GeocodingSearchDetails) end end + + describe '#purchases' do + it 'calls request on the client with expected params' do + expect(passenger_client).to receive(:request) do |params| + expect(params[:url].to_s).to eq('passenger/purchases') + result_with_index_data + end + + expect(passenger_client.purchases(options)).to all(be_a(Ioki::Model::Passenger::Purchase)) + end + end + + describe '#purchase' do + it 'calls request on the client with expected params' do + expect(passenger_client).to receive(:request) do |params| + expect(params[:url].to_s).to eq('passenger/purchases/0815') + [result_with_data, full_response] + end + expect(passenger_client.purchase('0815', options)).to be_a Ioki::Model::Passenger::Purchase + end + end + + describe '#reserve_debit' do + let(:reserve_debit) { Ioki::Model::Passenger::ReserveDebit.new(paypal_secure_element: 'secret') } + + it 'calls request on the client with expected params' do + expect(passenger_client).to receive(:request) do |params| + expect(params[:url].to_s).to eq('passenger/purchases/0815/reserve_debit') + expect(params[:body][:data]).to match(hash_including(paypal_secure_element: 'secret')) + [result_with_data, full_response] + end + + expect(passenger_client.update_reserve_debit('0815', reserve_debit, options)).to be_a Ioki::Model::Passenger::Purchase + end + end + + describe '#settle_debit' do + let(:settle_debit) do + Ioki::Model::Passenger::SettleDebit.new( + payment_method: Ioki::Model::Passenger::PaymentMethod.new( + payment_method_type: 'service_credits', + id: 'pam_1' + ), + paypal_secure_element: 'secret' + ) + end + + it 'calls request on the client with expected params' do + expect(passenger_client).to receive(:request) do |params| + expect(params[:url].to_s).to eq('passenger/purchases/0815/settle_debit') + expect(params[:body][:data]).to match( + hash_including( + payment_method: hash_including( + payment_method_type: 'service_credits', + id: 'pam_1' + ), + paypal_secure_element: 'secret' + ) + ) + [result_with_data, full_response] + end + + expect(passenger_client.update_settle_debit('0815', settle_debit, options)).to be_a Ioki::Model::Passenger::Purchase + end + end end