Class: Edi::MiraklSeller::InvoiceMessageProcessor
- Inherits:
-
BaseEdiService
- Object
- BaseService
- BaseEdiService
- Edi::MiraklSeller::InvoiceMessageProcessor
- Defined in:
- app/services/edi/mirakl_seller/invoice_message_processor.rb
Overview
Service object: invoice message processor.
Constant Summary
Constants included from RequestIdentifiable
RequestIdentifiable::REQUEST_ID_HEADERS
Constants included from AddressAbbreviator
AddressAbbreviator::MAX_LENGTH
Instance Attribute Summary
Attributes inherited from BaseEdiService
Attributes inherited from BaseService
Instance Method Summary collapse
-
#create_invoice(invoice, options = {}) ⇒ EdiCommunicationLog?
The created log.
- #instantiate_transporter(_transporter, transporter_profile = nil) ⇒ Object
Methods inherited from BaseEdiService
#amazon_feed_product_type, #duplicate_po_already_notified?, #initialize, #mark_duplicate_po_as_notified, #onboard_ordered_catalog_items, #report_order_creation_issues, #safe_process_edi_communication_log
Methods included from RequestIdentifiable
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, #process, #tagged_logger
Constructor Details
This class inherits a constructor from Edi::BaseEdiService
Instance Method Details
#create_invoice(invoice, options = {}) ⇒ EdiCommunicationLog?
Returns the created log.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/services/edi/mirakl_seller/invoice_message_processor.rb', line 10 def create_invoice(invoice, = {}) order = invoice.order pdf_upload = invoice.get_or_regen_pdf edi_log = nil h = { order_documents: [ { file_name: pdf_upload., type_code: 'CUSTOMER_INVOICE' } ] } transport = instantiate_transporter(orchestrator.transporter, orchestrator.transporter_profile) EdiCommunicationLog.transaction do edi_log = EdiCommunicationLog.new partner: orchestrator.partner, category: 'invoice', data: h.to_json, data_type: 'json', transmit_after: [:transmit_after] remote_path = orchestrator..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}" = { order_documents: h.to_json, files: HTTP::FormData::File.new(pdf_upload.to_file, filename: pdf_upload.) } res = transport.send_file(remote_path, ) 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] edi_log.complete! edi_log.edi_documents.create!(invoice: invoice) else edi_log.error end end edi_log end |
#instantiate_transporter(_transporter, transporter_profile = nil) ⇒ Object
52 53 54 55 |
# File 'app/services/edi/mirakl_seller/invoice_message_processor.rb', line 52 def instantiate_transporter(_transporter, transporter_profile = nil) # It doesn't matter what we get in the params, mirakl only has 1 transporter Transport::MiraklTransporter.new({ profile: transporter_profile }) end |