Class: SolidusInvoice::InvoiceJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/solidus_invoice/invoice_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(*args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/jobs/solidus_invoice/invoice_job.rb', line 8

def perform(*args)
  opts = args[0]
  invoice = Spree::Invoice.find(opts[:invoice_id])
  env = opts[:env]

  sunat_invoice = invoice.build_sunat_invoice

  if invoice.doc_type == '01'
    # send to SUNAT
    client = SunatInvoice::InvoiceClient.new(env)
    response = client.dispatch(sunat_invoice)
    invoice.update(communicated: true) if response.success?
  end
end