Ruby gem for creating SEPA XML files
We love building payment applications! So after developing the DTAUS library for Ruby we move on with SEPA.
Features
This gem implements the following two messages out of the ISO 20022 standard:
- Credit Transfer Initiation (
pain.001.003.03
, pain.001.002.03
and pain.001.001.03
) - Direct Debit Initiation (
pain.008.003.02
, pain.008.002.02
and pain.008.001.02
)
It handles the Specification of Data Formats v2.7 (2013-11-04).
BTW: pain is a shortcut for Payment Initiation.
Requirements
- Ruby 2.2 or newer
- ActiveModel 3.1 or newer (including 6.0)
Installation
gem install sepa_king
Usage
How to create the XML for Direct Debit Initiation (in German: "Lastschriften")
sdd = SEPA::DirectDebit.new(
name: 'Gläubiger GmbH',
bic: 'BANKDEFFXXX',
iban: 'DE87200500001234567890',
creditor_identifier: 'DE98ZZZ09999999999'
)
sdd.add_transaction(
name: 'Zahlemann & Söhne GbR',
bic: 'SPUEDE2UXXX',
iban: 'DE21500500009876543210',
amount: 39.99,
currency: 'EUR',
instruction: '12345',
reference: 'XYZ/2013-08-ABO/6789',
remittance_information: 'Vielen Dank für Ihren Einkauf!',
mandate_id: 'K-02-2011-12345',
mandate_date_of_signature: Date.new(2011,1,25),
local_instrument: 'CORE',
sequence_type: 'OOFF',
requested_date: Date.new(2013,9,5),
batch_booking: true
creditor_account: SEPA::CreditorAccount.new(
name: 'Creditor Inc.',
bic: 'RABONL2U',
iban: 'NL08RABO0135742099',
creditor_identifier: 'NL53ZZZ091734220000'
)
debtor_address: SEPA::DebtorAddress.new(
country_code: 'CH',
address_line1: 'Mustergasse 123a',
address_line2: '1234 Musterstadt'
street_name: 'Mustergasse',
building_number: '123a',
post_code: '1234',
town_name: 'Musterstadt'
)
)
sdd.add_transaction ...
xml_string = sdd.to_xml
xml_string = sdd.to_xml('pain.008.002.02')
How to create the XML for Credit Transfer Initiation (in German: "Überweisungen")
sct = SEPA::CreditTransfer.new(
name: 'Schuldner GmbH',
bic: 'BANKDEFFXXX',
iban: 'DE87200500001234567890'
)
sct.add_transaction(
name: 'Telekomiker AG',
bic: 'PBNKDEFF370',
iban: 'DE37112589611964645802',
amount: 102.50,
currency: 'EUR',
instruction: '12345',
reference: 'XYZ-1234/123',
remittance_information: 'Rechnung vom 22.08.2013',
requested_date: Date.new(2013,9,5),
batch_booking: true,
service_level: 'URGP'
category_purpose: 'SALA',
creditor_address: SEPA::CreditorAddress.new(
country_code: 'CH',
address_line1: 'Mustergasse 123a',
address_line2: '1234 Musterstadt'
street_name: 'Mustergasse',
building_number: '123a',
post_code: '1234',
town_name: 'Musterstadt'
)
)
sct.add_transaction ...
xml_string = sct.to_xml
xml_string = sct.to_xml('pain.001.002.03')
Validations
You can rely on our internal validations, raising errors when needed, during
message creation.
To validate your models holding SEPA related information (e.g. BIC, IBAN,
mandate_id) you can use our validator classes or rely on some constants.
Examples:
class BankAccount < ActiveRecord::Base
validates_with SEPA::IBANValidator, field_name: :iban_the_terrible
validates_with SEPA::BICValidator, field_name: :bank_bic
end
class Payment < ActiveRecord::Base
validates_inclusion_of :sepa_sequence_type, in: SEPA::DirectDebitTransaction::SEQUENCE_TYPES
validates_with SEPA::MandateIdentifierValidator, field_name: :mandate_id
end
Beware: The SEPA::IBANValidator is strict - e.g. it does not allow any spaces in the IBAN.
Also see:
Changelog
https://github.com/salesking/sepa_king/releases
Contributors
https://github.com/salesking/sepa_king/graphs/contributors
Resources
License
Released under the MIT license
Copyright (c) 2013-2019 Georg Leciejewski (SalesKing), Georg Ledermann (https://github.com/ledermann)