Skip to content

Commit

Permalink
Api Updates
Browse files Browse the repository at this point in the history
* Adds `card_token` object to `PaymentInstrumentRequest` for Integrated Platforms (CS2)
* Adds `if-match` header to `UpdatePaymentInstrumentRequest` for Integrated Platforms (CS2)
* Fix typo for `TransactionCurrencyAmount` in Financial Actions (CS2)
  • Loading branch information
martinseco committed Apr 20, 2023
1 parent abb05e7 commit 7ab9b3d
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 20 deletions.
2 changes: 2 additions & 0 deletions lib/checkout_sdk/accounts/accounts.rb
Expand Up @@ -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'
11 changes: 11 additions & 0 deletions 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
11 changes: 11 additions & 0 deletions 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
4 changes: 0 additions & 4 deletions lib/checkout_sdk/accounts/payment_instrument_request.rb
Expand Up @@ -24,10 +24,6 @@ class PaymentInstrumentRequest
:default,
:document,
:instrument_details

def initialize
@type = CheckoutSdk::Common::InstrumentType::BANK_ACCOUNT
end
end
end
end
Expand Up @@ -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
1 change: 1 addition & 0 deletions lib/checkout_sdk/common/instrument_type.rb
Expand Up @@ -6,6 +6,7 @@ module InstrumentType
BANK_ACCOUNT = 'bank_account'
TOKEN = 'token'
CARD = 'card'
CARD_TOKEN = 'card_token'
end
end
end
3 changes: 2 additions & 1 deletion lib/checkout_sdk/json_serializer.rb
Expand Up @@ -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 = {}
Expand Down
1 change: 1 addition & 0 deletions spec/checkout_sdk/accounts/accounts_integration_spec.rb
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down
25 changes: 15 additions & 10 deletions spec/checkout_sdk/transfers/transfers_integration_spec.rb
@@ -1,32 +1,36 @@
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

describe '.retrieve_transfer' do
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
Expand All @@ -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
Expand Down

0 comments on commit 7ab9b3d

Please sign in to comment.