Class: ActiveMerchant::Billing::CheckoutGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/checkout.rb

Constant Summary collapse

ACTIONS =
{
  'purchase' => '1',
  'authorize' => '4',
  'capture' => '5',
  'refund' => '2',
  'void_purchase' => '3',
  'void_authorize' => '9',
  'void_capture' => '7'
}

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, #generate_unique_id, inherited, non_fractional_currency?, #scrub, supported_countries, #supported_countries, supported_countries=, supports?, #supports_scrubbing?, #test?

Methods included from CreditCardFormatting

#expdate, #format

Constructor Details

#initialize(options = {}) ⇒ CheckoutGateway

Returns a new instance of CheckoutGateway


28
29
30
31
32
33
# File 'lib/active_merchant/billing/gateways/checkout.rb', line 28

def initialize(options = {})
  @url = (options[:gateway_url] || self.live_url)

  requires!(options, :merchant_id, :password)
  super
end

Instance Method Details

#authorize(amount, payment_method, options) ⇒ Object


49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/active_merchant/billing/gateways/checkout.rb', line 49

def authorize(amount, payment_method, options)
  requires!(options, :order_id)

  commit('authorize', amount, options) do |xml|
    add_credentials(xml, options)
    add_invoice(xml, amount, options)
    add_payment_method(xml, payment_method)
    add_billing_info(xml, options)
    add_shipping_info(xml, options)
    add_user_defined_fields(xml, options)
    add_other_fields(xml, options)
  end
end

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


63
64
65
66
67
68
69
70
71
# File 'lib/active_merchant/billing/gateways/checkout.rb', line 63

def capture(amount, authorization, options = {})
  commit('capture', amount, options) do |xml|
    add_credentials(xml, options)
    add_reference(xml, authorization)
    add_invoice(xml, amount, options)
    add_user_defined_fields(xml, options)
    add_other_fields(xml, options)
  end
end

#purchase(amount, payment_method, options) ⇒ Object


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/active_merchant/billing/gateways/checkout.rb', line 35

def purchase(amount, payment_method, options)
  requires!(options, :order_id)

  commit('purchase', amount, options) do |xml|
    add_credentials(xml, options)
    add_invoice(xml, amount, options)
    add_payment_method(xml, payment_method)
    add_billing_info(xml, options)
    add_shipping_info(xml, options)
    add_user_defined_fields(xml, options)
    add_other_fields(xml, options)
  end
end

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


82
83
84
85
86
87
88
# File 'lib/active_merchant/billing/gateways/checkout.rb', line 82

def refund(amount, authorization, options = {})
  commit('refund') do |xml|
    add_credentials(xml, options)
    add_invoice(xml, amount.to_i, options)
    add_reference(xml, authorization)
  end
end

#verify(credit_card, options = {}) ⇒ Object


90
91
92
93
94
95
# File 'lib/active_merchant/billing/gateways/checkout.rb', line 90

def verify(credit_card, options={})
  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(100, credit_card, options) }
    r.process(:ignore_result) { void(r.authorization, options) }
  end
end

#void(authorization, options = {}) ⇒ Object


73
74
75
76
77
78
79
80
# File 'lib/active_merchant/billing/gateways/checkout.rb', line 73

def void(authorization, options = {})
  _, _, orig_action, amount, currency = split_authorization(authorization)
  commit("void_#{orig_action}") do |xml|
    add_credentials(xml, options)
    add_invoice(xml, amount.to_i, options.merge(currency: currency))
    add_reference(xml, authorization)
  end
end