Class: Ticketbai::Operations::IssuanceUnsigned

Inherits:
Object
  • Object
show all
Defined in:
lib/ticketbai/operations/issuance_unsigned.rb

Overview

In this operation, the document is not signed and it is not encoded in Base64 when making the request to the API as issuance and annulment operations, instead it is directly appended to the tag FacturaEmitida of the api payload document.

Constant Summary collapse

OPERATION_NAME =
:issuance_unsigned

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ IssuanceUnsigned

Returns a new instance of IssuanceUnsigned.

Parameters:

  • receiver_nif (String)

    Spanish NIF or official identification document in case of being another country

  • receiver_name (String)

    Name of the receiver

  • receiver_country (String)

    Country code of the receiver (Ex: ES|DE)

  • receiver_in_eu (Boolean)

    The receiver residence is in Europe?

  • invoice_serial (String)

    Invoices serial number

  • invoice_number (String)

    Invoices number

  • invoice_date (String)

    Invoices emission date (Format: d-m-Y)

  • simplified_invoice (Boolean)

    is a simplified invoice?

  • invoice_description (String)

    Invoices description text

  • invoice_total (String)

    Total invoice amount

  • invoice_vat_key (String)

    Key of the VAT regime

  • invoice_amount (String)

    Taxable base of the invoice

  • invoice_vat (Float)

    Invoice VAT (Ex: 21.0)

  • invoice_vat_total (String)

    Invoices number



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ticketbai/operations/issuance_unsigned.rb', line 33

def initialize(**args)
  @receiver_nif = args[:receiver_nif].strip
  @receiver_name = args[:receiver_name]
  @receiver_country = args[:receiver_country]&.upcase || 'ES'
  @receiver_in_eu = args[:receiver_in_eu]
  @invoice_serial = args[:invoice_serial]
  @invoice_number = args[:invoice_number]
  @invoice_date = args[:invoice_date]
  @simplified_invoice = args[:simplified_invoice]
  @invoice_description = args[:invoice_description]
  @invoice_total = args[:invoice_total]
  @invoice_vat_key = args[:invoice_vat_key]
  @invoice_amount = args[:invoice_amount]
  @invoice_vat = args[:invoice_vat]
  @invoice_vat_total = args[:invoice_vat_total]
end

Instance Attribute Details

#invoice_amountObject (readonly)

Factura > TipoDesglose



13
14
15
# File 'lib/ticketbai/operations/issuance_unsigned.rb', line 13

def invoice_amount
  @invoice_amount
end

#invoice_dateObject (readonly)

Factura > CabeceraFactura



9
10
11
# File 'lib/ticketbai/operations/issuance_unsigned.rb', line 9

def invoice_date
  @invoice_date
end

#invoice_descriptionObject (readonly)

Factura > DatosFactura



11
12
13
# File 'lib/ticketbai/operations/issuance_unsigned.rb', line 11

def invoice_description
  @invoice_description
end

#invoice_numberObject (readonly)

Factura > CabeceraFactura



9
10
11
# File 'lib/ticketbai/operations/issuance_unsigned.rb', line 9

def invoice_number
  @invoice_number
end

#invoice_serialObject (readonly)

Factura > CabeceraFactura



9
10
11
# File 'lib/ticketbai/operations/issuance_unsigned.rb', line 9

def invoice_serial
  @invoice_serial
end

#invoice_timeObject (readonly)

Factura > CabeceraFactura



9
10
11
# File 'lib/ticketbai/operations/issuance_unsigned.rb', line 9

def invoice_time
  @invoice_time
end

#invoice_totalObject (readonly)

Factura > DatosFactura



11
12
13
# File 'lib/ticketbai/operations/issuance_unsigned.rb', line 11

def invoice_total
  @invoice_total
end

#invoice_vatObject (readonly)

Factura > TipoDesglose



13
14
15
# File 'lib/ticketbai/operations/issuance_unsigned.rb', line 13

def invoice_vat
  @invoice_vat
end

#invoice_vat_keyObject (readonly)

Factura > DatosFactura



11
12
13
# File 'lib/ticketbai/operations/issuance_unsigned.rb', line 11

def invoice_vat_key
  @invoice_vat_key
end

#invoice_vat_totalObject (readonly)

Factura > TipoDesglose



13
14
15
# File 'lib/ticketbai/operations/issuance_unsigned.rb', line 13

def invoice_vat_total
  @invoice_vat_total
end

#receiver_nameObject (readonly)

Sujetos > Destinatario



7
8
9
# File 'lib/ticketbai/operations/issuance_unsigned.rb', line 7

def receiver_name
  @receiver_name
end

#receiver_nifObject (readonly)

Sujetos > Destinatario



7
8
9
# File 'lib/ticketbai/operations/issuance_unsigned.rb', line 7

def receiver_nif
  @receiver_nif
end

Instance Method Details

#build_documentObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ticketbai/operations/issuance_unsigned.rb', line 54

def build_document
  if @receiver_nif && @receiver_name
    @receiver = Ticketbai::Nodes::Receiver.new(receiver_country: @receiver_country, receiver_nif: @receiver_nif, receiver_name: @receiver_name)
  end

  @invoice_header = Ticketbai::Nodes::InvoiceHeader.new(
    invoice_serial: @invoice_serial,
    invoice_number: @invoice_number,
    invoice_date: @invoice_date,
    invoice_time: @invoice_time,
    simplified_invoice: @simplified_invoice
  )
  @invoice_data = Ticketbai::Nodes::InvoiceData.new(
    invoice_description: @invoice_description,
    invoice_total: @invoice_total,
    invoice_vat_key: @invoice_vat_key
  )
  @breakdown_type = Ticketbai::Nodes::BreakdownType.new(
    receiver_country: @receiver_country,
    invoice_amount: @invoice_amount,
    invoice_vat: @invoice_vat,
    invoice_vat_total: @invoice_vat_total,
    receiver_in_eu: @receiver_in_eu,
    simplified_invoice: @simplified_invoice
  )

  Ticketbai::Documents::IssuanceUnsigned.new(
    receiver: @receiver,
    invoice_header: @invoice_header,
    invoice_data: @invoice_data,
    breakdown_type: @breakdown_type
  ).create
end

#createObject



50
51
52
# File 'lib/ticketbai/operations/issuance_unsigned.rb', line 50

def create
  build_document
end