Skip to content

Commit

Permalink
Add custom id field on Address to use by couriers that support it
Browse files Browse the repository at this point in the history
  • Loading branch information
raulr committed Nov 3, 2021
1 parent 81bbd12 commit 99fe6d5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- `Address` can now include a custom id for couriers that support it (currently only Correos Express).

## [0.1.1] - 2021-10-11
### Fixed
Expand Down
3 changes: 2 additions & 1 deletion lib/deliveries/address.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Deliveries
class Address
attr_accessor :name, :email, :phone, :country, :state, :city, :street, :postcode
attr_accessor :name, :email, :phone, :country, :state, :city, :street, :postcode, :address_id

COUNTRY_PHONE_PREFIXES = {
be: 32,
Expand Down Expand Up @@ -30,6 +30,7 @@ def initialize(**attributes)
self.city = attributes[:city]
self.street = attributes[:street]
self.postcode = attributes[:postcode]
self.address_id = attributes[:address_id]
end

def courierize(courier_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def execute
refRecogida: reference_code,
fechaRecogida: pickup_date&.strftime('%d%m%Y') || '',
clienteRecogida: CorreosExpress.config(:pickup_receiver_code),
codRemit: '',
codRemit: sender.address_id || '',
nomRemit: sender.name,
nifRemit: '',
dirRecog: sender.street,
Expand All @@ -34,7 +34,7 @@ def execute
contRecog: sender.name,
tlfnoRecog: sender.phone,
emailRecog: sender.email,
codDest: CorreosExpress.config(:pickup_receiver_code),
codDest: receiver.address_id || CorreosExpress.config(:pickup_receiver_code),
nomDest: receiver.name,
dirDest: receiver.street,
pobDest: receiver.city,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize(sender:, receiver:, collection_point:, parcels:,
def execute
params = {
solicitante: CorreosExpress.config(:client_code),
codRte: CorreosExpress.config(:shipment_sender_code),
codRte: sender.address_id || CorreosExpress.config(:shipment_sender_code),
ref: reference_code,
fecha: format_date(shipment_date),
nomRte: sender.name,
Expand All @@ -33,6 +33,7 @@ def execute
contacRte: sender.name,
telefRte: sender.phone,
emailRte: sender.email,
codDest: receiver.address_id || '',
nomDest: receiver.name,
dirDest: receiver.street,
pobDest: receiver.city,
Expand Down

0 comments on commit 99fe6d5

Please sign in to comment.