Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make charge bearer optional instead of constant set to SLEV #7

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2018-2023 viafintech GmbH
Copyright (c) 2018-2024 viafintech GmbH

Copyright (c) 2013-2017 Georg Leciejewski (Sales King GmbH) & Georg Ledermann for portions of this project copied from sepa_king

Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ sdd.add_transaction(
# One of these strings:
# 'CHTA' ("Banklastschrift") - Only for Swiss Direct Debits
# 'CHDD' ("PostFinance-Lastschrift") - Only for Swiss Direct Debits
service_level: 'CHTA'
service_level: 'CHTA',

# Local instrument, in German "Lastschriftart"
# One of these strings:
Expand Down Expand Up @@ -198,6 +198,14 @@ sct.add_transaction(
# 'URGP' ("Taggleiche Eilüberweisung")
service_level: 'URGP'

# OPTIONAL: Charge Bearer
# One of these strings:
# 'DEBT' (Borne by Debitor)
# 'CRED' (Borne by Creditor)
# 'SHAR' (Shared)
# 'SLEV' (Service Level) - Must be SLEV for SEPA transfers
charge_bearer: 'SHAR',

# OPTIONAL: Unstructured information to indicate the purpose of the payment
# String, max. 4 char
category_purpose: 'SALA',
Expand Down
7 changes: 5 additions & 2 deletions lib/sps_king/message/credit_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def transaction_group(transaction)
requested_date: transaction.requested_date,
batch_booking: transaction.batch_booking,
service_level: transaction.service_level,
category_purpose: transaction.category_purpose
category_purpose: transaction.category_purpose,
charge_bearer: transaction.charge_bearer,
}
end

Expand Down Expand Up @@ -56,7 +57,9 @@ def build_payment_informations(builder)
builder.BIC(account.bic)
end
end
builder.ChrgBr('SLEV')
if group[:charge_bearer]
builder.ChrgBr(group[:charge_bearer])
end

transactions.each do |transaction|
build_transaction(builder, transaction)
Expand Down
7 changes: 6 additions & 1 deletion lib/sps_king/transaction/credit_transfer_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ module SPS
class CreditTransferTransaction < Transaction
attr_accessor :service_level,
:creditor_address,
:category_purpose
:category_purpose,
:charge_bearer

CHARGE_BEARERS = ['DEBT', 'CRED', 'SHAR', 'SLEV'].freeze

validates_length_of :category_purpose, within: 1..4, allow_nil: true

validates :charge_bearer, inclusion: CHARGE_BEARERS, allow_nil: true

validate { |t| t.validate_requested_date_after(Date.today) }

def schema_compatible?(schema_name)
Expand Down
21 changes: 21 additions & 0 deletions spec/lib/sps_king/message/credit_transfer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,27 @@
end
end

context 'with charge bearer' do
SPS::CreditTransferTransaction::CHARGE_BEARERS.each do |charge_bearer|
context "with value #{charge_bearer}" do
subject do
sct = credit_transfer

sct.add_transaction(credit_transfer_transaction.merge(charge_bearer: charge_bearer))

sct.to_xml
end

it 'should contain payment_information with <ChrgBr>' do
puts subject

expect(subject)
.to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/ChrgBr', charge_bearer)
end
end
end
end

context 'with different batch_booking given' do
subject do
sct = credit_transfer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
bic: 'RAIFCH22',
amount: 102.50,
reference: 'XYZ-1234/123',
remittance_information: 'Rechnung 123 vom 22.08.2013'
remittance_information: 'Rechnung 123 vom 22.08.2013',
)
).to be_valid
end
Expand Down Expand Up @@ -50,4 +50,16 @@
expect(SPS::CreditTransferTransaction).not_to accept('', 'X' * 5, for: :category_purpose)
end
end

context 'Charge Bearer' do
it 'should allow valid value' do
expect(SPS::CreditTransferTransaction)
.to accept(nil, 'DEBT', 'CRED', 'SHAR', 'SLEV', for: :charge_bearer)
end

it 'should not allow invalid value' do
expect(SPS::CreditTransferTransaction)
.not_to accept('', 'X' * 5, 'X' * 4, for: :charge_bearer)
end
end
end
Loading