Skip to content

Commit

Permalink
Add SEPA Direct Debit Core Support (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
armando-rodriguez-cko authored Apr 26, 2024
1 parent 8e04613 commit 66e5935
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/checkout_sdk/common/instrument_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module InstrumentType
BANK_ACCOUNT = 'bank_account'
TOKEN = 'token'
CARD = 'card'
SEPA = 'sepa'
CARD_TOKEN = 'card_token'
end
end
Expand Down
26 changes: 26 additions & 0 deletions lib/checkout_sdk/instruments/create/instrument_data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

module CheckoutSdk
module Instruments
# @!attribute account_number
# @return [String]
# @!attribute country
# @return [String] {CheckoutSdk::Common::Country}
# @!attribute currency
# @return [String] {CheckoutSdk::Common::Currency}
# @!attribute payment_type
# @return [String] {CheckoutSdk::Payments::PaymentType}
# @!attribute mandate_id
# @return [String]
# @!attribute date_of_signature
# @return [DateTime]
class InstrumentData
attr_accessor :account_number,
:country,
:currency,
:payment_type,
:mandate_id,
:date_of_signature
end
end
end
18 changes: 18 additions & 0 deletions lib/checkout_sdk/instruments/create/instrument_sepa.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module CheckoutSdk
module Instruments
# @!attribute instrument_data
# @return [InstrumentData]
# @!attribute account_holder
# @return [CheckoutSdk::Common::AccountHolder]
class InstrumentSepa < Instrument
attr_accessor :instrument_data,
:account_holder

def initialize
super CheckoutSdk::Common::InstrumentType::SEPA
end
end
end
end
2 changes: 2 additions & 0 deletions lib/checkout_sdk/instruments/instruments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
require 'checkout_sdk/instruments/create/instrument'
require 'checkout_sdk/instruments/create/instrument_token'
require 'checkout_sdk/instruments/create/instrument_bank_account'
require 'checkout_sdk/instruments/create/instrument_sepa'
require 'checkout_sdk/instruments/create/instrument_data'
# Client
require 'checkout_sdk/instruments/base_instruments_client'
require 'checkout_sdk/instruments/instruments_client'
Expand Down
5 changes: 4 additions & 1 deletion lib/checkout_sdk/payments/payment_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ module Payments
# @return [PaymentRetryRequest]
# @!attribute metadata
# @return [Hash{String => Object}]
# @!attribute instruction
# @return [PaymentInstruction]
class PaymentRequest
attr_accessor :payment_context_id,
:source,
Expand Down Expand Up @@ -93,7 +95,8 @@ class PaymentRequest
:processing,
:items,
:retry,
:metadata
:metadata,
:instruction
end
end
end
27 changes: 27 additions & 0 deletions spec/checkout_sdk/instruments/instruments_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,33 @@
end
end

context 'when requesting a sepa instrument' do
it 'returns a sepa instrument response' do
instruments_data = CheckoutSdk::Instruments::InstrumentData.new
instruments_data.account_number = "FR7630006000011234567890189"
instruments_data.country = CheckoutSdk::Common::Country::FR
instruments_data.currency = CheckoutSdk::Common::Currency::EUR
instruments_data.payment_type = CheckoutSdk::Payments::PaymentType::RECURRING

account_holder = CheckoutSdk::Common::AccountHolder.new
account_holder.first_name = 'John'
account_holder.last_name = 'Smith'
account_holder.billing_address = address
account_holder.phone = phone

request = CheckoutSdk::Instruments::InstrumentSepa.new
request.instrument_data = instruments_data
request.account_holder = account_holder

response = default_sdk.instruments.create(request)

expect(response).not_to be nil
expect(response.id).not_to be nil
expect(response.fingerprint).not_to be nil

end
end

context 'when requesting card token instrument with missing data' do
it 'raises an error' do
request = CheckoutSdk::Instruments::InstrumentToken.new
Expand Down

0 comments on commit 66e5935

Please sign in to comment.