Class: Edi::MiraklSeller::ConfirmMessageSender

Inherits:
BaseEdiService show all
Defined in:
app/services/edi/mirakl_seller/confirm_message_sender.rb

Constant Summary

Constants included from AddressAbbreviator

AddressAbbreviator::MAX_LENGTH

Instance Attribute Summary

Attributes inherited from BaseEdiService

#orchestrator

Instance Method Summary collapse

Methods inherited from BaseEdiService

#duplicate_po_already_notified?, #initialize, #mark_duplicate_po_as_notified, #report_order_creation_issues, #safe_process_edi_communication_log

Methods included from AddressAbbreviator

#abbreviate_street, #collect_street_originals, #record_address_abbreviation_notes

Methods inherited from BaseService

#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger

Constructor Details

This class inherits a constructor from Edi::BaseEdiService

Instance Method Details

#process(edi_communication_logs = nil) ⇒ Object

Retrieves messages according to the partner config



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/edi/mirakl_seller/confirm_message_sender.rb', line 6

def process(edi_communication_logs = nil)
  edi_communication_logs ||= EdiCommunicationLog.requiring_processing.where(partner: orchestrator.partner).where(category: :order_confirm).order(:created_at)
  [edi_communication_logs].flatten.each do |edi_log|
    transport = Transport::MiraklTransporter.new({ profile: orchestrator.transporter_profile })
    order = edi_log.edi_documents.where.not(order_id: nil).first.order
    remote_path = orchestrator.tracking_advice_remote_path.gsub! '{order_id}', order.edi_transaction_id
    logger.info "Sending #{edi_log.category} data #{edi_log.data} to #{remote_path} using transporter method: puts using profile #{orchestrator.transporter_profile}"
    res = transport.send_data(edi_log.data, remote_path, 'put')
    edi_log.transmit_datetime = Time.current
    edi_log.notes = "HTTP CODE: #{res[:http_result].try(:code)}, HTTP BODY: #{res[:http_result].try(:body)}"
    logger.info "Result: HTTP CODE: #{res[:http_result].try(:code)}, HTTP BODY: #{res[:http_result].try(:body)}"
    if res[:success]
      confirm_remote_path = orchestrator.validate_shipping_remote_path.gsub! '{order_id}', order.edi_transaction_id
      logger.info "Sending #{edi_log.category} data #{edi_log.data} to #{confirm_remote_path} using transporter method: puts using profile #{orchestrator.transporter_profile}"
      transport.send_data(nil, confirm_remote_path, 'put')
      edi_log.complete!
    else
      edi_log.error
    end
  end
end