Class: Bean::Payment

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Machine
Defined in:
lib/bean/payment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Machine

included

Instance Attribute Details

#credit_cardObject

Returns the value of attribute credit_card.



9
10
11
# File 'lib/bean/payment.rb', line 9

def credit_card
  @credit_card
end

Instance Method Details

#authorize(amount = amount, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bean/payment.rb', line 11

def authorize(amount=amount, options = {})
  return false if bean
  card = options.delete(:on) || (credit_card rescue nil)
  return false unless card
  
  process(amount,{
    :event => 'authorize',
    :state => 'authorized',
    :credit => 'payment',
    :debit =>'pending'
  }) do |gw|
    gw.authorize(amount, card, options)
  end
end

#capture(options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bean/payment.rb', line 26

def capture(options = {})
  return false unless bean.state == 'authorized'
  
  process(amount,{
    :event => 'capture',
    :state => 'captured',
    :credit => 'pending',
    :debit =>'cash'
  }) do |gw|
    gw.capture(amount, bean.reference, options)
  end
end