diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fadb4d..e3eed08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/deliveries/address.rb b/lib/deliveries/address.rb index ff63c01..ade10cd 100644 --- a/lib/deliveries/address.rb +++ b/lib/deliveries/address.rb @@ -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, @@ -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) diff --git a/lib/deliveries/couriers/correos_express/pickups/create/format_params.rb b/lib/deliveries/couriers/correos_express/pickups/create/format_params.rb index c325d5c..b37f406 100644 --- a/lib/deliveries/couriers/correos_express/pickups/create/format_params.rb +++ b/lib/deliveries/couriers/correos_express/pickups/create/format_params.rb @@ -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, @@ -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, diff --git a/lib/deliveries/couriers/correos_express/shipments/create/format_params.rb b/lib/deliveries/couriers/correos_express/shipments/create/format_params.rb index 32527aa..b1f65f7 100644 --- a/lib/deliveries/couriers/correos_express/shipments/create/format_params.rb +++ b/lib/deliveries/couriers/correos_express/shipments/create/format_params.rb @@ -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, @@ -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,