Module: ActiveMerchant::Billing::MastercardGateway

Included in:
CitrusPayGateway, TnsGateway
Defined in:
lib/active_merchant/billing/gateways/mastercard.rb

Instance Method Summary collapse

Instance Method Details

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



17
18
19
20
21
22
23
24
25
# File 'lib/active_merchant/billing/gateways/mastercard.rb', line 17

def authorize(amount, payment_method, options={})
  post = new_post
  add_invoice(post, amount, options)
  add_reference(post, *new_authorization)
  add_payment_method(post, payment_method)
  add_customer_data(post, payment_method, options)

  commit('authorize', post)
end

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



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

def capture(amount, authorization, options={})
  post = new_post
  add_invoice(post, amount, options, :transaction)
  add_reference(post, *next_authorization(authorization))
  add_customer_data(post, nil, options)

  commit('capture', post)
end

#initialize(options = {}) ⇒ Object



5
6
7
8
# File 'lib/active_merchant/billing/gateways/mastercard.rb', line 5

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

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



10
11
12
13
14
15
# File 'lib/active_merchant/billing/gateways/mastercard.rb', line 10

def purchase(amount, payment_method, options={})
  MultiResponse.run do |r|
    r.process { authorize(amount, payment_method, options) }
    r.process { capture(amount, r.authorization, options) }
  end
end

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



36
37
38
39
40
41
42
43
# File 'lib/active_merchant/billing/gateways/mastercard.rb', line 36

def refund(amount, authorization, options={})
  post = new_post
  add_invoice(post, amount, options, :transaction)
  add_reference(post, *next_authorization(authorization))
  add_customer_data(post, nil, options)

  commit('refund', post)
end

#scrub(transcript) ⇒ Object



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

def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Basic ).*\\r\\n), '\1[FILTERED]').
    gsub(%r(("number"?\\?":"?\\?")\d*), '\1[FILTERED]').
    gsub(%r(("securityCode"?\\?":"?\\?")\d*), '\1[FILTERED]')
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/active_merchant/billing/gateways/mastercard.rb', line 70

def supports_scrubbing?
  true
end

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



52
53
54
55
56
57
# File 'lib/active_merchant/billing/gateways/mastercard.rb', line 52

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

#verify_credentialsObject



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

def verify_credentials
  url = build_url(SecureRandom.uuid, "nonexistent")
  begin
    ssl_get(url, headers)
  rescue ResponseError => e
    return false if e.response.code.to_i == 401
  end

  true
end

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



45
46
47
48
49
50
# File 'lib/active_merchant/billing/gateways/mastercard.rb', line 45

def void(authorization, options={})
  post = new_post
  add_reference(post, *next_authorization(authorization), :targetTransactionId)

  commit('void', post)
end