Class: MerchantSidekick::ActiveMerchant::CreditCardPayment

Inherits:
Payment
  • Object
show all
Defined in:
lib/merchant_sidekick/active_merchant/credit_card_payment.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Payment

class_for, #content_attributes, content_column_names, #content_column_names, #success?

Class Method Details

.authorize(amount, credit_card, options = {}) ⇒ Object



43
44
45
46
47
# File 'lib/merchant_sidekick/active_merchant/credit_card_payment.rb', line 43

def authorize(amount, credit_card, options = {})
  process('authorization', amount, options) do |gw|
    gw.authorize(amount.cents, credit_card, options)
  end
end

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



49
50
51
52
53
# File 'lib/merchant_sidekick/active_merchant/credit_card_payment.rb', line 49

def capture(amount, authorization, options = {})
  process('capture', amount, options) do |gw|
    gw.capture(amount.cents, authorization, options)
  end
end

.credit(amount, authorization, options = {}) ⇒ Object

requires :card_number option



68
69
70
71
72
# File 'lib/merchant_sidekick/active_merchant/credit_card_payment.rb', line 68

def credit(amount, authorization, options = {})
  process('credit', amount, options) do |gw|
    gw.credit(amount.cents, authorization, options)
  end
end

.gatewayObject

Returns an active merchant gateway instance, based on the following:

* an active merchant gateway instance assigned to the gateway
  class accessor
* a merchant sidekick specific gateway identifier, 
  e.g. :authorize_net_gateway, is passed into the gateway class accessor
* otherwise falls back to the default gateway assigned as
  MerchantSidekick::Gateways::Gateway.default_gateway

Declare as needed in the environment.

E.g.

CreditCardPayment.gateway = ActiveMerchant::Billing::AuthorizeNetGateway.new({
  :login    => @login_id,
  :password => @transaction_key
})

or

CreditCardPayment.gateway = :authorize_net_gateway


32
33
34
35
36
37
38
39
40
41
# File 'lib/merchant_sidekick/active_merchant/credit_card_payment.rb', line 32

def gateway
  if @@gateway.is_a? ::ActiveMerchant::Billing::Gateway
    @@gateway
  elsif @@gateway.is_a? Symbol
    @@gateway = "::MerchantSidekick::ActiveMerchant::Gateways::#{@@gateway.to_s.classify}".constantize.gateway
    @@gateway
  else
    @@gateway = MerchantSidekick::Gateway.default_gateway
  end
end

.purchase(amount, credit_card, options = {}) ⇒ Object



55
56
57
58
59
# File 'lib/merchant_sidekick/active_merchant/credit_card_payment.rb', line 55

def purchase(amount, credit_card, options = {})
  process('purchase', amount, options) do |gw|
    gw.purchase(amount.cents, credit_card, options)
  end
end

.transfer(amount, destination_account, options = {}) ⇒ Object

works with paypal payflow



75
76
77
78
79
# File 'lib/merchant_sidekick/active_merchant/credit_card_payment.rb', line 75

def transfer(amount, , options={})
  process('transfer', amount, options) do |gw|
    gw.transfer(amount.cents, , options)
  end
end

.void(amount, authorization, options = {}) ⇒ Object



61
62
63
64
65
# File 'lib/merchant_sidekick/active_merchant/credit_card_payment.rb', line 61

def void(amount, authorization, options = {})
  process('void', amount, options) do |gw|
    gw.void(authorization, options)
  end
end

Instance Method Details

#payment_typeObject

override in sublcass



111
112
113
# File 'lib/merchant_sidekick/active_merchant/credit_card_payment.rb', line 111

def payment_type
  :credit_card
end