Class: PagSeguro::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/pagseguro/order.rb

Constant Summary collapse

BILLING_MAPPING =

Map all billing attributes that will be added as form inputs.

{
  :name                  => "cliente_nome",
  :address_zipcode       => "cliente_cep",
  :address_street        => "cliente_end",
  :address_number        => "cliente_num",
  :address_complement    => "cliente_compl",
  :address_neighbourhood => "cliente_bairro",
  :address_city          => "cliente_cidade",
  :address_state         => "cliente_uf",
  :address_country       => "cliente_pais",
  :phone_area_code       => "cliente_ddd",
  :phone_number          => "cliente_tel",
  :email                 => "cliente_email"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order_id = nil) ⇒ Order

Returns a new instance of Order.



29
30
31
32
33
# File 'lib/pagseguro/order.rb', line 29

def initialize(order_id = nil)
  reset!
  self.id = order_id
  self.billing = {}
end

Instance Attribute Details

#billingObject

The billing info that will be sent to PagSeguro.



23
24
25
# File 'lib/pagseguro/order.rb', line 23

def billing
  @billing
end

#productsObject

The list of products added to the order



20
21
22
# File 'lib/pagseguro/order.rb', line 20

def products
  @products
end

#shipping_typeObject

Define the shipping type. Can be EN (PAC) or SD (Sedex)



27
28
29
# File 'lib/pagseguro/order.rb', line 27

def shipping_type
  @shipping_type
end

Instance Method Details

#<<(options) ⇒ Object

Add a new product to the PagSeguro order The allowed values are:

  • weight (Optional. If float, will be multiplied by 1000g)

  • shipping (Optional. If float, will be multiplied by 100 cents)

  • quantity (Optional. Defaults to 1)

  • price (Required. If float, will be multiplied by 100 cents)

  • description (Required. Identifies the product)

  • id (Required. Should match the product on your database)

  • fees (Optional. If float, will be multiplied by 100 cents)



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/pagseguro/order.rb', line 60

def <<(options)
  options = {
    :weight => nil,
    :shipping => nil,
    :fees => nil,
    :quantity => 1
  }.merge(options)

  # convert shipping to cents
  options[:shipping] = convert_unit(options[:shipping], 100)

  # convert fees to cents
  options[:fees] = convert_unit(options[:fees], 100)

  # convert price to cents
  options[:price] = convert_unit(options[:price], 100)

  # convert weight to grammes
  options[:weight] = convert_unit(options[:weight], 1000)

  products.push(options)
end

#add(options) ⇒ Object



83
84
85
# File 'lib/pagseguro/order.rb', line 83

def add(options)
  self << options
end

#idObject

Get the order identifier



42
43
44
# File 'lib/pagseguro/order.rb', line 42

def id
  @id
end

#id=(identifier) ⇒ Object

Set the order identifier. Should be a unique value to identify this order on your own application



37
38
39
# File 'lib/pagseguro/order.rb', line 37

def id=(identifier)
  @id = identifier
end

#reset!Object

Remove all products from this order



47
48
49
# File 'lib/pagseguro/order.rb', line 47

def reset!
  @products = []
end