Class: Opensteam::Payment::CreditCardPayment
- Defined in:
- lib/opensteam/payment/credit_card_payment.rb
Instance Attribute Summary collapse
-
#credit_card ⇒ Object
Returns the value of attribute credit_card.
Instance Method Summary collapse
-
#authorize(amount = nil, options = {}) ⇒ Object
authorize amount and credit_card at payment gateway.
-
#capture(amount, authorization, options = {}) ⇒ Object
capture amount from authorization.
- #gateway ⇒ Object
-
#initialize(*args, &block) ⇒ CreditCardPayment
constructor
A new instance of CreditCardPayment.
-
#purchase(amount = nil, options = {}) ⇒ Object
purchase amount from credit_card.
-
#set_credit_card=(fields) ⇒ Object
inits a new credit card and assigns it to current payment object.
Methods inherited from Base
Methods included from StateMachine
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_card ⇒ Object
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 ( amount = nil, = {} ) self.amount = amount || self.order.total_price #self.credit_card.decrypt_number transactions.process( :action => :authorize, :amount => amount_in_cents ) do |gw| gw.( amount_in_cents, self.credit_card, ) 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, , = {} ) self.amount = amount || self.order.total_price transactions.process( :action => :capture, :amount => amount ) do |gw| gw.capture( amount_in_cents, , ) end end |
#gateway ⇒ Object
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, = {} ) self.amount = amount || self.order.total_price # self.credit_card.decrypt_number process :purchase, amount_in_cents, self.credit_card, 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 |