Class: Bling::API::Order

Inherits:
Request show all
Defined in:
lib/bling/api/order.rb

Overview

This class is used to make requests to all available actions related to orders in Bling api. Is strongly recommended to use the Bling::API module wrapper

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Bling::API::Request

Instance Method Details

#create(params) ⇒ Array

Insert a order in Bling

Examples:

order = Bling::API::Order.new.create(
  {
  order_number: '123',
  ecommerce_order_number: 'R123',
  store: 'Foo',
  selling_category: '',
  user: {
   name: 'Jonh Doe',
   company_name: '',
   tax_type: 1,
   document: '35165478662',
   ir_rg: '306153420',
   tax_classification: 1,
   address: 'My great street',
   number: '33',
   additional_address: 'apt 12',
   zipcode: '03454020',
   city: 'Sao Paulo',
   uf: 'SP',
   phone: '(11) 2233-3322',
   cellphone: '(11) 2233-3322',
   email: jonh@@doe.com'
  },
  shipment: {
    carrier: 'Correios',
    shipment_type: 'R'
    shipment_label: {}
  },
  items: [
    { code: '001', description: 'lorem', unit: 'pc', item_quantity: 3, price: 12.30 },
    { code: '002', description: 'lorem', unit: 'pc', item_quantity: 4, price: 32.30 },
  ],
  installments: [
    { date: '28/06/2016', amount: 140.00, additional_info: '' },
    { date: '28/07/2016', amount: 140.00, additional_info: '' },
  ],
  shipment_amount: 10.0,
  discount_amount: 0.0,
  additional_info: '',
  private_additional_info: ''
  }
)

Parameters:

  • params (Hash)

    A hash with order options

Returns:

  • (Array)

    Call order#create and return an array with one record



82
83
84
# File 'lib/bling/api/order.rb', line 82

def create(params)
  post_request(t_url(:order), parsed_xml(params))
end

#get(order_id) ⇒ Array

Get a specific object based on order_id

Examples:

order = Bling::API::order.new.get

Parameters:

  • cpf (String)

    or cnpj from the order in Bling

Returns:

  • (Array)

    Call order#show and return an array with one record



28
29
30
# File 'lib/bling/api/order.rb', line 28

def get(order_id)
  get_request(t_url(:order, order_id))
end

#listArray

Get a list of available orders

Examples:

orders = Bling::API::Order.new.list

Returns:

  • (Array)

    Call orders index and return an array with records



15
16
17
# File 'lib/bling/api/order.rb', line 15

def list
  get_request(t_url(:orders))
end

#put(order_id, status) ⇒ Array

Put an order status update based on order_id

Available statuses

- 0 (Em Aberto)
- 1 (Atendido)
- 2 (Cancelado)
- 3 (Em Andamento)
- 4 (Venda Agenciada)
- 10 (Em Digita

Examples:

order = Bling::API::order.new.update(order_id, status)

Parameters:

  • cpf (String)

    or cnpj from the order in Bling

  • status (Integer)

    number for order in Bling

Returns:

  • (Array)

    Call order#show and return an array with one record

Raises:

  • (ArgumentError)


106
107
108
109
110
# File 'lib/bling/api/order.rb', line 106

def put(order_id, status)
  raise ArgumentError unless [0, 1, 2, 3, 4, 10, 11].include?(status.to_i)
  xml = order_update_template % { status: status.to_i }
  put_request(t_url(:order, order_id), xml)
end