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::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#add_field_to_post_if_present, #add_fields_to_post_if_present, #card_brand, card_brand, #generate_unique_id, inherited, #scrub, #supported_countries, supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #supports_scrubbing?, #test?

Methods included from CreditCardFormatting

#expdate, #format

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

Constructor Details

#initialize(options = {}) ⇒ CheckoutGateway

Returns a new instance of CheckoutGateway.



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

def initialize(options = {})
  requires!(options, :merchant_id, :password)
  super
end

Instance Method Details

#authorize(amount, payment_method, options) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/active_merchant/billing/gateways/checkout.rb', line 46

def authorize(amount, payment_method, options)
  commit('authorize', amount, options) do |xml|
    add_credentials(xml, options)
    add_invoice(xml, amount, options)
    add_track_id(xml, options[:order_id] || generate_unique_id)
    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



59
60
61
62
63
64
65
66
67
# File 'lib/active_merchant/billing/gateways/checkout.rb', line 59

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



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

def purchase(amount, payment_method, options)
  commit('purchase', amount, options) do |xml|
    add_credentials(xml, options)
    add_invoice(xml, amount, options)
    add_track_id(xml, options[:order_id] || generate_unique_id)
    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



78
79
80
81
82
83
84
# File 'lib/active_merchant/billing/gateways/checkout.rb', line 78

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



86
87
88
89
90
91
# File 'lib/active_merchant/billing/gateways/checkout.rb', line 86

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



69
70
71
72
73
74
75
76
# File 'lib/active_merchant/billing/gateways/checkout.rb', line 69

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