Class: Apruve::Order
- Inherits:
-
ApruveObject
- Object
- ApruveObject
- Apruve::Order
- Defined in:
- lib/apruve/resources/order.rb
Instance Attribute Summary collapse
-
#accepts_payment_terms ⇒ Object
Returns the value of attribute accepts_payment_terms.
-
#accepts_payments_via ⇒ Object
Returns the value of attribute accepts_payments_via.
-
#amount_cents ⇒ Object
Returns the value of attribute amount_cents.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#default_payment_method ⇒ Object
Returns the value of attribute default_payment_method.
-
#expire_at ⇒ Object
Returns the value of attribute expire_at.
-
#final_state_at ⇒ Object
Returns the value of attribute final_state_at.
-
#finalize_on_create ⇒ Object
Returns the value of attribute finalize_on_create.
-
#id ⇒ Object
Returns the value of attribute id.
-
#invoice_on_create ⇒ Object
Returns the value of attribute invoice_on_create.
-
#links ⇒ Object
Returns the value of attribute links.
-
#merchant_id ⇒ Object
Returns the value of attribute merchant_id.
-
#merchant_order_id ⇒ Object
Returns the value of attribute merchant_order_id.
-
#order_items ⇒ Object
Returns the value of attribute order_items.
-
#payment_term ⇒ Object
Returns the value of attribute payment_term.
-
#po_number ⇒ Object
Returns the value of attribute po_number.
-
#secure_hash ⇒ Object
Returns the value of attribute secure_hash.
-
#shipping_cents ⇒ Object
Returns the value of attribute shipping_cents.
-
#shopper_id ⇒ Object
Returns the value of attribute shopper_id.
-
#status ⇒ Object
Returns the value of attribute status.
-
#tax_cents ⇒ Object
Returns the value of attribute tax_cents.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Class Method Summary collapse
- .cancel!(id) ⇒ Object
- .finalize!(id) ⇒ Object
- .find(id) ⇒ Object
- .find_all(merchant_order_id = nil) ⇒ Object
- .find_by_hash(hash) ⇒ Object
- .invoices_for(order_id) ⇒ Object
Instance Method Summary collapse
-
#initialize(params) ⇒ Order
constructor
A new instance of Order.
-
#payment_terms ⇒ Object
The field is actually named ‘payment_term’, but some integrations are currently using ‘payment_terms’.
- #payment_terms=(pt) ⇒ Object
- #save! ⇒ Object
- #update! ⇒ Object
- #validate ⇒ Object
- #value_string ⇒ Object
Methods inherited from ApruveObject
#logger, logger, #to_hash, #to_json
Constructor Details
#initialize(params) ⇒ Order
Returns a new instance of Order.
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/apruve/resources/order.rb', line 58 def initialize(params) super # hydrate line items if appropriate if @order_items.nil? @order_items = [] elsif @order_items.is_a?(Array) && @order_items.first.is_a?(Hash) hydrated_items = [] @order_items.each do |item| hydrated_items << Apruve::OrderItem.new(item) end @order_items = hydrated_items end end |
Instance Attribute Details
#accepts_payment_terms ⇒ Object
Returns the value of attribute accepts_payment_terms.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def accepts_payment_terms @accepts_payment_terms end |
#accepts_payments_via ⇒ Object
Returns the value of attribute accepts_payments_via.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def accepts_payments_via @accepts_payments_via end |
#amount_cents ⇒ Object
Returns the value of attribute amount_cents.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def amount_cents @amount_cents end |
#created_at ⇒ Object
Returns the value of attribute created_at.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def created_at @created_at end |
#currency ⇒ Object
Returns the value of attribute currency.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def currency @currency end |
#default_payment_method ⇒ Object
Returns the value of attribute default_payment_method.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def default_payment_method @default_payment_method end |
#expire_at ⇒ Object
Returns the value of attribute expire_at.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def expire_at @expire_at end |
#final_state_at ⇒ Object
Returns the value of attribute final_state_at.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def final_state_at @final_state_at end |
#finalize_on_create ⇒ Object
Returns the value of attribute finalize_on_create.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def finalize_on_create @finalize_on_create end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def id @id end |
#invoice_on_create ⇒ Object
Returns the value of attribute invoice_on_create.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def invoice_on_create @invoice_on_create end |
#links ⇒ Object
Returns the value of attribute links.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def links @links end |
#merchant_id ⇒ Object
Returns the value of attribute merchant_id.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def merchant_id @merchant_id end |
#merchant_order_id ⇒ Object
Returns the value of attribute merchant_order_id.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def merchant_order_id @merchant_order_id end |
#order_items ⇒ Object
Returns the value of attribute order_items.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def order_items @order_items end |
#payment_term ⇒ Object
Returns the value of attribute payment_term.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def payment_term @payment_term end |
#po_number ⇒ Object
Returns the value of attribute po_number.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def po_number @po_number end |
#secure_hash ⇒ Object
Returns the value of attribute secure_hash.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def secure_hash @secure_hash end |
#shipping_cents ⇒ Object
Returns the value of attribute shipping_cents.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def shipping_cents @shipping_cents end |
#shopper_id ⇒ Object
Returns the value of attribute shopper_id.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def shopper_id @shopper_id end |
#status ⇒ Object
Returns the value of attribute status.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def status @status end |
#tax_cents ⇒ Object
Returns the value of attribute tax_cents.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def tax_cents @tax_cents end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
3 4 5 |
# File 'lib/apruve/resources/order.rb', line 3 def updated_at @updated_at end |
Class Method Details
.cancel!(id) ⇒ Object
46 47 48 49 50 |
# File 'lib/apruve/resources/order.rb', line 46 def self.cancel!(id) response = Apruve.post("orders/#{id}/cancel") logger.debug response.body Order.new(response.body) end |
.finalize!(id) ⇒ Object
31 32 33 34 35 |
# File 'lib/apruve/resources/order.rb', line 31 def self.finalize!(id) response = Apruve.post("orders/#{id}/finalize") logger.debug response.body Order.new(response.body) end |
.find(id) ⇒ Object
8 9 10 11 12 |
# File 'lib/apruve/resources/order.rb', line 8 def self.find(id) response = Apruve.get("orders/#{id}") logger.debug response.body Order.new(response.body) end |
.find_all(merchant_order_id = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/apruve/resources/order.rb', line 14 def self.find_all(merchant_order_id = nil) if merchant_order_id.nil? response = Apruve.get('orders') else response = Apruve.get("orders?merchant_order_id=#{merchant_order_id}") end logger.debug response.body response.body.map { |order| Order.new(order) } end |
.find_by_hash(hash) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/apruve/resources/order.rb', line 24 def self.find_by_hash(hash) response = Apruve.get("orders?secure_hash=#{hash}") logger.debug response.body orders = response.body.map { |order| Order.new(order) } orders.max_by { |order| order.created_at } end |
Instance Method Details
#payment_terms ⇒ Object
The field is actually named ‘payment_term’, but some integrations are currently using ‘payment_terms’. Pass those requests through to the correct attribute.
109 110 111 |
# File 'lib/apruve/resources/order.rb', line 109 def payment_terms self.payment_term end |
#payment_terms=(pt) ⇒ Object
113 114 115 |
# File 'lib/apruve/resources/order.rb', line 113 def payment_terms=(pt) self.payment_term=pt end |
#save! ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/apruve/resources/order.rb', line 78 def save! validate response = Apruve.post('orders', self.to_json) self.id = response.body['id'] self.status = response.body['status'] self.created_at = response.body['created_at'] end |
#update! ⇒ Object
52 53 54 55 56 |
# File 'lib/apruve/resources/order.rb', line 52 def update! response = Apruve.patch("orders/#{id}", {order: self}.to_json ) logger.debug response.body initialize response.body end |
#validate ⇒ Object
72 73 74 75 76 |
# File 'lib/apruve/resources/order.rb', line 72 def validate errors = [] errors << 'merchant_id must be set' if merchant_id.nil? raise Apruve::ValidationError.new(errors) if errors.length > 0 end |
#value_string ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/apruve/resources/order.rb', line 86 def value_string # add each field in the PR str = "#{merchant_id}#{merchant_order_id}#{amount_cents}#{currency}#{tax_cents}#{shipping_cents}#{expire_at}#{accepts_payment_terms}#{finalize_on_create}#{invoice_on_create}" # add the line items self.order_items.each do |item| str += "#{item.title}#{item.plan_code}#{item.price_total_cents}#{item.price_ea_cents}"\ "#{item.quantity}#{item.merchant_notes}#{item.description}#{item.variant_info}#{item.sku}"\ "#{item.vendor}#{item.view_product_url}" end str end |