czech_post_b2b_client 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bfcab9012bcc1bdb68a40691d169192bbe563e3
4
- data.tar.gz: f8ab6f6daca0ef901e640b855e1525125b2e113c
3
+ metadata.gz: 2a85b06fa34faeb7213e1441a6545383e8643f33
4
+ data.tar.gz: 91bc102f0d2f2686b9d0e64fdb42db9ba7f295e6
5
5
  SHA512:
6
- metadata.gz: 7d70c14295933177860de0d4b9ed845f479f64e28469cb13416152337c9e367eb1fb75337fbc8a3303446355765efbd184f6dcef0ecaf118387f05642a105ff2
7
- data.tar.gz: cb1933bd56a3859fe895d4e4b4884f530e36b300a781219957f619e155e7ca5b0cac668ab8ac9b7c63a04f96cd9abfc2160203b5dd405aa205ae5f3247cee8fc
6
+ metadata.gz: 25c9c40f2da073568cdb86f391caf378b6a2005c17433486d8e88354e24bad2e0b388e3c2e4331e0b15f241fee1845b6ad9d541db2f2c624e86d869a9e649196
7
+ data.tar.gz: 6ef1357723687047dc2483f262214a2a01b91f368119af7b1c2608713c7a12d9649bb22da65f28d8b3d005106b07e3a192fa581a668cb0529c0fdbf51d3a478c
@@ -2,6 +2,11 @@
2
2
 
3
3
  All changes to the gem are documented here.
4
4
 
5
+ ## [1.2.3] - 2020-08-21
6
+
7
+ - Corrected order in XML `sequence` elements
8
+ - Added `schemaLocation` to root element and placed publicly accessible XSDs into Github repo
9
+
5
10
  ## [1.2.2] - 2020-08-19
6
11
 
7
12
  - Printing templates now include @page_dimensions
data/README.md CHANGED
@@ -10,6 +10,7 @@ There are these supported operations of API:
10
10
  - *getParcelState* - returns all known states for listed parcels [HTTP GET - sync response]
11
11
  - *getParcelsPrinting* - returns PDF with address labels/stickers for listed parcels [HTTP GET - sync response]
12
12
 
13
+ ## Development of this gem is donated by [Squared s.r.o.](https://www.vyvolej.to)
13
14
 
14
15
  ## Installation
15
16
  ### 1) Registration at Czech Post (CP)
@@ -277,6 +278,8 @@ end
277
278
 
278
279
  ## Troubleshooting
279
280
 
281
+ You can validate request XML against XSD in [`documents/latest_xsds`](./documents/latest_xsds) (There are no public files from Czech Post :-( )
282
+
280
283
  1) Read all stuff in [`./documents`](./documents/) and [Yard docs](./doc/index.html), maybe it helps.
281
284
  2) If You get "handshake protocol failed" You do not have correct setup for certificates. If You get any xml response (see logger in debug mode) certificates are ok.
282
285
  You can always try `TimePeriodStatisticator` for that check, it do not need any "before" actions.
@@ -22,15 +22,14 @@ module CzechPostB2bClient
22
22
  # set defaults here
23
23
 
24
24
  # ours, accessible, but maybe out of date, for test usage
25
- @namespaces = {
26
- 'xmlns' => 'https://raw.githubusercontent.com/foton/czech_post_b2b_client/master/documents/B2B_CP_POL_2020-05-21/B2BCommon-v1.1.xsd',
27
- 'xmlns:ns2' => 'https://raw.githubusercontent.com/foton/czech_post_b2b_client/master/documents/B2B_CP_POL_2020-05-21/B2B-POLServices-v1.8.xsd'
28
- }
29
- # original, accessible only with setup certificates
30
25
  @namespaces = {
31
26
  'xmlns' => 'https://b2b.postaonline.cz/schema/B2BCommon-v1',
32
- 'xmlns:ns2' => 'https://b2b.postaonline.cz/schema/POLServices-v1'
27
+ 'xmlns:ns2' => 'https://b2b.postaonline.cz/schema/POLServices-v1',
28
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
29
+ 'xsi:noNamespaceSchemaLocation' => 'https://raw.githubusercontent.com/foton/czech_post_b2b_client/master/documents/latest_xsds/B2BCommon.xsd',
30
+ 'xsi:schemaLocation' => 'https://b2b.postaonline.cz/schema/POLServices-v1 https://raw.githubusercontent.com/foton/czech_post_b2b_client/master/documents/latest_xsds/B2BPOLServices.xsd'
33
31
  }
32
+
34
33
  @language = :cs
35
34
  @logger = defined?(Rails) ? ::Rails.logger : ::Logger.new(STDOUT)
36
35
  @b2b_api_base_uri = 'https://b2b.postaonline.cz/services/POLService/v1'
@@ -107,15 +107,6 @@ module CzechPostB2bClient
107
107
  end
108
108
  end
109
109
 
110
- def cache_on_delivery_address
111
- adr_data = common_data.dig(:cash_on_delivery, :address)
112
- return nil unless adr_data
113
-
114
- new_element('ns2:codAddress').tap do |cod_address|
115
- add_address_elements(cod_address, adr_data, without: ['ns2:firstName', 'ns2:surname'])
116
- end
117
- end
118
-
119
110
  def cache_on_delivery_bank
120
111
  data = common_data.dig(:cash_on_delivery, :bank_account)
121
112
  return nil unless data
@@ -184,20 +175,32 @@ module CzechPostB2bClient
184
175
  add_parcel_adress_element('ns2:doPOLParcelAddressDocument', parcel[:document_addressee])
185
176
  end
186
177
 
187
- def add_parcel_adress_element(element_name, addressee_data) # rubocop:disable Metrics/AbcSize
178
+ def add_parcel_adress_element(element_name, addressee_data) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
188
179
  return nil if addressee_data.nil?
189
180
 
190
181
  address_data = addressee_data[:address]
182
+
191
183
  new_element(element_name).tap do |do_parcel_address|
192
184
  add_element_to(do_parcel_address, 'ns2:recordID', value: addressee_data[:addressee_id]) # Nepovinne: Interni oznaceni adresata
193
-
194
- add_address_elements(do_parcel_address, address_data) # Nepovinne: Adresa
185
+ add_element_to(do_parcel_address, 'ns2:firstName', value: address_data[:first_name]) # Nepovinne: Jmeno
186
+ add_element_to(do_parcel_address, 'ns2:surname', value: address_data[:last_name]) # Nepovinne: Prijmeni
187
+ add_element_to(do_parcel_address, 'ns2:companyName', value: address_data[:company_name]) # Nepovinne: Nazev spolecnosti
188
+ add_element_to(do_parcel_address, 'ns2:aditionAddress', value: address_data[:addition_to_name]) # Nepovinne: Doplnujici iformace k nazvu podavatele
195
189
 
196
190
  add_element_to(do_parcel_address, 'ns2:subject', value: addressee_data[:addressee_type]) # Nepovinne: Typ adresata
197
191
  add_element_to(do_parcel_address, 'ns2:ic', value: addressee_data[:ic]) # Nepovinne: ICO
198
192
  add_element_to(do_parcel_address, 'ns2:dic', value: addressee_data[:dic]) # Nepovinne: DIC
199
193
  add_element_to(do_parcel_address, 'ns2:specification', value: addressee_data[:addressee_specification]) # Nepovinne: Specifikace napr. datum narozeni
200
194
 
195
+ add_element_to(do_parcel_address, 'ns2:street', value: address_data[:street]) # Nepovinne: Ulice
196
+ add_element_to(do_parcel_address, 'ns2:houseNumber', value: address_data[:house_number]) # Nepovinne: Cislo popisne
197
+ add_element_to(do_parcel_address, 'ns2:sequenceNumber', value: address_data[:sequence_number]) # Nepovinne: Cislo orientacni
198
+ add_element_to(do_parcel_address, 'ns2:partCity', value: address_data[:city_part]) # Nepovinne: Cast obce
199
+ add_element_to(do_parcel_address, 'ns2:city', value: address_data[:city]) # Nepovinne: Obec
200
+ add_element_to(do_parcel_address, 'ns2:zipCode', value: address_data[:post_code]) # Nepovinne: PSC
201
+ add_element_to(do_parcel_address, 'ns2:isoCountry', value: address_data[:country_iso_code]) # Nepovinne, default 'CZ': ISO kod zeme
202
+ add_element_to(do_parcel_address, 'ns2:subIsoCountry', value: address_data[:subcountry_iso_code]) # Nepovinne: ISO kod uzemi
203
+
201
204
  add_bank_elements(do_parcel_address, addressee_data[:bank_account]) # Nepovinne. Kod banky, cislo a predcisli uctu
202
205
  add_contact_elements(do_parcel_address, addressee_data) # Nepovinne. Telefon, Mobil a Email
203
206
 
@@ -206,7 +209,6 @@ module CzechPostB2bClient
206
209
  (addressee_data[:advice_informations] || []).each_with_index do |adv_info, index|
207
210
  add_element_to(do_parcel_address, 'ns2:adviceInformation' + (index + 1).to_s, value: adv_info) # Nepovinne: Informace 1- 6 k dodejce
208
211
  end
209
-
210
212
  add_element_to(do_parcel_address, 'ns2:adviceNote', value: addressee_data[:advice_note]) # Nepovinne: Poznamka k dodejce
211
213
  end
212
214
  end
@@ -242,7 +244,7 @@ module CzechPostB2bClient
242
244
 
243
245
  def custom_goods_for(description_data)
244
246
  new_element('ns2:doPOLParcelCustomsGoods').tap do |do_p_customs_goods|
245
- add_element_to(do_p_customs_goods, 'ns2:sequence', value: description_data[:order]) # Nepovinne: Poradi
247
+ add_element_to(do_p_customs_goods, 'ns2:sequence', value: description_data[:order].to_i) # Nepovinne: Poradi , cisl0 1-20
246
248
  add_element_to(do_p_customs_goods, 'ns2:customCont', value: description_data[:description]) # Nepovinne: Popis zbozi
247
249
  add_element_to(do_p_customs_goods, 'ns2:quantity', value: description_data[:quantity]) # Nepovinne: Mnozstvi
248
250
  add_element_to(do_p_customs_goods, 'ns2:weight', value: description_data[:weight_in_kg]) # Nepovinne: Hmotnost
@@ -252,34 +254,6 @@ module CzechPostB2bClient
252
254
  end
253
255
  end
254
256
 
255
- # Nepovinne. Adresa
256
- def add_address_elements(parent_element, address_data, without: [])
257
- return if address_data.nil?
258
-
259
- address_tags_and_values(address_data).each_pair do |xml_tag, value|
260
- unless without.include?(xml_tag)
261
- add_element_to(parent_element, xml_tag, value: value) unless value.nil?
262
- end
263
- end
264
- end
265
-
266
- def address_tags_and_values(address_data)
267
- {
268
- 'ns2:firstName' => address_data[:first_name], # Nepovinne: Jmeno
269
- 'ns2:surname' => address_data[:last_name], # Nepovinne: Prijmeni
270
- 'ns2:companyName' => address_data[:company_name], # Nepovinne: Nazev spolecnosti
271
- 'ns2:aditionAddress' => address_data[:addition_to_name], # Nepovinne: Doplnujici iformace k nazvu podavatele
272
- 'ns2:street' => address_data[:street], # Nepovinne: Ulice
273
- 'ns2:houseNumber' => address_data[:house_number], # Nepovinne: Cislo popisne
274
- 'ns2:sequenceNumber' => address_data[:sequence_number], # Nepovinne: Cislo orientacni
275
- 'ns2:partCity' => address_data[:city_part], # Nepovinne: Cast obce
276
- 'ns2:city' => address_data[:city], # Nepovinne: Obec
277
- 'ns2:zipCode' => address_data[:post_code], # Nepovinne: PSC
278
- 'ns2:isoCountry' => address_data[:country_iso_code], # Nepovinne, default 'CZ': ISO kod zeme
279
- 'ns2:subIsoCountry' => address_data[:subcountry_iso_code] # Nepovinne: ISO kod uzemi
280
- }
281
- end
282
-
283
257
  def add_bank_elements(parent_element, bank_account)
284
258
  return if bank_account.to_s == ''
285
259
 
@@ -291,9 +265,9 @@ module CzechPostB2bClient
291
265
  prefix, account, bank = nil
292
266
  end
293
267
 
268
+ add_element_to(parent_element, 'ns2:bank', value: bank) # Nepovinne: kod banky
294
269
  add_element_to(parent_element, 'ns2:prefixAccount', value: prefix) # Nepovinne: Predcisli k uctu
295
270
  add_element_to(parent_element, 'ns2:account', value: account) # Nepovinne: cislo uctu
296
- add_element_to(parent_element, 'ns2:bank', value: bank) # Nepovinne: kod banky
297
271
  end
298
272
 
299
273
  def add_contact_elements(parent_element, data_hash)
@@ -102,20 +102,11 @@ module CzechPostB2bClient
102
102
  end
103
103
 
104
104
  def sender_address
105
- return nil unless sender_data[:address]
106
-
107
- new_element('ns2:senderAddress').tap do |s_address|
108
- add_address_elements(s_address, sender_data[:address], without: ['ns2:firstName', 'ns2:surname'])
109
- end
105
+ add_header_address_element('ns2:senderAddress', sender_data)
110
106
  end
111
107
 
112
108
  def cache_on_delivery_address
113
- adr_data = common_data.dig(:cash_on_delivery, :address)
114
- return nil unless adr_data
115
-
116
- new_element('ns2:codAddress').tap do |cod_address|
117
- add_address_elements(cod_address, adr_data, without: ['ns2:firstName', 'ns2:surname'])
118
- end
109
+ add_header_address_element('ns2:codAddress', common_data[:cash_on_delivery])
119
110
  end
120
111
 
121
112
  def cache_on_delivery_bank
@@ -135,7 +126,7 @@ module CzechPostB2bClient
135
126
  end
136
127
  end
137
128
 
138
- def do_parcel_params(parcel_data) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
129
+ def do_parcel_params(parcel_data) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
139
130
  params = parcel_data[:params]
140
131
  cod = parcel_data[:cash_on_delivery] || {}
141
132
  new_element('ns2:doParcelParams').tap do |parcel_params|
@@ -185,20 +176,51 @@ module CzechPostB2bClient
185
176
  add_parcel_adress_element('ns2:doParcelAddressDocument', parcel_data[:document_addressee])
186
177
  end
187
178
 
188
- def add_parcel_adress_element(element_name, addressee_data) # rubocop:disable Metrics/AbcSize
179
+ def add_header_address_element(element_name, addressee_data) # rubocop:disable Metrics/AbcSize
189
180
  return nil if addressee_data.nil?
190
181
 
191
182
  address_data = addressee_data[:address]
183
+
192
184
  new_element(element_name).tap do |do_parcel_address|
193
- add_element_to(do_parcel_address, 'ns2:recordID', value: addressee_data[:addressee_id]) # Nepovinne: Interni oznaceni adresata
185
+ add_element_to(do_parcel_address, 'ns2:companyName', value: address_data[:company_name]) # Nepovinne: Nazev spolecnosti
186
+ add_element_to(do_parcel_address, 'ns2:aditionAddress', value: address_data[:addition_to_name]) # Nepovinne: Doplnujici iformace k nazvu podavatele
187
+ add_element_to(do_parcel_address, 'ns2:street', value: address_data[:street]) # Nepovinne: Ulice
188
+ add_element_to(do_parcel_address, 'ns2:houseNumber', value: address_data[:house_number]) # Nepovinne: Cislo popisne
189
+ add_element_to(do_parcel_address, 'ns2:sequenceNumber', value: address_data[:sequence_number]) # Nepovinne: Cislo orientacni
190
+ add_element_to(do_parcel_address, 'ns2:partCity', value: address_data[:city_part]) # Nepovinne: Cast obce
191
+ add_element_to(do_parcel_address, 'ns2:city', value: address_data[:city]) # Nepovinne: Obec
192
+ add_element_to(do_parcel_address, 'ns2:zipCode', value: address_data[:post_code]) # Nepovinne: PSC
193
+ add_element_to(do_parcel_address, 'ns2:isoCountry', value: address_data[:country_iso_code]) # Nepovinne, default 'CZ': ISO kod zeme
194
+ add_element_to(do_parcel_address, 'ns2:subIsoCountry', value: address_data[:subcountry_iso_code]) # Nepovinne: ISO kod uzemi
195
+ end
196
+ end
197
+
198
+ def add_parcel_adress_element(element_name, addressee_data) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
199
+ return nil if addressee_data.nil?
200
+
201
+ address_data = addressee_data[:address]
194
202
 
195
- add_address_elements(do_parcel_address, address_data) # Nepovinne: Adresa
203
+ new_element(element_name).tap do |do_parcel_address|
204
+ add_element_to(do_parcel_address, 'ns2:recordID', value: addressee_data[:addressee_id]) # Nepovinne: Interni oznaceni adresata
205
+ add_element_to(do_parcel_address, 'ns2:firstName', value: address_data[:first_name]) # Nepovinne: Jmeno
206
+ add_element_to(do_parcel_address, 'ns2:surname', value: address_data[:last_name]) # Nepovinne: Prijmeni
207
+ add_element_to(do_parcel_address, 'ns2:companyName', value: address_data[:company_name]) # Nepovinne: Nazev spolecnosti
208
+ add_element_to(do_parcel_address, 'ns2:aditionAddress', value: address_data[:addition_to_name]) # Nepovinne: Doplnujici iformace k nazvu podavatele
196
209
 
197
210
  add_element_to(do_parcel_address, 'ns2:subject', value: addressee_data[:addressee_type]) # Nepovinne: Typ adresata
198
211
  add_element_to(do_parcel_address, 'ns2:ic', value: addressee_data[:ic]) # Nepovinne: ICO
199
212
  add_element_to(do_parcel_address, 'ns2:dic', value: addressee_data[:dic]) # Nepovinne: DIC
200
213
  add_element_to(do_parcel_address, 'ns2:specification', value: addressee_data[:addressee_specification]) # Nepovinne: Specifikace napr. datum narozeni
201
214
 
215
+ add_element_to(do_parcel_address, 'ns2:street', value: address_data[:street]) # Nepovinne: Ulice
216
+ add_element_to(do_parcel_address, 'ns2:houseNumber', value: address_data[:house_number]) # Nepovinne: Cislo popisne
217
+ add_element_to(do_parcel_address, 'ns2:sequenceNumber', value: address_data[:sequence_number]) # Nepovinne: Cislo orientacni
218
+ add_element_to(do_parcel_address, 'ns2:partCity', value: address_data[:city_part]) # Nepovinne: Cast obce
219
+ add_element_to(do_parcel_address, 'ns2:city', value: address_data[:city]) # Nepovinne: Obec
220
+ add_element_to(do_parcel_address, 'ns2:zipCode', value: address_data[:post_code]) # Nepovinne: PSC
221
+ add_element_to(do_parcel_address, 'ns2:isoCountry', value: address_data[:country_iso_code]) # Nepovinne, default 'CZ': ISO kod zeme
222
+ add_element_to(do_parcel_address, 'ns2:subIsoCountry', value: address_data[:subcountry_iso_code]) # Nepovinne: ISO kod uzemi
223
+
202
224
  add_bank_elements(do_parcel_address, addressee_data[:bank_account]) # Nepovinne. Kod banky, cislo a predcisli uctu
203
225
  add_contact_elements(do_parcel_address, addressee_data) # Nepovinne. Telefon, Mobil a Email
204
226
 
@@ -207,7 +229,6 @@ module CzechPostB2bClient
207
229
  (addressee_data[:advice_informations] || []).each_with_index do |adv_info, index|
208
230
  add_element_to(do_parcel_address, 'ns2:adviceInformation' + (index + 1).to_s, value: adv_info) # Nepovinne: Informace 1- 6 k dodejce
209
231
  end
210
-
211
232
  add_element_to(do_parcel_address, 'ns2:adviceNote', value: addressee_data[:advice_note]) # Nepovinne: Poznamka k dodejce
212
233
  end
213
234
  end
@@ -278,9 +299,9 @@ module CzechPostB2bClient
278
299
  prefix, account, bank = nil
279
300
  end
280
301
 
302
+ add_element_to(parent_element, 'ns2:bank', value: bank) # Nepovinne: kod banky
281
303
  add_element_to(parent_element, 'ns2:prefixAccount', value: prefix) # Nepovinne: Predcisli k uctu
282
304
  add_element_to(parent_element, 'ns2:account', value: account) # Nepovinne: cislo uctu
283
- add_element_to(parent_element, 'ns2:bank', value: bank) # Nepovinne: kod banky
284
305
  end
285
306
 
286
307
  def add_contact_elements(parent_element, data_hash)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CzechPostB2bClient
4
- VERSION = '1.2.2'
4
+ VERSION = '1.2.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: czech_post_b2b_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petr Mlčoch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-19 00:00:00.000000000 Z
11
+ date: 2020-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ox