diff --git a/lib/checkout_sdk/accounts/accounts.rb b/lib/checkout_sdk/accounts/accounts.rb index 795113d..7bf5d6f 100644 --- a/lib/checkout_sdk/accounts/accounts.rb +++ b/lib/checkout_sdk/accounts/accounts.rb @@ -31,6 +31,8 @@ require 'checkout_sdk/accounts/instrument_details' require 'checkout_sdk/accounts/instrument_details_faster_payments' require 'checkout_sdk/accounts/instrument_details_sepa' +require 'checkout_sdk/accounts/instrument_details_card_token' require 'checkout_sdk/accounts/payment_instrument_request' require 'checkout_sdk/accounts/payment_instruments_query' +require 'checkout_sdk/accounts/headers' require 'checkout_sdk/accounts/update_payment_instrument_request' diff --git a/lib/checkout_sdk/accounts/headers.rb b/lib/checkout_sdk/accounts/headers.rb new file mode 100644 index 0000000..ae549fd --- /dev/null +++ b/lib/checkout_sdk/accounts/headers.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module CheckoutSdk + module Accounts + # @!attribute if_match + # @return [String] + class Headers + attr_accessor :if_match + end + end +end diff --git a/lib/checkout_sdk/accounts/instrument_details_card_token.rb b/lib/checkout_sdk/accounts/instrument_details_card_token.rb new file mode 100644 index 0000000..4adce65 --- /dev/null +++ b/lib/checkout_sdk/accounts/instrument_details_card_token.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module CheckoutSdk + module Accounts + # @!attribute token + # @return [String] + class InstrumentDetailsCardToken < InstrumentDetails + attr_accessor :token + end + end +end diff --git a/lib/checkout_sdk/accounts/payment_instrument_request.rb b/lib/checkout_sdk/accounts/payment_instrument_request.rb index ebfc8b8..c4c519f 100644 --- a/lib/checkout_sdk/accounts/payment_instrument_request.rb +++ b/lib/checkout_sdk/accounts/payment_instrument_request.rb @@ -24,10 +24,6 @@ class PaymentInstrumentRequest :default, :document, :instrument_details - - def initialize - @type = CheckoutSdk::Common::InstrumentType::BANK_ACCOUNT - end end end end diff --git a/lib/checkout_sdk/accounts/update_payment_instrument_request.rb b/lib/checkout_sdk/accounts/update_payment_instrument_request.rb index 3272f60..3c8b3ae 100644 --- a/lib/checkout_sdk/accounts/update_payment_instrument_request.rb +++ b/lib/checkout_sdk/accounts/update_payment_instrument_request.rb @@ -6,9 +6,12 @@ module Accounts # @return [String] # @!attribute default # @return [TrueClass, FalseClass] + # @!attribute headers + # @return [Headers] class UpdatePaymentInstrumentRequest attr_accessor :label, - :default + :default, + :headers end end end diff --git a/lib/checkout_sdk/common/instrument_type.rb b/lib/checkout_sdk/common/instrument_type.rb index 216e260..d926ede 100644 --- a/lib/checkout_sdk/common/instrument_type.rb +++ b/lib/checkout_sdk/common/instrument_type.rb @@ -6,6 +6,7 @@ module InstrumentType BANK_ACCOUNT = 'bank_account' TOKEN = 'token' CARD = 'card' + CARD_TOKEN = 'card_token' end end end diff --git a/lib/checkout_sdk/json_serializer.rb b/lib/checkout_sdk/json_serializer.rb index 83dd6ec..d34b2d6 100644 --- a/lib/checkout_sdk/json_serializer.rb +++ b/lib/checkout_sdk/json_serializer.rb @@ -5,7 +5,8 @@ class JsonSerializer KEYS_TRANSFORMATIONS = { three_ds: '3ds', account_holder_type: 'account-holder-type', payment_network: 'payment-network', - from_: 'from' }.freeze + from_: 'from', + if_match: 'if-match' }.freeze def self.to_custom_hash(object) hash = {} diff --git a/spec/checkout_sdk/accounts/accounts_integration_spec.rb b/spec/checkout_sdk/accounts/accounts_integration_spec.rb index cd1cb0e..7caca10 100644 --- a/spec/checkout_sdk/accounts/accounts_integration_spec.rb +++ b/spec/checkout_sdk/accounts/accounts_integration_spec.rb @@ -227,6 +227,7 @@ def build_payment_instrument(file) request = CheckoutSdk::Accounts::PaymentInstrumentRequest.new request.label = 'Barclays' + request.type = CheckoutSdk::Common::InstrumentType::BANK_ACCOUNT request.currency = CheckoutSdk::Common::Currency::GBP request.country = CheckoutSdk::Common::Country::GB request.default = false diff --git a/spec/checkout_sdk/payments/hosted/hosted_payments_integration_spec.rb b/spec/checkout_sdk/payments/hosted/hosted_payments_integration_spec.rb index a6322e7..373f930 100644 --- a/spec/checkout_sdk/payments/hosted/hosted_payments_integration_spec.rb +++ b/spec/checkout_sdk/payments/hosted/hosted_payments_integration_spec.rb @@ -58,7 +58,7 @@ def create_hosted_payments_request product = CheckoutSdk::Common::Product.new product.name = 'Gold Necklace' product.quantity = 1 - product.price = 10 + product.price = 1000 three_ds_request = CheckoutSdk::Payments::ThreeDSRequest.new three_ds_request.enabled = true diff --git a/spec/checkout_sdk/payments/hosted/previous/hosted_payments_integration_spec.rb b/spec/checkout_sdk/payments/hosted/previous/hosted_payments_integration_spec.rb index 1e3ef7f..cdda236 100644 --- a/spec/checkout_sdk/payments/hosted/previous/hosted_payments_integration_spec.rb +++ b/spec/checkout_sdk/payments/hosted/previous/hosted_payments_integration_spec.rb @@ -60,7 +60,7 @@ def create_hosted_payments_request product = CheckoutSdk::Common::Product.new product.name = 'Gold Necklace' product.quantity = 1 - product.price = 10 + product.price = 1000 three_ds_request = CheckoutSdk::Payments::ThreeDSRequest.new three_ds_request.enabled = true diff --git a/spec/checkout_sdk/payments/links/payment_links_integration_spec.rb b/spec/checkout_sdk/payments/links/payment_links_integration_spec.rb index 9005c70..8b254dc 100644 --- a/spec/checkout_sdk/payments/links/payment_links_integration_spec.rb +++ b/spec/checkout_sdk/payments/links/payment_links_integration_spec.rb @@ -59,7 +59,7 @@ def create_payment_links_request product = CheckoutSdk::Common::Product.new product.name = 'Gold Necklace' product.quantity = 1 - product.price = 10 + product.price = 200 three_ds_request = CheckoutSdk::Payments::ThreeDSRequest.new three_ds_request.enabled = true diff --git a/spec/checkout_sdk/payments/links/previous/payment_links_integrattion_spec.rb b/spec/checkout_sdk/payments/links/previous/payment_links_integrattion_spec.rb index 5b62033..8e125d2 100644 --- a/spec/checkout_sdk/payments/links/previous/payment_links_integrattion_spec.rb +++ b/spec/checkout_sdk/payments/links/previous/payment_links_integrattion_spec.rb @@ -61,7 +61,7 @@ def create_payment_links_request product = CheckoutSdk::Common::Product.new product.name = 'Gold Necklace' product.quantity = 1 - product.price = 10 + product.price = 200 three_ds_request = CheckoutSdk::Payments::ThreeDSRequest.new three_ds_request.enabled = true diff --git a/spec/checkout_sdk/transfers/transfers_integration_spec.rb b/spec/checkout_sdk/transfers/transfers_integration_spec.rb index 88ba5ec..7127b93 100644 --- a/spec/checkout_sdk/transfers/transfers_integration_spec.rb +++ b/spec/checkout_sdk/transfers/transfers_integration_spec.rb @@ -1,24 +1,28 @@ +require 'securerandom' + RSpec.describe CheckoutSdk::Transfers do describe '.initiate_transfer_of_funds' do context 'when requesting transfer of funds' do - it 'should initiates transfer of funds' do + it 'should fail when requesting idempotent transfer' do request = create_transfer - response = oauth_sdk.transfers.initiate_transfer_of_funds(request) + + idempotency_key = SecureRandom.uuid + + response = oauth_sdk.transfers.initiate_transfer_of_funds(request, idempotency_key) + expect(response).not_to be_nil expect(response.status).to eq('pending') + end - it 'should fail when requesting idempotent transfer' do + it 'should fail when initiating transfer of funds without idempotency key' do request = create_transfer - response = oauth_sdk.transfers.initiate_transfer_of_funds(request) - expect(response).not_to be_nil - expect(response.status).to eq('pending') - idempotency_key = '795900f2-aadd-476c-9093-df65c99bf37a' - expect { oauth_sdk.transfers.initiate_transfer_of_funds(request, idempotency_key) } - .to raise_error(CheckoutSdk::CheckoutApiException) { |e| expect(e.http_metadata.status_code).to eq 409 } + expect { oauth_sdk.transfers.initiate_transfer_of_funds(request) } + .to raise_error(CheckoutSdk::CheckoutApiException) { |e| expect(e.http_metadata.status_code).to eq 422 } end + end end @@ -26,7 +30,7 @@ context 'when fetching a transfer of funds' do it 'should successfully retrieve transfer information' do request = create_transfer - create_response = oauth_sdk.transfers.initiate_transfer_of_funds(request) + create_response = oauth_sdk.transfers.initiate_transfer_of_funds(request, SecureRandom.uuid) retrieve_response = oauth_sdk.transfers.retrieve_transfer(create_response.id) expect(retrieve_response).not_to be_nil @@ -48,6 +52,7 @@ def create_transfer transfer_destination = CheckoutSdk::Transfers::TransferDestination.new transfer_destination.id = 'ent_w4jelhppmfiufdnatam37wrfc4' create_transfer = CheckoutSdk::Transfers::CreateTransfer.new + create_transfer.reference = 'reference' create_transfer.transfer_type = CheckoutSdk::Transfers::TransferType::COMMISSION create_transfer.source = transfer_source create_transfer.destination = transfer_destination