Class: PagSeguro::Order
- Inherits:
-
Object
- Object
- PagSeguro::Order
- 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
-
#billing ⇒ Object
The billing info that will be sent to PagSeguro.
-
#products ⇒ Object
The list of products added to the order.
-
#shipping_type ⇒ Object
Define the shipping type.
Instance Method Summary collapse
-
#<<(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).
- #add(options) ⇒ Object
-
#id ⇒ Object
Get the order identifier.
-
#id=(identifier) ⇒ Object
Set the order identifier.
-
#initialize(order_id = nil) ⇒ Order
constructor
A new instance of Order.
-
#reset! ⇒ Object
Remove all products from this order.
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
#billing ⇒ Object
The billing info that will be sent to PagSeguro.
23 24 25 |
# File 'lib/pagseguro/order.rb', line 23 def billing @billing end |
#products ⇒ Object
The list of products added to the order
20 21 22 |
# File 'lib/pagseguro/order.rb', line 20 def products @products end |
#shipping_type ⇒ Object
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 <<() = { :weight => nil, :shipping => nil, :fees => nil, :quantity => 1 }.merge() # convert shipping to cents [:shipping] = convert_unit([:shipping], 100) # convert fees to cents [:fees] = convert_unit([:fees], 100) # convert price to cents [:price] = convert_unit([:price], 100) # convert weight to grammes [:weight] = convert_unit([:weight], 1000) products.push() end |
#add(options) ⇒ Object
83 84 85 |
# File 'lib/pagseguro/order.rb', line 83 def add() self << end |
#id ⇒ Object
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 |