sepa 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sepa/base.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  module Sepa
2
3
  class Base
3
4
  include Aduki::Initializer
@@ -16,6 +17,17 @@ module Sepa
16
17
  false
17
18
  end
18
19
 
20
+ def normalize str
21
+ return str if str.is_a? Fixnum
22
+ return str if str.is_a? Float
23
+ str.gsub(/[àéèûîôüïöÿçÇÉÈáÀÁÜÏÖß]/, {
24
+ 'à' => 'a', 'é' => 'e', 'è' => 'e',
25
+ 'û' => 'u', 'î' => 'i', 'ô' => 'o', 'ü' => 'u', 'ï' => 'i', 'ö' => 'o',
26
+ 'ÿ' => 'y', 'ç' => 'c', 'Ç' => 'C', 'É' => 'E', 'È' => 'E', 'á' => 'a',
27
+ 'À' => 'A', 'Á' => 'A', 'Ü' => 'U', 'Ï' => 'I', 'Ö' => 'O', 'ß' => 'ss'
28
+ }).gsub(/[^a-zA-Z0-9_@ \.,()'+\/\?-]/, '')
29
+ end
30
+
19
31
  def to_xml builder
20
32
  self.class.attribute_defs.each do |name, meta|
21
33
  item = self.send(name)
@@ -23,10 +35,10 @@ module Sepa
23
35
  attributes = build_xml_attributes options[:attributes]
24
36
  next if item == nil || (item.is_a?(Sepa::Base) && item.empty?)
25
37
  if meta[:type] == :string
26
- builder.__send__(meta[:tag], item, attributes)
38
+ builder.__send__(meta[:tag], normalize(item), attributes)
27
39
  elsif meta[:type] == :[]
28
40
  if meta[:member_type] == nil
29
- item.each { |obj| builder.__send__(meta[:tag], obj, attributes) }
41
+ item.each { |obj| builder.__send__(meta[:tag], normalize(obj), attributes) }
30
42
  else
31
43
  item.each do |obj|
32
44
  builder.__send__(meta[:tag], attributes) { obj.to_xml builder }
@@ -4,6 +4,21 @@ require 'countries'
4
4
  require 'sepa/payments_initiation/pain00800104/customer_direct_debit_initiation'
5
5
 
6
6
  class Sepa::DirectDebitOrder
7
+ def self.new_order props
8
+ o = Order.new
9
+ o.message_id = props[:message_identification]
10
+ p = o.initiating_party = Party.new
11
+ p.name = props[:name]
12
+ p.address_line_1 = props[:address_1]
13
+ p.address_line_2 = props[:address_2]
14
+ p.postcode = props[:postcode]
15
+ p.town = props[:town]
16
+ p.country = props[:country]
17
+ p.contact_name = props[:contact]
18
+ p.contact_phone = props[:phone]
19
+ p.contact_email = props[:email]
20
+ end
21
+
7
22
  module Helper
8
23
  def blank? item
9
24
  item == nil || blank_string?(item)
@@ -29,6 +44,38 @@ class Sepa::DirectDebitOrder
29
44
  @message_id, @initiating_party, @creditor_payments = message_id, initiating_party, creditor_payments
30
45
  end
31
46
 
47
+ def new_payment
48
+ self.creditor_payments ||= []
49
+ cp = CreditorPayment.new
50
+ cp.id = props[:payment_identification]
51
+ cp.collection_date = props[:collection_date]
52
+ p = cp.creditor = Party.new
53
+ p.name = props[:name]
54
+ p.address_line_1 = props[:address_1]
55
+ p.address_line_2 = props[:address_2]
56
+ p.postcode = props[:postcode]
57
+ p.town = props[:town]
58
+ p.country = props[:country]
59
+ p.contact_name = props[:contact]
60
+ p.contact_phone = props[:phone]
61
+ p.contact_email = props[:email]
62
+
63
+ a = cp.creditor_account = BankAccount.new
64
+ a.iban = props[:iban]
65
+ a.swift = props[:bic]
66
+
67
+ sepa_id = if props[:sepa_identifier][:private]
68
+ PrivateSepaIdentifier.new(props[:sepa_identifier][:private])
69
+ else
70
+ OrganisationSepaIdentifier.new(props[:sepa_identifier][:organisation])
71
+ end
72
+
73
+ cp.sepa_identification = sepa_id
74
+
75
+ self.creditor_payments << cp
76
+ cp
77
+ end
78
+
32
79
  def to_properties opts
33
80
  hsh = {
34
81
  "group_header.message_identification" => message_id,
@@ -84,9 +131,12 @@ class Sepa::DirectDebitOrder
84
131
  hsh["#{prefix}.postal_address.town_name"] = town unless blank? town
85
132
  end
86
133
  hsh["#{prefix}.postal_address.country"] = cc unless blank? cc
87
- hsh["#{prefix}.contact_details.name"] = contact_name unless blank? contact_name
88
- hsh["#{prefix}.contact_details.phone_number"] = contact_phone unless blank? contact_phone
89
- hsh["#{prefix}.contact_details.email_address"] = contact_email unless blank? contact_email
134
+
135
+ unless opts[:pain_008_001_version] == "02"
136
+ hsh["#{prefix}.contact_details.name"] = contact_name unless blank? contact_name
137
+ hsh["#{prefix}.contact_details.phone_number"] = contact_phone unless blank? contact_phone
138
+ hsh["#{prefix}.contact_details.email_address"] = contact_email unless blank? contact_email
139
+ end
90
140
  end
91
141
  hsh
92
142
  end
@@ -163,7 +213,7 @@ class Sepa::DirectDebitOrder
163
213
  hsh["#{prefix}.payment_type_information.sequence_type"] = sequence_type
164
214
  end
165
215
 
166
- hsh = hsh.merge creditor.to_properties("#{prefix}.creditor", opts)
216
+ hsh = hsh.merge creditor.to_properties("#{prefix}.creditor", opts.merge({ context: :creditor }))
167
217
  hsh = hsh.merge creditor_account.to_properties("#{prefix}.creditor", opts)
168
218
  hsh = hsh.merge sepa_identification.to_properties("#{prefix}.creditor_scheme_identification", opts)
169
219
 
data/lib/sepa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sepa
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
@@ -15,7 +15,7 @@
15
15
  <AdrLine>289, Livva de Getamire</AdrLine>
16
16
  </PstlAdr>
17
17
  <CtctDtls>
18
- <Nm>M. Le Gérant</Nm>
18
+ <Nm>M. Le Gerant</Nm>
19
19
  <PhneNb>+33 111 111 111</PhneNb>
20
20
  <EmailAdr>gerant@softify.bigbang</EmailAdr>
21
21
  </CtctDtls>
@@ -36,7 +36,7 @@
36
36
  </PmtTpInf>
37
37
  <ReqdColltnDt>2013-07-10</ReqdColltnDt>
38
38
  <Cdtr>
39
- <Nm>Mon École</Nm>
39
+ <Nm>Mon Ecole</Nm>
40
40
  <PstlAdr>
41
41
  <PstCd>75022</PstCd>
42
42
  <TwnNm>Paris</TwnNm>
@@ -26,17 +26,12 @@
26
26
  </PmtTpInf>
27
27
  <ReqdColltnDt>2013-07-10</ReqdColltnDt>
28
28
  <Cdtr>
29
- <Nm>Mon École</Nm>
29
+ <Nm>Mon Ecole</Nm>
30
30
  <PstlAdr>
31
31
  <Ctry>FR</Ctry>
32
32
  <AdrLine>3, Livva de Getamire</AdrLine>
33
33
  <AdrLine>75022 Paris</AdrLine>
34
34
  </PstlAdr>
35
- <CtctDtls>
36
- <Nm>M. le Directeur</Nm>
37
- <PhneNb>+33 999 999 999</PhneNb>
38
- <EmailAdr>directeur@monecole.softify.com</EmailAdr>
39
- </CtctDtls>
40
35
  </Cdtr>
41
36
  <CdtrAcct>
42
37
  <Id>
@@ -84,11 +79,6 @@
84
79
  <AdrLine>256, Livva de Getamire</AdrLine>
85
80
  <AdrLine>75048 BERLIN</AdrLine>
86
81
  </PstlAdr>
87
- <CtctDtls>
88
- <Nm>Samuel ADAMS</Nm>
89
- <PhneNb>09876543210</PhneNb>
90
- <EmailAdr>samuel@adams.sepa.i.hope.this.works</EmailAdr>
91
- </CtctDtls>
92
82
  </Dbtr>
93
83
  <DbtrAcct>
94
84
  <Id>
@@ -119,11 +109,6 @@
119
109
  <AdrLine>256, Livva de Getamire</AdrLine>
120
110
  <AdrLine>75048 BERLIN</AdrLine>
121
111
  </PstlAdr>
122
- <CtctDtls>
123
- <Nm>Samuel ADAMS</Nm>
124
- <PhneNb>09876543210</PhneNb>
125
- <EmailAdr>samuel@adams.sepa.i.hope.this.works</EmailAdr>
126
- </CtctDtls>
127
112
  </Dbtr>
128
113
  <DbtrAcct>
129
114
  <Id>
@@ -148,17 +133,12 @@
148
133
  </PmtTpInf>
149
134
  <ReqdColltnDt>2013-07-10</ReqdColltnDt>
150
135
  <Cdtr>
151
- <Nm>Mon École</Nm>
136
+ <Nm>Mon Ecole</Nm>
152
137
  <PstlAdr>
153
138
  <Ctry>FR</Ctry>
154
139
  <AdrLine>3, Livva de Getamire</AdrLine>
155
140
  <AdrLine>75022 Paris</AdrLine>
156
141
  </PstlAdr>
157
- <CtctDtls>
158
- <Nm>M. le Directeur</Nm>
159
- <PhneNb>+33 999 999 999</PhneNb>
160
- <EmailAdr>directeur@monecole.softify.com</EmailAdr>
161
- </CtctDtls>
162
142
  </Cdtr>
163
143
  <CdtrAcct>
164
144
  <Id>
@@ -206,11 +186,6 @@
206
186
  <AdrLine>64, Livva de Getamire</AdrLine>
207
187
  <AdrLine>30005 RENNES</AdrLine>
208
188
  </PstlAdr>
209
- <CtctDtls>
210
- <Nm>Conan DALTON</Nm>
211
- <PhneNb>01234567890</PhneNb>
212
- <EmailAdr>conan@dalton.sepa.i.hope.this.works</EmailAdr>
213
- </CtctDtls>
214
189
  </Dbtr>
215
190
  <DbtrAcct>
216
191
  <Id>
@@ -241,11 +216,6 @@
241
216
  <AdrLine>64, Livva de Getamire</AdrLine>
242
217
  <AdrLine>30005 RENNES</AdrLine>
243
218
  </PstlAdr>
244
- <CtctDtls>
245
- <Nm>Conan DALTON</Nm>
246
- <PhneNb>01234567890</PhneNb>
247
- <EmailAdr>conan@dalton.sepa.i.hope.this.works</EmailAdr>
248
- </CtctDtls>
249
219
  </Dbtr>
250
220
  <DbtrAcct>
251
221
  <Id>
@@ -275,11 +245,6 @@
275
245
  <AdrLine>512, Livva de Meet Agir</AdrLine>
276
246
  <AdrLine>75099 LONDON</AdrLine>
277
247
  </PstlAdr>
278
- <CtctDtls>
279
- <Nm>Johann S. BACH</Nm>
280
- <PhneNb>09876543210</PhneNb>
281
- <EmailAdr>js@bach.sepa.i.hope.this.works</EmailAdr>
282
- </CtctDtls>
283
248
  </Dbtr>
284
249
  <DbtrAcct>
285
250
  <Id>
@@ -309,11 +274,6 @@
309
274
  <AdrLine>512, Livva de Meet Agir</AdrLine>
310
275
  <AdrLine>75099 LONDON</AdrLine>
311
276
  </PstlAdr>
312
- <CtctDtls>
313
- <Nm>Johann S. BACH</Nm>
314
- <PhneNb>09876543210</PhneNb>
315
- <EmailAdr>js@bach.sepa.i.hope.this.works</EmailAdr>
316
- </CtctDtls>
317
277
  </Dbtr>
318
278
  <DbtrAcct>
319
279
  <Id>
@@ -15,7 +15,7 @@
15
15
  <AdrLine>289, Livva de Getamire</AdrLine>
16
16
  </PstlAdr>
17
17
  <CtctDtls>
18
- <Nm>M. Le Gérant</Nm>
18
+ <Nm>M. Le Gerant</Nm>
19
19
  <PhneNb>+33 111 111 111</PhneNb>
20
20
  <EmailAdr>gerant@softify.bigbang</EmailAdr>
21
21
  </CtctDtls>
@@ -36,7 +36,7 @@
36
36
  </PmtTpInf>
37
37
  <ReqdColltnDt>2013-07-10</ReqdColltnDt>
38
38
  <Cdtr>
39
- <Nm>Mon École</Nm>
39
+ <Nm>Mon Ecole</Nm>
40
40
  <PstlAdr>
41
41
  <PstCd>75022</PstCd>
42
42
  <TwnNm>Paris</TwnNm>
@@ -15,7 +15,7 @@
15
15
  <AdrLine>289, Livva de Getamire</AdrLine>
16
16
  </PstlAdr>
17
17
  <CtctDtls>
18
- <Nm>M. Le Gérant</Nm>
18
+ <Nm>M. Le Gerant</Nm>
19
19
  <PhneNb>+33 111 111 111</PhneNb>
20
20
  <EmailAdr>gerant@softify.bigbang</EmailAdr>
21
21
  </CtctDtls>
@@ -36,7 +36,7 @@
36
36
  </PmtTpInf>
37
37
  <ReqdColltnDt>2013-07-10</ReqdColltnDt>
38
38
  <Cdtr>
39
- <Nm>Mon École</Nm>
39
+ <Nm>Mon Ecole</Nm>
40
40
  <PstlAdr>
41
41
  <PstCd>75022</PstCd>
42
42
  <TwnNm>Paris</TwnNm>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sepa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: