Class: MerchantSidekick::SalesInvoice

Inherits:
Invoice
  • Object
show all
Defined in:
lib/merchant_sidekick/sales_invoice.rb

Instance Attribute Summary

Attributes inherited from Invoice

#authorization

Instance Method Summary collapse

Methods inherited from Invoice

#enter_authorized, #enter_paid, #enter_payment_declined, #enter_pending, #enter_refunded, #enter_voided, #evaluate, #exit_authorized, #exit_paid, #exit_payment_declined, #exit_pending, #exit_refunded, #exit_voided, #gross_total, #guard_payment_authorized_from_payment_declined, #guard_payment_authorized_from_pending, #guard_payment_captured_from_authorized, #guard_payment_paid_from_pending, #guard_payment_refunded_from_paid, #guard_payment_voided_from_authorized, #guard_transaction_declined_from_authorized, #guard_transaction_declined_from_payment_declined, #guard_transaction_declined_from_pending, #net_total, #number, #payment_type, #payment_type_display, #tax_total, #total

Instance Method Details

#cash(payment_object, options = {}) ⇒ Object

cash invoice, combines authorization and capture in one step



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/merchant_sidekick/sales_invoice.rb', line 14

def cash(payment_object, options={})
  transaction do
    cash_result = MerchantSidekick::Payment.class_for(payment_object).transfer(
      gross_total,
      payment_object,
      payment_options(options)
    )
    self.push_payment(cash_result)

    save(:validate => false)

    if cash_result.success?
      payment_paid!
    else
      transaction_declined!
    end
    cash_result
  end
end

#payment_options(options = {}) ⇒ Object

returns a hash of additional merchant data passed to authorize you want to pass in the following additional options

:ip => ip address of the buyer


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/merchant_sidekick/sales_invoice.rb', line 39

def payment_options(options={})
  { # general
    :buyer => self.buyer,
    :seller => self.seller,
    :payable => self,
    # active merchant relevant
    :customer => "#{self.seller.name} (#{self.seller.id})",
    :email => self.seller && self.seller.respond_to?(:email) ? self.seller.email : nil,
    :invoice => self.number,
    :merchant => self.buyer ? "#{self.buyer.name} (#{self.buyer.id})" : nil,
    :currency => self.currency,
    :billing_address => self.billing_address ? self.billing_address.to_merchant_attributes : nil,
    :shipping_address =>  self.shipping_address ? self.shipping_address.to_merchant_attributes : nil
  }.merge(options)
end

#sales_invoice?Boolean

— instance methods

Returns:

  • (Boolean)


9
10
11
# File 'lib/merchant_sidekick/sales_invoice.rb', line 9

def sales_invoice?
  true
end