deliveries 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +11 -4
- data/CHANGELOG.md +22 -2
- data/Gemfile.lock +25 -25
- data/README.md +22 -11
- data/deliveries.gemspec +1 -1
- data/lib/deliveries/address.rb +2 -1
- data/lib/deliveries/couriers/correos_express/pickups/create/format_params.rb +3 -3
- data/lib/deliveries/couriers/correos_express/shipments/create/format_params.rb +2 -1
- data/lib/deliveries/couriers/correos_express.rb +3 -3
- data/lib/deliveries/couriers/envialia/authentication.rb +50 -0
- data/lib/deliveries/couriers/envialia/labels/generate.rb +88 -0
- data/lib/deliveries/couriers/envialia/pickups/create.rb +147 -0
- data/lib/deliveries/couriers/envialia/pickups/trace/format_response.rb +94 -0
- data/lib/deliveries/couriers/envialia/pickups/trace.rb +69 -0
- data/lib/deliveries/couriers/envialia/shipments/create.rb +148 -0
- data/lib/deliveries/couriers/envialia/shipments/trace/format_response.rb +97 -0
- data/lib/deliveries/couriers/envialia/shipments/trace.rb +71 -0
- data/lib/deliveries/couriers/envialia.rb +93 -0
- data/lib/deliveries/couriers/mondial_relay.rb +3 -3
- data/lib/deliveries/couriers/spring.rb +1 -1
- data/lib/deliveries/version.rb +1 -1
- metadata +13 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bb252635f57203e34b0d593df80f4fc0aa033ebfb70675f646cf192fc946a647
|
|
4
|
+
data.tar.gz: 6e232ea5c543aaeaf298e618f2f97b7192b04b6de72f45de3204b1f2f4ab1d3f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 75e7cd7e1b1380f0b889d91515e7f356f5847b24106e98487c4b2cc1b1a907da87dfee8c184f29d7c6ffb6c9d89398b06d3ab30a67ee8535330a2263ff989a58
|
|
7
|
+
data.tar.gz: f09ac1de09045873b6a8e0f91d31e011f7b7a232c4924d6b391f9b87b99d40dc62d1d0923b00c8fd96138df8dccda169f80669f259664d974dca47a8952dbb77
|
data/.github/workflows/main.yml
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
name: Ruby
|
|
2
2
|
|
|
3
|
-
on: [push,pull_request]
|
|
3
|
+
on: [push, pull_request]
|
|
4
4
|
|
|
5
5
|
jobs:
|
|
6
6
|
build:
|
|
7
7
|
runs-on: ubuntu-latest
|
|
8
|
+
|
|
9
|
+
strategy:
|
|
10
|
+
fail-fast: false
|
|
11
|
+
matrix:
|
|
12
|
+
ruby: [2.6, 2.7, '3.0']
|
|
13
|
+
|
|
8
14
|
steps:
|
|
9
15
|
- uses: actions/checkout@v2
|
|
10
|
-
- name:
|
|
16
|
+
- name: Install poppler-utils
|
|
17
|
+
run: sudo apt-get install poppler-utils
|
|
18
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
|
11
19
|
uses: ruby/setup-ruby@v1
|
|
12
20
|
with:
|
|
13
|
-
ruby-version:
|
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
|
14
22
|
- name: Run the default task
|
|
15
23
|
run: |
|
|
16
|
-
sudo apt-get install poppler-utils
|
|
17
24
|
gem install bundler -v 2.2.4
|
|
18
25
|
bundle install
|
|
19
26
|
bundle exec rake
|
data/CHANGELOG.md
CHANGED
|
@@ -6,8 +6,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.3.0] - 2021-11-26
|
|
10
|
+
### Added
|
|
11
|
+
- Envialia courier integration
|
|
12
|
+
|
|
13
|
+
## [0.2.1] - 2021-11-04
|
|
14
|
+
### Fixed
|
|
15
|
+
- Field `clienteRecogida` must have the same value as `codDest` in Correos Express pickup.
|
|
16
|
+
|
|
17
|
+
## [0.2.0] - 2021-11-03
|
|
18
|
+
### Added
|
|
19
|
+
- `Address` can now include a custom id for couriers that support it (currently only Correos Express).
|
|
20
|
+
|
|
21
|
+
## [0.1.1] - 2021-10-11
|
|
22
|
+
### Fixed
|
|
23
|
+
- Fix keyword parameter passing to make it compatible with Ruby 3.0.
|
|
24
|
+
|
|
9
25
|
## [0.1.0] - 2021-09-27
|
|
10
26
|
🎉 First release!
|
|
11
27
|
|
|
12
|
-
[Unreleased]: https://github.com/ecommerce-ventures/deliveries/compare/v0.
|
|
13
|
-
[0.
|
|
28
|
+
[Unreleased]: https://github.com/ecommerce-ventures/deliveries/compare/v0.3.0...HEAD
|
|
29
|
+
[0.3.0]: https://github.com/ecommerce-ventures/deliveries/compare/v0.2.1...v0.3.0
|
|
30
|
+
[0.2.1]: https://github.com/ecommerce-ventures/deliveries/compare/v0.2.0...v0.2.1
|
|
31
|
+
[0.2.0]: https://github.com/ecommerce-ventures/deliveries/compare/v0.1.1...v0.2.0
|
|
32
|
+
[0.1.1]: https://github.com/ecommerce-ventures/deliveries/compare/v0.1.0...v0.1.1
|
|
33
|
+
[0.1.0]: https://github.com/ecommerce-ventures/deliveries/releases/tag/v0.1.0
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
deliveries (0.
|
|
4
|
+
deliveries (0.3.0)
|
|
5
5
|
activesupport (>= 5.2.0)
|
|
6
6
|
hexapdf
|
|
7
7
|
httparty
|
|
@@ -12,7 +12,7 @@ PATH
|
|
|
12
12
|
GEM
|
|
13
13
|
remote: https://rubygems.org/
|
|
14
14
|
specs:
|
|
15
|
-
activesupport (6.1.4)
|
|
15
|
+
activesupport (6.1.4.1)
|
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
17
17
|
i18n (>= 1.6, < 2)
|
|
18
18
|
minitest (>= 5.1)
|
|
@@ -35,49 +35,49 @@ GEM
|
|
|
35
35
|
gyoku (1.3.1)
|
|
36
36
|
builder (>= 2.1.2)
|
|
37
37
|
hashdiff (1.0.1)
|
|
38
|
-
hexapdf (0.
|
|
38
|
+
hexapdf (0.19.0)
|
|
39
39
|
cmdparse (~> 3.0, >= 3.0.3)
|
|
40
40
|
geom2d (~> 0.3)
|
|
41
|
-
httparty (0.
|
|
41
|
+
httparty (0.20.0)
|
|
42
42
|
mime-types (~> 3.0)
|
|
43
43
|
multi_xml (>= 0.5.2)
|
|
44
|
-
httpi (2.
|
|
44
|
+
httpi (2.5.0)
|
|
45
45
|
rack
|
|
46
46
|
socksify
|
|
47
|
-
i18n (1.8.
|
|
47
|
+
i18n (1.8.11)
|
|
48
48
|
concurrent-ruby (~> 1.0)
|
|
49
|
-
mime-types (3.
|
|
49
|
+
mime-types (3.4.1)
|
|
50
50
|
mime-types-data (~> 3.2015)
|
|
51
|
-
mime-types-data (3.2021.
|
|
51
|
+
mime-types-data (3.2021.1115)
|
|
52
52
|
mini_magick (4.11.0)
|
|
53
53
|
minitest (5.14.4)
|
|
54
54
|
multi_xml (0.6.0)
|
|
55
|
-
nokogiri (1.12.
|
|
55
|
+
nokogiri (1.12.5-x86_64-linux)
|
|
56
56
|
racc (~> 1.4)
|
|
57
57
|
nori (2.6.0)
|
|
58
|
-
parallel (1.
|
|
58
|
+
parallel (1.21.0)
|
|
59
59
|
parser (3.0.2.0)
|
|
60
60
|
ast (~> 2.4.1)
|
|
61
61
|
public_suffix (4.0.6)
|
|
62
|
-
racc (1.
|
|
62
|
+
racc (1.6.0)
|
|
63
63
|
rack (2.2.3)
|
|
64
64
|
rainbow (3.0.0)
|
|
65
65
|
rake (13.0.6)
|
|
66
66
|
regexp_parser (2.1.1)
|
|
67
67
|
rexml (3.2.5)
|
|
68
|
-
rspec (3.
|
|
69
|
-
rspec-core (~> 3.
|
|
70
|
-
rspec-expectations (~> 3.
|
|
71
|
-
rspec-mocks (~> 3.
|
|
72
|
-
rspec-core (3.
|
|
73
|
-
rspec-support (~> 3.
|
|
74
|
-
rspec-expectations (3.
|
|
68
|
+
rspec (3.10.0)
|
|
69
|
+
rspec-core (~> 3.10.0)
|
|
70
|
+
rspec-expectations (~> 3.10.0)
|
|
71
|
+
rspec-mocks (~> 3.10.0)
|
|
72
|
+
rspec-core (3.10.1)
|
|
73
|
+
rspec-support (~> 3.10.0)
|
|
74
|
+
rspec-expectations (3.10.1)
|
|
75
75
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
76
|
-
rspec-support (~> 3.
|
|
77
|
-
rspec-mocks (3.
|
|
76
|
+
rspec-support (~> 3.10.0)
|
|
77
|
+
rspec-mocks (3.10.2)
|
|
78
78
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
79
|
-
rspec-support (~> 3.
|
|
80
|
-
rspec-support (3.
|
|
79
|
+
rspec-support (~> 3.10.0)
|
|
80
|
+
rspec-support (3.10.3)
|
|
81
81
|
rubocop (0.93.1)
|
|
82
82
|
parallel (~> 1.10)
|
|
83
83
|
parser (>= 2.7.1.5)
|
|
@@ -87,7 +87,7 @@ GEM
|
|
|
87
87
|
rubocop-ast (>= 0.6.0)
|
|
88
88
|
ruby-progressbar (~> 1.7)
|
|
89
89
|
unicode-display_width (>= 1.4.0, < 2.0)
|
|
90
|
-
rubocop-ast (1.
|
|
90
|
+
rubocop-ast (1.12.0)
|
|
91
91
|
parser (>= 3.0.1.1)
|
|
92
92
|
ruby-progressbar (1.11.0)
|
|
93
93
|
savon (2.12.1)
|
|
@@ -101,7 +101,7 @@ GEM
|
|
|
101
101
|
socksify (1.7.1)
|
|
102
102
|
tzinfo (2.0.4)
|
|
103
103
|
concurrent-ruby (~> 1.0)
|
|
104
|
-
unicode-display_width (1.
|
|
104
|
+
unicode-display_width (1.8.0)
|
|
105
105
|
wasabi (3.6.1)
|
|
106
106
|
addressable
|
|
107
107
|
httpi (~> 2.0)
|
|
@@ -110,7 +110,7 @@ GEM
|
|
|
110
110
|
addressable (>= 2.8.0)
|
|
111
111
|
crack (>= 0.3.2)
|
|
112
112
|
hashdiff (>= 0.4.0, < 2.0.0)
|
|
113
|
-
zeitwerk (2.
|
|
113
|
+
zeitwerk (2.5.1)
|
|
114
114
|
|
|
115
115
|
PLATFORMS
|
|
116
116
|
x86_64-linux
|
data/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Deliveries is a gem that gives you the ability to integrate multiple shipping se
|
|
|
6
6
|
|
|
7
7
|
Add the following line to your Gemfile
|
|
8
8
|
|
|
9
|
-
```
|
|
9
|
+
```ruby
|
|
10
10
|
gem 'deliveries'
|
|
11
11
|
```
|
|
12
12
|
Then run:
|
|
@@ -20,7 +20,7 @@ bundle install
|
|
|
20
20
|
Each courier requires a different configuration, below we will leave some examples
|
|
21
21
|
|
|
22
22
|
#### 1. Mondial Relay
|
|
23
|
-
```
|
|
23
|
+
```ruby
|
|
24
24
|
Deliveries.courier(:mondial_relay).configure do |config|
|
|
25
25
|
config.mondial_relay_merchant = '...'
|
|
26
26
|
config.mondial_relay_key = '...'
|
|
@@ -28,7 +28,7 @@ end
|
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
#### 2. Mondial Relay Dual
|
|
31
|
-
```
|
|
31
|
+
```ruby
|
|
32
32
|
Deliveries.courier(:mondial_relay_dual).configure do |config|
|
|
33
33
|
config.dual_carrier_login = '...'
|
|
34
34
|
config.dual_carrier_password = '...'
|
|
@@ -48,7 +48,7 @@ end
|
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
#### 3. Correos Express
|
|
51
|
-
```
|
|
51
|
+
```ruby
|
|
52
52
|
Deliveries.courier(:correos_express).configure do |config|
|
|
53
53
|
config.username = '...'
|
|
54
54
|
config.password = '...'
|
|
@@ -67,7 +67,7 @@ end
|
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
#### 4. Spring
|
|
70
|
-
```
|
|
70
|
+
```ruby
|
|
71
71
|
Deliveries.courier(:spring).configure do |config|
|
|
72
72
|
config.api_key = '...'
|
|
73
73
|
config.countries = {
|
|
@@ -89,7 +89,7 @@ end
|
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
#### 5. UPS
|
|
92
|
-
```
|
|
92
|
+
```ruby
|
|
93
93
|
Deliveries.courier(:ups).configure do |config|
|
|
94
94
|
config.license_number = '...'
|
|
95
95
|
config.username = '...'
|
|
@@ -103,25 +103,36 @@ Deliveries.courier(:ups).configure do |config|
|
|
|
103
103
|
end
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
+
#### Time Zone
|
|
107
|
+
|
|
108
|
+
This library uses Active Support's Time extension, so a time zone must be set before using it:
|
|
109
|
+
|
|
110
|
+
```ruby
|
|
111
|
+
require 'active_support/time'
|
|
112
|
+
|
|
113
|
+
# Configure time zone
|
|
114
|
+
Time.zone = 'Madrid'
|
|
115
|
+
```
|
|
116
|
+
|
|
106
117
|
## Usage
|
|
107
118
|
|
|
108
119
|
#### Get collection point by country and postcode
|
|
109
120
|
|
|
110
|
-
```
|
|
121
|
+
```ruby
|
|
111
122
|
# Example Using Ups
|
|
112
123
|
|
|
113
124
|
Deliveries.courier(:ups).get_collection_points(postcode: '...', country: 'it')
|
|
114
125
|
```
|
|
115
126
|
#### Get collection point info
|
|
116
127
|
|
|
117
|
-
```
|
|
128
|
+
```ruby
|
|
118
129
|
# Example Using Mondial Relay
|
|
119
130
|
|
|
120
131
|
Deliveries.courier(:mondial_relay).get_collection_point(global_point_id: 'mondial_relay~fr~00000~XXXXXX')
|
|
121
132
|
```
|
|
122
133
|
|
|
123
134
|
#### Create a Shipment
|
|
124
|
-
```
|
|
135
|
+
```ruby
|
|
125
136
|
# Example Using Correos Express
|
|
126
137
|
|
|
127
138
|
sender = Deliveries::Address.new(
|
|
@@ -158,7 +169,7 @@ response = Deliveries.courier(:correos_express).create_shipment(
|
|
|
158
169
|
```
|
|
159
170
|
|
|
160
171
|
#### Create a Pickup
|
|
161
|
-
```
|
|
172
|
+
```ruby
|
|
162
173
|
# Example Using Spring
|
|
163
174
|
|
|
164
175
|
sender = Deliveries::Address.new(
|
|
@@ -193,7 +204,7 @@ response = Deliveries.courier(:spring).create_pickup(
|
|
|
193
204
|
```
|
|
194
205
|
|
|
195
206
|
#### Download a Label
|
|
196
|
-
```
|
|
207
|
+
```ruby
|
|
197
208
|
# Example Using Spring
|
|
198
209
|
|
|
199
210
|
label = Deliveries.courier(:spring).get_label(tracking_code: '...')
|
data/deliveries.gemspec
CHANGED
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
|
15
15
|
|
|
16
16
|
spec.metadata['homepage_uri'] = spec.homepage
|
|
17
17
|
spec.metadata['source_code_uri'] = 'https://github.com/ecommerce-ventures/deliveries'
|
|
18
|
-
spec.metadata['changelog_uri'] = 'https://github.com/ecommerce-ventures/deliveries/CHANGELOG.md'
|
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/ecommerce-ventures/deliveries/blob/master/CHANGELOG.md'
|
|
19
19
|
|
|
20
20
|
# Specify which files should be added to the gem when it is released.
|
|
21
21
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
data/lib/deliveries/address.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module Deliveries
|
|
2
2
|
class Address
|
|
3
|
-
attr_accessor :name, :email, :phone, :country, :state, :city, :street, :postcode
|
|
3
|
+
attr_accessor :name, :email, :phone, :country, :state, :city, :street, :postcode, :address_id
|
|
4
4
|
|
|
5
5
|
COUNTRY_PHONE_PREFIXES = {
|
|
6
6
|
be: 32,
|
|
@@ -30,6 +30,7 @@ module Deliveries
|
|
|
30
30
|
self.city = attributes[:city]
|
|
31
31
|
self.street = attributes[:street]
|
|
32
32
|
self.postcode = attributes[:postcode]
|
|
33
|
+
self.address_id = attributes[:address_id]
|
|
33
34
|
end
|
|
34
35
|
|
|
35
36
|
def courierize(courier_id)
|
|
@@ -24,8 +24,8 @@ module Deliveries
|
|
|
24
24
|
solicitante: CorreosExpress.config(:client_code),
|
|
25
25
|
refRecogida: reference_code,
|
|
26
26
|
fechaRecogida: pickup_date&.strftime('%d%m%Y') || '',
|
|
27
|
-
clienteRecogida: CorreosExpress.config(:pickup_receiver_code),
|
|
28
|
-
codRemit: '',
|
|
27
|
+
clienteRecogida: receiver.address_id || CorreosExpress.config(:pickup_receiver_code),
|
|
28
|
+
codRemit: sender.address_id || '',
|
|
29
29
|
nomRemit: sender.name,
|
|
30
30
|
nifRemit: '',
|
|
31
31
|
dirRecog: sender.street,
|
|
@@ -34,7 +34,7 @@ module Deliveries
|
|
|
34
34
|
contRecog: sender.name,
|
|
35
35
|
tlfnoRecog: sender.phone,
|
|
36
36
|
emailRecog: sender.email,
|
|
37
|
-
codDest: CorreosExpress.config(:pickup_receiver_code),
|
|
37
|
+
codDest: receiver.address_id || CorreosExpress.config(:pickup_receiver_code),
|
|
38
38
|
nomDest: receiver.name,
|
|
39
39
|
dirDest: receiver.street,
|
|
40
40
|
pobDest: receiver.city,
|
|
@@ -23,7 +23,7 @@ module Deliveries
|
|
|
23
23
|
def execute
|
|
24
24
|
params = {
|
|
25
25
|
solicitante: CorreosExpress.config(:client_code),
|
|
26
|
-
codRte: CorreosExpress.config(:shipment_sender_code),
|
|
26
|
+
codRte: sender.address_id || CorreosExpress.config(:shipment_sender_code),
|
|
27
27
|
ref: reference_code,
|
|
28
28
|
fecha: format_date(shipment_date),
|
|
29
29
|
nomRte: sender.name,
|
|
@@ -33,6 +33,7 @@ module Deliveries
|
|
|
33
33
|
contacRte: sender.name,
|
|
34
34
|
telefRte: sender.phone,
|
|
35
35
|
emailRte: sender.email,
|
|
36
|
+
codDest: receiver.address_id || '',
|
|
36
37
|
nomDest: receiver.name,
|
|
37
38
|
dirDest: receiver.street,
|
|
38
39
|
pobDest: receiver.city,
|
|
@@ -51,7 +51,7 @@ module Deliveries
|
|
|
51
51
|
points = CollectionPoints::Search.new(postcode: postcode).execute
|
|
52
52
|
points.each do |point|
|
|
53
53
|
collection_point_params = CollectionPoints::Search::FormatResponse.new(response: point).execute
|
|
54
|
-
collection_points << Deliveries::CollectionPoint.new(collection_point_params)
|
|
54
|
+
collection_points << Deliveries::CollectionPoint.new(**collection_point_params)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
collection_points
|
|
@@ -79,7 +79,7 @@ module Deliveries
|
|
|
79
79
|
).execute
|
|
80
80
|
|
|
81
81
|
tracking_info_params = Shipments::Trace::FormatResponse.new(response: response).execute
|
|
82
|
-
Deliveries::TrackingInfo.new(tracking_info_params)
|
|
82
|
+
Deliveries::TrackingInfo.new(**tracking_info_params)
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
def pickup_info(tracking_code:, **)
|
|
@@ -89,7 +89,7 @@ module Deliveries
|
|
|
89
89
|
|
|
90
90
|
tracking_info_params = Pickups::Trace::FormatResponse.new(response: response).execute
|
|
91
91
|
|
|
92
|
-
Deliveries::TrackingInfo.new(tracking_info_params)
|
|
92
|
+
Deliveries::TrackingInfo.new(**tracking_info_params)
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
def get_label(tracking_code:, **)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
|
|
3
|
+
module Deliveries
|
|
4
|
+
module Couriers
|
|
5
|
+
module Envialia
|
|
6
|
+
module Authentication
|
|
7
|
+
include HTTParty
|
|
8
|
+
|
|
9
|
+
def session_id
|
|
10
|
+
response = HTTParty.post(
|
|
11
|
+
login_endpoint,
|
|
12
|
+
body: login_body,
|
|
13
|
+
headers: login_headers,
|
|
14
|
+
debug_output: Deliveries.debug ? Deliveries.logger : nil
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
raise Deliveries::ClientError unless response.success?
|
|
18
|
+
|
|
19
|
+
response.dig('Envelope', 'Header', 'ROClientIDHeader', 'ID')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def login_body
|
|
23
|
+
<<~XML
|
|
24
|
+
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
|
|
25
|
+
<soapenv:Body>
|
|
26
|
+
<tns:LoginWSService___LoginCli2 xmlns:tns="http://tempuri.org/">
|
|
27
|
+
<strCodAge>#{Deliveries.courier(:envialia).config(:agency_code)}</strCodAge>
|
|
28
|
+
<strCliente>#{Deliveries.courier(:envialia).config(:username)}</strCliente>
|
|
29
|
+
<strPass>#{Deliveries.courier(:envialia).config(:password)}</strPass>
|
|
30
|
+
</tns:LoginWSService___LoginCli2>
|
|
31
|
+
</soapenv:Body>
|
|
32
|
+
</soapenv:Envelope>
|
|
33
|
+
XML
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def login_headers
|
|
37
|
+
{ 'Content-Type' => 'application/json;charset=UTF-8', 'Accept' => 'application/json' }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def login_endpoint
|
|
41
|
+
if Envialia.live?
|
|
42
|
+
Envialia::ENVIALIA_LOGIN_ENDPOINT_LIVE
|
|
43
|
+
else
|
|
44
|
+
Envialia::ENVIALIA_LOGIN_ENDPOINT_TEST
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
|
|
3
|
+
module Deliveries
|
|
4
|
+
module Couriers
|
|
5
|
+
module Envialia
|
|
6
|
+
module Labels
|
|
7
|
+
class Generate
|
|
8
|
+
include HTTParty
|
|
9
|
+
include Authentication
|
|
10
|
+
|
|
11
|
+
attr_accessor :tracking_codes
|
|
12
|
+
|
|
13
|
+
def initialize(tracking_codes:)
|
|
14
|
+
self.tracking_codes = tracking_codes.respond_to?(:each) ? tracking_codes : [tracking_codes]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def execute
|
|
18
|
+
decoded_labels = []
|
|
19
|
+
|
|
20
|
+
tracking_codes.each do |tracking_code|
|
|
21
|
+
response = self.class.post(
|
|
22
|
+
api_endpoint,
|
|
23
|
+
body: body(tracking_code),
|
|
24
|
+
headers: headers,
|
|
25
|
+
debug_output: Deliveries.debug ? Deliveries.logger : nil
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
raise Deliveries::ClientError unless response.success?
|
|
29
|
+
|
|
30
|
+
labels = response.dig('Envelope', 'Body', 'WebServService___ConsEtiquetaEnvio6Response', 'strEtiquetas')
|
|
31
|
+
|
|
32
|
+
if labels.blank?
|
|
33
|
+
raise Deliveries::APIError.new(
|
|
34
|
+
'No hay etiqutas disponibles',
|
|
35
|
+
404
|
|
36
|
+
)
|
|
37
|
+
else
|
|
38
|
+
decoded_labels << Base64.decode64(labels).force_encoding('binary')
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
decoded_labels
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def body(tracking_code)
|
|
48
|
+
<<~XML
|
|
49
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
50
|
+
<soap:Envelope
|
|
51
|
+
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
|
|
52
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
53
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
|
54
|
+
<soap:Header>
|
|
55
|
+
<ROClientIDHeader xmlns="http://tempuri.org/">
|
|
56
|
+
<ID>#{session_id}</ID>
|
|
57
|
+
</ROClientIDHeader>
|
|
58
|
+
</soap:Header>
|
|
59
|
+
<soap:Body>
|
|
60
|
+
<WebServService___ConsEtiquetaEnvio6>
|
|
61
|
+
<strCodAgeOri>#{Deliveries.courier(:envialia).config(:agency_code)}</strCodAgeOri>
|
|
62
|
+
<strAlbaran>#{tracking_code}</strAlbaran>
|
|
63
|
+
<strBulto></strBulto>
|
|
64
|
+
<boPaginaA4>false</boPaginaA4>
|
|
65
|
+
<intNumEtiqImpresasA4>0</intNumEtiqImpresasA4>
|
|
66
|
+
<strFormato>PDF</strFormato>
|
|
67
|
+
</WebServService___ConsEtiquetaEnvio6>
|
|
68
|
+
</soap:Body>
|
|
69
|
+
</soap:Envelope>
|
|
70
|
+
XML
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def headers
|
|
74
|
+
{ 'Content-Type' => 'application/json;charset=UTF-8', 'Accept' => 'application/json' }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def api_endpoint
|
|
78
|
+
if Envialia.live?
|
|
79
|
+
Envialia::ENVIALIA_ENDPOINT_LIVE
|
|
80
|
+
else
|
|
81
|
+
Envialia::ENVIALIA_ENDPOINT_TEST
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
|
|
3
|
+
module Deliveries
|
|
4
|
+
module Couriers
|
|
5
|
+
module Envialia
|
|
6
|
+
module Pickups
|
|
7
|
+
class Create
|
|
8
|
+
include HTTParty
|
|
9
|
+
include Authentication
|
|
10
|
+
|
|
11
|
+
attr_accessor :sender, :receiver, :parcels,
|
|
12
|
+
:reference_code, :pickup_date, :remarks, :tracking_code
|
|
13
|
+
|
|
14
|
+
def initialize(sender:, receiver:, parcels:,
|
|
15
|
+
reference_code:, pickup_date:, remarks:, tracking_code:)
|
|
16
|
+
|
|
17
|
+
self.sender = sender
|
|
18
|
+
self.receiver = receiver
|
|
19
|
+
self.parcels = parcels
|
|
20
|
+
self.reference_code = reference_code
|
|
21
|
+
self.pickup_date = pickup_date
|
|
22
|
+
self.remarks = remarks
|
|
23
|
+
self.tracking_code = tracking_code
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def execute
|
|
27
|
+
response = self.class.post(
|
|
28
|
+
api_endpoint,
|
|
29
|
+
body: body,
|
|
30
|
+
headers: headers,
|
|
31
|
+
debug_output: Deliveries.debug ? Deliveries.logger : nil
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
raise Deliveries::ClientError unless response.success?
|
|
35
|
+
|
|
36
|
+
pickup_number = response.dig('Envelope', 'Body', 'WebServService___GrabaRecogida3Response', 'strCodOut')
|
|
37
|
+
|
|
38
|
+
if pickup_number
|
|
39
|
+
Deliveries::Pickup.new(
|
|
40
|
+
courier_id: 'envialia',
|
|
41
|
+
sender: sender,
|
|
42
|
+
receiver: receiver,
|
|
43
|
+
parcels: parcels,
|
|
44
|
+
reference_code: reference_code,
|
|
45
|
+
tracking_code: pickup_number,
|
|
46
|
+
pickup_date: pickup_date
|
|
47
|
+
)
|
|
48
|
+
else
|
|
49
|
+
exception = response.dig('Envelope', 'Body', 'Fault')
|
|
50
|
+
|
|
51
|
+
if exception['faultcode'].eql?('Exception')
|
|
52
|
+
exception_code, exception_str = exception['faultstring'].split(':')
|
|
53
|
+
else
|
|
54
|
+
exception_code = 400
|
|
55
|
+
exception_str = exception['faultstring']
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
raise Deliveries::APIError.new(
|
|
59
|
+
exception_str.strip,
|
|
60
|
+
exception_code.to_i
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
|
|
67
|
+
def body
|
|
68
|
+
<<~XML
|
|
69
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
|
70
|
+
<soap:Header>
|
|
71
|
+
<ROClientIDHeader xmlns="http://tempuri.org/">
|
|
72
|
+
<ID>#{session_id}</ID>
|
|
73
|
+
</ROClientIDHeader>
|
|
74
|
+
</soap:Header>
|
|
75
|
+
<soap:Body>
|
|
76
|
+
<WebServService___GrabaRecogida3 xmlns="http://tempuri.org/">
|
|
77
|
+
<strCod></strCod>
|
|
78
|
+
<strAlbaran>#{tracking_code}</strAlbaran>
|
|
79
|
+
<strCodAgeCargo>#{Deliveries.courier(:envialia).config(:agency_code)}</strCodAgeCargo>
|
|
80
|
+
<strCodAgeOri></strCodAgeOri>
|
|
81
|
+
<dtFecRec>#{pickup_date.strftime('%Y/%m/%d')}</dtFecRec>
|
|
82
|
+
<strNomOri>#{sender.name}</strNomOri>
|
|
83
|
+
<strPobOri>#{sender.city}</strPobOri>
|
|
84
|
+
<strDirOri>#{sender.street}</strDirOri>
|
|
85
|
+
<strCPOri>#{format_postcode(sender.postcode, sender.country)}</strCPOri>
|
|
86
|
+
<strTlfOri>#{sender.phone}</strTlfOri>
|
|
87
|
+
<strNomDes>#{receiver.name}</strNomDes>
|
|
88
|
+
<strPobDes>#{receiver.city}</strPobDes>
|
|
89
|
+
<strDirDes>#{receiver.street}</strDirDes>
|
|
90
|
+
<strCPDes>#{format_postcode(receiver.postcode, receiver.country)}</strCPDes>
|
|
91
|
+
<strTlfDes>#{receiver.phone}</strTlfDes>
|
|
92
|
+
<strCodPais>#{receiver.country}</strCodPais>
|
|
93
|
+
<intBul>#{parcels}</intBul>
|
|
94
|
+
<strCodTipoServ>72</strCodTipoServ>
|
|
95
|
+
<dPesoOri>0</dPesoOri>
|
|
96
|
+
<dAltoOri>0</dAltoOri>
|
|
97
|
+
<dAnchoOri>0</dAnchoOri>
|
|
98
|
+
<dLargoOri>0</dLargoOri>
|
|
99
|
+
<dReembolso>0</dReembolso>
|
|
100
|
+
<dValor>0</dValor>
|
|
101
|
+
<dAnticipo>0</dAnticipo>
|
|
102
|
+
<dCobCli>0</dCobCli>
|
|
103
|
+
<strObs>#{remarks}</strObs>
|
|
104
|
+
<boSabado>false</boSabado>
|
|
105
|
+
<boRetorno>false</boRetorno>
|
|
106
|
+
<boGestOri>false</boGestOri>
|
|
107
|
+
<boGestDes>false</boGestDes>
|
|
108
|
+
<boAnulado>false</boAnulado>
|
|
109
|
+
<boAcuse>false</boAcuse>
|
|
110
|
+
<strRef>#{reference_code}</strRef>
|
|
111
|
+
<dBaseImp>0</dBaseImp>
|
|
112
|
+
<dImpuesto>0</dImpuesto>
|
|
113
|
+
<boPorteDebCli>false</boPorteDebCli>
|
|
114
|
+
<strDesDirEmails>#{receiver.email}</strDesDirEmails>
|
|
115
|
+
<boCampo5>false</boCampo5>
|
|
116
|
+
<boPagoDUAImp>false</boPagoDUAImp>
|
|
117
|
+
<boPagoImpDes>false</boPagoImpDes>
|
|
118
|
+
</WebServService___GrabaRecogida3>
|
|
119
|
+
</soap:Body>
|
|
120
|
+
</soap:Envelope>
|
|
121
|
+
XML
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def headers
|
|
125
|
+
{ 'Content-Type' => 'application/json;charset=UTF-8', 'Accept' => 'application/json' }
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def api_endpoint
|
|
129
|
+
if Envialia.live?
|
|
130
|
+
Envialia::ENVIALIA_ENDPOINT_LIVE
|
|
131
|
+
else
|
|
132
|
+
Envialia::ENVIALIA_ENDPOINT_TEST
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def format_postcode(postcode, country)
|
|
137
|
+
if country.to_sym.downcase == :pt
|
|
138
|
+
postcode&.split('-')&.first
|
|
139
|
+
else
|
|
140
|
+
postcode
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|