Class: Opensteam::Payment::CreditCardPayment

Inherits:
Base
  • Object
show all
Defined in:
lib/opensteam/payment/credit_card_payment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

[], inherited, new_with_type

Methods included from StateMachine

included

Constructor Details

#initialize(*args, &block) ⇒ CreditCardPayment

Returns a new instance of CreditCardPayment.



40
41
42
43
# File 'lib/opensteam/payment/credit_card_payment.rb', line 40

def initialize(*args, &block )
  self.credit_card = ActiveMerchant::Billing::CreditCard.new
  super( *args, &block )
end

Instance Attribute Details

#credit_cardObject

Returns the value of attribute credit_card.



35
36
37
# File 'lib/opensteam/payment/credit_card_payment.rb', line 35

def credit_card
  @credit_card
end

Instance Method Details

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

authorize amount and credit_card at payment gateway



62
63
64
65
66
67
68
69
70
# File 'lib/opensteam/payment/credit_card_payment.rb', line 62

def authorize( amount = nil, options = {} )
  self.amount = amount || self.order.total_price
  #self.credit_card.decrypt_number
  
  transactions.process( :action => :authorize, :amount => amount_in_cents ) do |gw|
    gw.authorize( amount_in_cents, self.credit_card, options )
  end
  
end

#capture(amount, authorization, options = {}) ⇒ Object

capture amount from authorization



74
75
76
77
78
79
80
81
# File 'lib/opensteam/payment/credit_card_payment.rb', line 74

def capture( amount, authorization, options = {} )
  self.amount = amount || self.order.total_price
  
  transactions.process( :action => :capture, :amount => amount ) do |gw|
    gw.capture( amount_in_cents, authorization, options )
  end
  
end

#gatewayObject



46
47
48
# File 'lib/opensteam/payment/credit_card_payment.rb', line 46

def gateway
  self.class.gateway_class.new( :login => self.class.gateway_user, :password => self.class.gateway_password )
end

#purchase(amount = nil, options = {}) ⇒ Object

purchase amount from credit_card



85
86
87
88
89
90
# File 'lib/opensteam/payment/credit_card_payment.rb', line 85

def purchase( amount = nil, options = {} )
  self.amount = amount || self.order.total_price
  # self.credit_card.decrypt_number

  process :purchase, amount_in_cents, self.credit_card, options
end

#set_credit_card=(fields) ⇒ Object

inits a new credit card and assigns it to current payment object



51
52
53
54
55
56
57
58
# File 'lib/opensteam/payment/credit_card_payment.rb', line 51

def set_credit_card=(fields)
  #self.credit_card = CreditCard.new( fields )
  fields.update( :type => fields.delete(:brand) ) if fields[:brand]
  self.credit_card = ActiveMerchant::Billing::CreditCard.new( fields )
  self.data = { :number => self.credit_card.display_number,
    :first_name => self.credit_card.first_name,
    :last_name => self.credit_card.last_name }
end