Class: Apruve::Invoice
- Inherits:
-
ApruveObject
- Object
- ApruveObject
- Apruve::Invoice
- Defined in:
- lib/apruve/resources/invoice.rb
Instance Attribute Summary collapse
-
#amount_cents ⇒ Object
Returns the value of attribute amount_cents.
-
#amount_due ⇒ Object
Returns the value of attribute amount_due.
-
#bill_to_address ⇒ Object
Returns the value of attribute bill_to_address.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#due_at ⇒ Object
Returns the value of attribute due_at.
-
#final_state_at ⇒ Object
Returns the value of attribute final_state_at.
-
#fiscal_representative ⇒ Object
Returns the value of attribute fiscal_representative.
-
#id ⇒ Object
Returns the value of attribute id.
-
#invoice_items ⇒ Object
Returns the value of attribute invoice_items.
-
#issue_on_create ⇒ Object
Returns the value of attribute issue_on_create.
-
#issued_at ⇒ Object
Returns the value of attribute issued_at.
-
#links ⇒ Object
Returns the value of attribute links.
-
#merchant_invoice_id ⇒ Object
Returns the value of attribute merchant_invoice_id.
-
#merchant_notes ⇒ Object
Returns the value of attribute merchant_notes.
-
#opened_at ⇒ Object
Returns the value of attribute opened_at.
-
#order_id ⇒ Object
Returns the value of attribute order_id.
-
#payments ⇒ Object
Returns the value of attribute payments.
-
#remittance_address ⇒ Object
Returns the value of attribute remittance_address.
-
#ship_to_address ⇒ Object
Returns the value of attribute ship_to_address.
-
#shipping_cents ⇒ Object
Returns the value of attribute shipping_cents.
-
#sold_to_address ⇒ Object
Returns the value of attribute sold_to_address.
-
#status ⇒ Object
Returns the value of attribute status.
-
#tax_cents ⇒ Object
Returns the value of attribute tax_cents.
Class Method Summary collapse
Instance Method Summary collapse
- #cancel! ⇒ Object
- #close! ⇒ Object
-
#initialize(params) ⇒ Invoice
constructor
A new instance of Invoice.
- #issue! ⇒ Object
- #save! ⇒ Object
- #update! ⇒ Object
- #validate ⇒ Object
Methods inherited from ApruveObject
#logger, logger, #to_hash, #to_json
Constructor Details
#initialize(params) ⇒ Invoice
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/apruve/resources/invoice.rb', line 13 def initialize(params) super # hydrate payment items if appropriate if @invoice_items.nil? @invoice_items = [] elsif @invoice_items.is_a?(Array) && @invoice_items.first.is_a?(Hash) hydrated_items = [] @invoice_items.each do |item| hydrated_items << Apruve::OrderItem.new(item) end @invoice_items = hydrated_items end @currency = Apruve.default_currency if currency.nil? end |
Instance Attribute Details
#amount_cents ⇒ Object
Returns the value of attribute amount_cents.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def amount_cents @amount_cents end |
#amount_due ⇒ Object
Returns the value of attribute amount_due.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def amount_due @amount_due end |
#bill_to_address ⇒ Object
Returns the value of attribute bill_to_address.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def bill_to_address @bill_to_address end |
#created_at ⇒ Object
Returns the value of attribute created_at.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def created_at @created_at end |
#currency ⇒ Object
Returns the value of attribute currency.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def currency @currency end |
#due_at ⇒ Object
Returns the value of attribute due_at.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def due_at @due_at end |
#final_state_at ⇒ Object
Returns the value of attribute final_state_at.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def final_state_at @final_state_at end |
#fiscal_representative ⇒ Object
Returns the value of attribute fiscal_representative.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def fiscal_representative @fiscal_representative end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def id @id end |
#invoice_items ⇒ Object
Returns the value of attribute invoice_items.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def invoice_items @invoice_items end |
#issue_on_create ⇒ Object
Returns the value of attribute issue_on_create.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def issue_on_create @issue_on_create end |
#issued_at ⇒ Object
Returns the value of attribute issued_at.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def issued_at @issued_at end |
#links ⇒ Object
Returns the value of attribute links.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def links @links end |
#merchant_invoice_id ⇒ Object
Returns the value of attribute merchant_invoice_id.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def merchant_invoice_id @merchant_invoice_id end |
#merchant_notes ⇒ Object
Returns the value of attribute merchant_notes.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def merchant_notes @merchant_notes end |
#opened_at ⇒ Object
Returns the value of attribute opened_at.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def opened_at @opened_at end |
#order_id ⇒ Object
Returns the value of attribute order_id.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def order_id @order_id end |
#payments ⇒ Object
Returns the value of attribute payments.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def payments @payments end |
#remittance_address ⇒ Object
Returns the value of attribute remittance_address.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def remittance_address @remittance_address end |
#ship_to_address ⇒ Object
Returns the value of attribute ship_to_address.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def ship_to_address @ship_to_address end |
#shipping_cents ⇒ Object
Returns the value of attribute shipping_cents.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def shipping_cents @shipping_cents end |
#sold_to_address ⇒ Object
Returns the value of attribute sold_to_address.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def sold_to_address @sold_to_address end |
#status ⇒ Object
Returns the value of attribute status.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def status @status end |
#tax_cents ⇒ Object
Returns the value of attribute tax_cents.
3 4 5 |
# File 'lib/apruve/resources/invoice.rb', line 3 def tax_cents @tax_cents end |
Class Method Details
Instance Method Details
#cancel! ⇒ Object
64 65 66 67 68 69 |
# File 'lib/apruve/resources/invoice.rb', line 64 def cancel! validate response = Apruve.post("invoices/#{id}/cancel") self.status = response.body['status'] self.status end |
#close! ⇒ Object
57 58 59 60 61 62 |
# File 'lib/apruve/resources/invoice.rb', line 57 def close! validate response = Apruve.post("invoices/#{id}/close") self.status = response.body['status'] self.status end |
#issue! ⇒ Object
50 51 52 53 54 55 |
# File 'lib/apruve/resources/invoice.rb', line 50 def issue! validate response = Apruve.post("invoices/#{id}/issue") self.status = response.body['status'] self.status end |
#save! ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/apruve/resources/invoice.rb', line 35 def save! validate response = Apruve.post('invoices', self.to_json) self.id = response.body['id'] self.status = response.body['status'] self.status end |
#update! ⇒ Object
43 44 45 46 47 48 |
# File 'lib/apruve/resources/invoice.rb', line 43 def update! validate response = Apruve.patch("invoices/#{id}", self.to_json) self.status = response.body['status'] self.status end |
#validate ⇒ Object
28 29 30 31 32 33 |
# File 'lib/apruve/resources/invoice.rb', line 28 def validate errors = [] errors << 'order_id must be set' if order_id.nil? errors << 'amount_cents must be set' if amount_cents.nil? raise Apruve::ValidationError.new(errors) if errors.length > 0 end |