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
26
# 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)
  add_3dsecure_id(post, options)

  commit('authorize', post)
end

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


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

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)
  add_3dsecure_id(post, 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


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

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


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

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


72
73
74
# File 'lib/active_merchant/billing/gateways/mastercard.rb', line 72

def supports_scrubbing?
  true
end

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


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

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


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

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


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

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

  commit('void', post)
end