From 9f590ef58fad2b49e790d34dcabf689d5e42e8e4 Mon Sep 17 00:00:00 2001 From: Martin Seco Date: Wed, 5 Apr 2023 10:58:47 -0300 Subject: [PATCH] Api Updates * Add reference property to Financial Actions query * Add support for Forex (FX) rates API * Remove marketplace from HostedPayments & PaymentLinks --- .../financial/financial_actions_query.rb | 3 +++ lib/checkout_sdk/forex/forex.rb | 2 ++ lib/checkout_sdk/forex/forex_client.rb | 13 ++++++++--- lib/checkout_sdk/forex/forex_source.rb | 10 +++++++++ lib/checkout_sdk/forex/rates_query_filter.rb | 20 +++++++++++++++++ .../hosted/hosted_payments_session.rb | 4 ---- .../payments/links/payment_link.rb | 4 ---- .../forex/forex_integration_spec.rb | 22 +++++++++++++++++++ 8 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 lib/checkout_sdk/forex/forex_source.rb create mode 100644 lib/checkout_sdk/forex/rates_query_filter.rb diff --git a/lib/checkout_sdk/financial/financial_actions_query.rb b/lib/checkout_sdk/financial/financial_actions_query.rb index c243153..4844738 100644 --- a/lib/checkout_sdk/financial/financial_actions_query.rb +++ b/lib/checkout_sdk/financial/financial_actions_query.rb @@ -6,6 +6,8 @@ module Financial # @return [String] # @!attribute action_id # @return [String] + # @!attribute reference + # @return [String] # @!attribute limit # @return [Integer] # @!attribute pagination_token @@ -13,6 +15,7 @@ module Financial class FinancialActionsQuery attr_accessor :payment_id, :action_id, + :reference, :limit, :pagination_token end diff --git a/lib/checkout_sdk/forex/forex.rb b/lib/checkout_sdk/forex/forex.rb index cc7c056..789f6b0 100644 --- a/lib/checkout_sdk/forex/forex.rb +++ b/lib/checkout_sdk/forex/forex.rb @@ -1,4 +1,6 @@ # frozen_string_literal: true require 'checkout_sdk/forex/quote_request' +require 'checkout_sdk/forex/forex_source' +require 'checkout_sdk/forex/rates_query_filter' require 'checkout_sdk/forex/forex_client' diff --git a/lib/checkout_sdk/forex/forex_client.rb b/lib/checkout_sdk/forex/forex_client.rb index c0e0644..237ee25 100644 --- a/lib/checkout_sdk/forex/forex_client.rb +++ b/lib/checkout_sdk/forex/forex_client.rb @@ -3,8 +3,10 @@ module CheckoutSdk module Forex class ForexClient < Client - FOREX = 'forex/quotes' - private_constant :FOREX + FOREX = 'forex' + QUOTES = 'quotes' + RATES = 'rates' + private_constant :FOREX, :QUOTES, :RATES # @param [ApiClient] api_client # @param [CheckoutConfiguration] configuration @@ -14,7 +16,12 @@ def initialize(api_client, configuration) # @param [Hash, QuoteRequest] quote_request def request_quote(quote_request) - api_client.invoke_post(FOREX, sdk_authorization, quote_request) + api_client.invoke_post(build_path(FOREX, QUOTES), sdk_authorization, quote_request) + end + + # @param [Hash, RatesQueryFilter] rates_query_filter + def get_rates(rates_query_filter) + api_client.invoke_get(build_path(FOREX, RATES), sdk_authorization, rates_query_filter) end end end diff --git a/lib/checkout_sdk/forex/forex_source.rb b/lib/checkout_sdk/forex/forex_source.rb new file mode 100644 index 0000000..743ff9c --- /dev/null +++ b/lib/checkout_sdk/forex/forex_source.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module CheckoutSdk + module Forex + module ForexSource + VISA = 'visa' + MASTERCARD = 'mastercard' + end + end +end diff --git a/lib/checkout_sdk/forex/rates_query_filter.rb b/lib/checkout_sdk/forex/rates_query_filter.rb new file mode 100644 index 0000000..34d9c88 --- /dev/null +++ b/lib/checkout_sdk/forex/rates_query_filter.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module CheckoutSdk + module Forex + # @!attribute product + # @return [String] + # @!attribute source + # @return [String] {ForexSource} + # @!attribute currency_pairs + # @return [String] + # @!attribute process_channel_id + # @return [String] + class RatesQueryFilter + attr_accessor :product, + :source, + :currency_pairs, + :process_channel_id + end + end +end diff --git a/lib/checkout_sdk/payments/hosted/hosted_payments_session.rb b/lib/checkout_sdk/payments/hosted/hosted_payments_session.rb index 57a9dd8..ff19347 100644 --- a/lib/checkout_sdk/payments/hosted/hosted_payments_session.rb +++ b/lib/checkout_sdk/payments/hosted/hosted_payments_session.rb @@ -50,9 +50,6 @@ module Payments # @return [Time] # @!attribute processing_channel_id # @return [String] - Not available on Previous. - # @!attribute marketplace - # @deprecated Please use {#amount_allocations} instead - # @return [CheckoutSdk::Common::MarketplaceData] - Not available on Previous. # @!attribute amount_allocations # @return [Array(CheckoutSdk::Common::AmountAllocations)] - Not available on Previous. class HostedPaymentsSession @@ -80,7 +77,6 @@ class HostedPaymentsSession :capture, :capture_on, :processing_channel_id, - :marketplace, :amount_allocations end end diff --git a/lib/checkout_sdk/payments/links/payment_link.rb b/lib/checkout_sdk/payments/links/payment_link.rb index a1e5ffd..8ac9127 100644 --- a/lib/checkout_sdk/payments/links/payment_link.rb +++ b/lib/checkout_sdk/payments/links/payment_link.rb @@ -18,9 +18,6 @@ module Payments # @return [String] # @!attribute processing_channel_id # @return [String] - Not available on Previous. - # @!attribute marketplace - # @deprecated Please use {#amount_allocations} instead - # @return [CheckoutSdk::Common::MarketplaceData] - Not available on Previous. # @!attribute amount_allocations # @return [Array(CheckoutSdk::Common::AmountAllocations)] - Not available on Previous. # @!attribute expires_in @@ -62,7 +59,6 @@ class PaymentLink :reference, :description, :processing_channel_id, - :marketplace, :amount_allocations, :expires_in, :customer, diff --git a/spec/checkout_sdk/forex/forex_integration_spec.rb b/spec/checkout_sdk/forex/forex_integration_spec.rb index fc87250..1a1aef6 100644 --- a/spec/checkout_sdk/forex/forex_integration_spec.rb +++ b/spec/checkout_sdk/forex/forex_integration_spec.rb @@ -20,4 +20,26 @@ end end end + + skip 'Skipping because processing_channel_id is invalid' do + describe '.get_rates' do + context 'when fetching rates with valid parameters' do + it 'retrieves valid rates' do + query = CheckoutSdk::Forex::RatesQueryFilter.new + query.product = 'card_payouts' + query.source = CheckoutSdk::Forex::ForexSource::VISA + query.currency_pairs = 'GBPEUR,USDNOK,JPNCAD' + query.process_channel_id = 'pc_abcdefghijklmnopqrstuvwxyz' + + response = oauth_sdk.forex.get_rates(query) + + assert_response response, %w[product + source + rates] + expect(response.product).to eq query.product + expect(response.source).to eq query.source + end + end + end + end end