Module: Deliveries::Couriers::MondialRelay
- Extended by:
- Deliveries::Courier
- Defined in:
- lib/deliveries/couriers/mondial_relay.rb,
lib/deliveries/couriers/mondial_relay/address.rb,
lib/deliveries/couriers/mondial_relay/status_codes.rb,
lib/deliveries/couriers/mondial_relay/labels/generate.rb,
lib/deliveries/couriers/mondial_relay/shipments/trace.rb,
lib/deliveries/couriers/mondial_relay/shipments/create.rb,
lib/deliveries/couriers/mondial_relay/shipments/create/defaults.rb,
lib/deliveries/couriers/mondial_relay/pickups/create/format_params.rb,
lib/deliveries/couriers/mondial_relay/shipments/create/format_params.rb,
lib/deliveries/couriers/mondial_relay/shipments/trace/format_response.rb,
lib/deliveries/couriers/mondial_relay/collection_points/search/format_response.rb
Defined Under Namespace
Modules: CollectionPoints, Labels, Pickups, Shipments, StatusCodes Classes: Address, Config
Constant Summary collapse
- WSDL_ENDPOINT =
'http://api.mondialrelay.com/Web_Services.asmx?WSDL'.freeze
- STATUS_CODES =
{ 0 => 'Successful operation', 1 => 'Incorrect merchant', 2 => 'Merchant number empty', 3 => 'Incorrect merchant account number', 5 => 'Incorrect Merchant shipment reference', 7 => 'Incorrect Consignee reference', 8 => 'Incorrect password or hash', 9 => 'Unknown or not unique city', 10 => 'Incorrect type of collection', 11 => 'Point Relais collection number incorrect', 12 => 'Point Relais collection country incorrect', 13 => 'Incorrect type of delivery', 14 => 'Incorrect delivery Point Relais number', 15 => 'Point Relais delivery country incorrect', 20 => 'Incorrect parcel weight', 21 => 'Incorrect developped lenght (length + height)', 22 => 'Incorrect parcel size', 24 => 'Incorrect shipment number', 26 => 'Incorrect assembly time', 27 => 'Incorrect mode of collection or delivery', 28 => 'Incorrect mode of collection', 29 => 'Incorrect mode of delivery', 30 => 'Incorrect address (L1)', 31 => 'Incorrect address (L2)', 33 => 'Incorrect address (L3)', 34 => 'Incorrect address (L4)', 35 => 'Incorrect city', 36 => 'Incorrect zip code', 37 => 'Incorrect country', 38 => 'Incorrect phone number', 39 => 'Incorrect e-mail', 40 => 'Missing parameters', 42 => 'Incorrect COD value', 43 => 'Incorrect COD currency', 44 => 'Incorrect shipment value', 45 => 'Incorrect shipment value currency', 46 => 'End of shipments number range reached', 47 => 'Incorrect number of parcels', 48 => 'Multi-Parcel not permitted at Point Relais', 49 => 'Incorrect action', 60 => 'Incorrect text field (this error code has no impact)', 61 => 'Incorrect notification request', 62 => 'Incorrect extra delivery information', 63 => 'Incorrect insurance', 64 => 'Incorrect assembly time', 65 => 'Incorrect appointement', 66 => 'Incorrect take back', 67 => 'Incorrect latitude', 68 => 'Incorrect longitude', 69 => 'Incorrect merchant code', 70 => 'Incorrect Point Relais number', 71 => 'Incorrect Nature de point de vente non valide', 74 => 'Incorrect language', 78 => 'Incorrect country of collection', 79 => 'Incorrect country of delivery', 80 => 'Tracking code : Recorded parcel', 81 => 'Tracking code : Parcel in process at Mondial Relay', 82 => 'Tracking code : Delivered parcel', 83 => 'Tracking code : Anomaly', 84 => '(Reserved tracking code)', 85 => '(Reserved tracking code)', 86 => '(Reserved tracking code)', 87 => '(Reserved tracking code)', 88 => '(Reserved tracking code)', 89 => '(Reserved tracking code)', 92 => 'The Point Relais country code and the consignee’s country code are different', 93 => 'No information given by the sorting plan', 94 => 'Unknown parcel', 95 => 'Merchant account not activated', 97 => 'Incorrect security key', 98 => 'Generic error (Incorrect parameters)', 99 => 'Generic error of service system (technical). Contact MR' }.freeze
Class Method Summary collapse
- .api_client ⇒ Object
- .calculate_security_param(params) ⇒ Object
- .create_pickup(sender:, receiver:, parcels:, reference_code:, pickup_date: nil, remarks: nil, language: 'FR') ⇒ Object
- .create_shipment(sender:, receiver:, parcels:, reference_code:, collection_point: nil, shipment_date: nil, remarks: nil, language: 'FR') ⇒ Object
- .get_collection_point(global_point_id:) ⇒ Object
- .get_collection_points(country:, postcode:) ⇒ Object
- .get_label(tracking_code:, language: 'FR') ⇒ Object
- .get_labels(tracking_codes:, language: 'FR') ⇒ Object
- .pickup_info(tracking_code:, language: 'FR') ⇒ Object
- .shipment_info(tracking_code:, language: 'FR') ⇒ Object
Methods included from Deliveries::Courier
config, configure, configured?, live?, test?
Class Method Details
.api_client ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/deliveries/couriers/mondial_relay.rb', line 27 def api_client Savon.client( wsdl: WSDL_ENDPOINT, logger: Deliveries.logger, log: Deliveries.debug, follow_redirects: true ) end |
.calculate_security_param(params) ⇒ Object
185 186 187 188 189 |
# File 'lib/deliveries/couriers/mondial_relay.rb', line 185 def calculate_security_param(params) Digest::MD5.hexdigest(params.map do |_, v| v end.join + Deliveries::Couriers::MondialRelay.config(:mondial_relay_key)).upcase end |
.create_pickup(sender:, receiver:, parcels:, reference_code:, pickup_date: nil, remarks: nil, language: 'FR') ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/deliveries/couriers/mondial_relay.rb', line 123 def create_pickup(sender:, receiver:, parcels:, reference_code:, pickup_date: nil, remarks: nil, language: 'FR') params = Pickups::Create::FormatParams.new( sender: sender.courierize(:mondial_relay), receiver: receiver.courierize(:mondial_relay), parcels: parcels, reference_code: reference_code, pickup_date: pickup_date, remarks: remarks, language: language ).execute tracking_code, label_url = Shipments::Create.new( params: params ).execute.values_at(:tracking_code, :label_url) Deliveries::Pickup.new( courier_id: 'mondial_relay', sender: sender, receiver: receiver, parcels: parcels, reference_code: reference_code, tracking_code: tracking_code, pickup_date: pickup_date, label: Label.new(url: label_url) ) end |
.create_shipment(sender:, receiver:, parcels:, reference_code:, collection_point: nil, shipment_date: nil, remarks: nil, language: 'FR') ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/deliveries/couriers/mondial_relay.rb', line 96 def create_shipment(sender:, receiver:, parcels:, reference_code:, collection_point: nil, shipment_date: nil, remarks: nil, language: 'FR') params = Shipments::Create::FormatParams.new( sender: sender.courierize(:mondial_relay), receiver: receiver.courierize(:mondial_relay), parcels: parcels, collection_point: collection_point, reference_code: reference_code, remarks: remarks, language: language ).execute tracking_code, label_url = Shipments::Create.new( params: params ).execute.values_at(:tracking_code, :label_url) Deliveries::Shipment.new( courier_id: 'mondial_relay', sender: sender, receiver: receiver, parcels: parcels, reference_code: reference_code, tracking_code: tracking_code, shipment_date: shipment_date, label: Label.new(url: label_url) ) end |
.get_collection_point(global_point_id:) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/deliveries/couriers/mondial_relay.rb', line 66 def get_collection_point(global_point_id:) global_point = Deliveries::CollectionPoint.parse_global_point_id(global_point_id: global_point_id) params = { 'Enseigne' => Deliveries::Couriers::MondialRelay.config(:mondial_relay_merchant), 'Pays' => global_point.country, 'NumPointRelais' => global_point.point_id, 'Ville' => '', 'CP' => '', 'Latitude' => '', 'Longitude' => '', 'Taille' => '', 'Poids' => '', 'Action' => '', 'DelaiEnvoi' => '0', 'RayonRecherche' => '', 'TypeActivite' => '', 'NACE' => '' } # Calculate security parameters. params['Security'] = calculate_security_param params response = api_client.call :wsi3_point_relais_recherche, message: params response_result = response.body.dig(:wsi3_point_relais_recherche_response, :wsi3_point_relais_recherche_result) point_relais_details = response_result.dig(:points_relais, :point_relais_details) if response_result[:stat] == '0' && point_relais_details.present? collection_point_params = CollectionPoints::Search::FormatResponse.new(response: point_relais_details).execute Deliveries::CollectionPoint.new(**collection_point_params) else raise Deliveries::APIError.new( StatusCodes.(response_result[:stat].to_i), response_result[:stat] ) end end |
.get_collection_points(country:, postcode:) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/deliveries/couriers/mondial_relay.rb', line 36 def get_collection_points(country:, postcode:) # Build params needed by web service. params = { 'Enseigne' => Deliveries::Couriers::MondialRelay.config(:mondial_relay_merchant), 'Pays' => country, 'NumPointRelais' => '', 'Ville' => '', 'CP' => postcode, 'Latitude' => '', 'Longitude' => '', 'Taille' => '', 'Poids' => '', 'Action' => '', 'DelaiEnvoi' => '0', 'RayonRecherche' => '', 'TypeActivite' => '', 'NACE' => '' } # Calculate security parameters. params['Security'] = calculate_security_param params response = api_client.call :wsi3_point_relais_recherche, message: params # If response returns OK stat code. if (response_result = response.body[:wsi3_point_relais_recherche_response][:wsi3_point_relais_recherche_result]) && response_result[:stat] == '0' collection_points = [] [response_result.dig(:points_relais, :point_relais_details)].flatten.compact.each do |point_params| collection_point_params = CollectionPoints::Search::FormatResponse.new(response: point_params).execute collection_points << Deliveries::CollectionPoint.new(**collection_point_params) end collection_points else raise Deliveries::APIError.new( StatusCodes.(response_result[:stat].to_i), response_result[:stat] ) end end |
.get_label(tracking_code:, language: 'FR') ⇒ Object
167 168 169 170 171 172 173 174 |
# File 'lib/deliveries/couriers/mondial_relay.rb', line 167 def get_label(tracking_code:, language: 'FR') label_url = Labels::Generate.new( tracking_codes: tracking_code, language: language ).execute Deliveries::Label.new(url: label_url) end |
.get_labels(tracking_codes:, language: 'FR') ⇒ Object
176 177 178 179 180 181 182 183 |
# File 'lib/deliveries/couriers/mondial_relay.rb', line 176 def get_labels(tracking_codes:, language: 'FR') labels_url = Labels::Generate.new( tracking_codes: tracking_codes, language: language ).execute Deliveries::Labels.new(url: labels_url) end |
.pickup_info(tracking_code:, language: 'FR') ⇒ Object
163 164 165 |
# File 'lib/deliveries/couriers/mondial_relay.rb', line 163 def pickup_info(tracking_code:, language: 'FR') shipment_info(tracking_code: tracking_code, language: language) end |
.shipment_info(tracking_code:, language: 'FR') ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/deliveries/couriers/mondial_relay.rb', line 151 def shipment_info(tracking_code:, language: 'FR') response = Shipments::Trace.new( tracking_code: tracking_code, language: language ).execute tracking_info_params = Shipments::Trace::FormatResponse.new(response: response).execute tracking_info_params = tracking_info_params.merge(tracking_code: tracking_code) Deliveries::TrackingInfo.new(**tracking_info_params) end |