Class: ActiveMerchant::Billing::CardknoxGateway

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

Constant Summary collapse

COMMANDS =
{
  credit_card: {
    purchase:          'cc:sale',
    authorization:     'cc:authonly',
    capture:           'cc:capture',
    refund:            'cc:refund',
    void:              'cc:void',
    save:              'cc:save'
  },
  check: {
    purchase:    'check:sale',
    refund:      'check:refund',
    void:        'check:void',
    save:        'check:save'
  }
}

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

#card_brand, card_brand, #generate_unique_id, inherited, supported_countries, #supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #test?

Methods included from CreditCardFormatting

#format

Methods included from PostsData

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

Constructor Details

#initialize(options = {}) ⇒ CardknoxGateway

Returns a new instance of CardknoxGateway.



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

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

Instance Method Details

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



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

def authorize(amount, source, options={})
  post = {}
  add_amount(post, amount)
  add_invoice(post, options)
  add_source(post, source)
  add_address(post, source, options)
  add_customer_data(post, options)
  add_custom_fields(post, options)
  commit(:authorization, source_type(source), post)
end

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



62
63
64
65
66
67
# File 'lib/active_merchant/billing/gateways/cardknox.rb', line 62

def capture(amount, authorization, options = {})
  post = {}
  add_reference(post, authorization)
  add_amount(post, amount)
  commit(:capture, source_type(authorization), post)
end

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

There are three sources for doing a purchase transation:

  • credit card

  • check

  • cardknox token, which is returned in the the authorization string “ref_num;token;command”



40
41
42
43
44
45
46
47
48
49
# File 'lib/active_merchant/billing/gateways/cardknox.rb', line 40

def purchase(amount, source, options={})
  post = {}
  add_amount(post, amount, options)
  add_invoice(post, options)
  add_source(post, source)
  add_address(post, source, options)
  add_customer_data(post, options)
  add_custom_fields(post, options)
  commit(:purchase, source_type(source), post)
end

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



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

def refund(amount, authorization, options={})
  post = {}
  add_reference(post, authorization)
  add_amount(post, amount)
  commit(:refund, source_type(authorization), post)
end

#scrub(transcript) ⇒ Object



103
104
105
106
107
108
109
110
# File 'lib/active_merchant/billing/gateways/cardknox.rb', line 103

def scrub(transcript)
  transcript.
    gsub(%r((xCardNum=)\d+), '\1[FILTERED]').
    gsub(%r((xCVV=)\d+), '\1[FILTERED]').
    gsub(%r((xAccount=)\d+), '\1[FILTERED]').
    gsub(%r((xRouting=)\d+), '\1[FILTERED]').
    gsub(%r((xKey=)\w+), '\1[FILTERED]')
end

#store(source, options = {}) ⇒ Object



89
90
91
92
93
94
95
96
97
# File 'lib/active_merchant/billing/gateways/cardknox.rb', line 89

def store(source, options = {})
  post = {}
  add_source(post, source)
  add_address(post, source, options)
  add_invoice(post, options)
  add_customer_data(post, options)
  add_custom_fields(post, options)
  commit(:save, source_type(source), post)
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/active_merchant/billing/gateways/cardknox.rb', line 99

def supports_scrubbing?
  true
end

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



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

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



76
77
78
79
80
# File 'lib/active_merchant/billing/gateways/cardknox.rb', line 76

def void(authorization, options = {})
  post = {}
  add_reference(post, authorization)
  commit(:void, source_type(authorization), post)
end