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


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

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


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

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


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

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

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


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/active_merchant/billing/gateways/mastercard.rb', line 9

def purchase(amount, payment_method, options = {})
  if options[:pay_mode]
    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('pay', post)
  else
    MultiResponse.run do |r|
      r.process { authorize(amount, payment_method, options) }
      r.process { capture(amount, r.authorization, options) }
    end
  end
end

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


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

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


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

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)

82
83
84
# File 'lib/active_merchant/billing/gateways/mastercard.rb', line 82

def supports_scrubbing?
  true
end

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


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

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


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

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


57
58
59
60
61
62
# File 'lib/active_merchant/billing/gateways/mastercard.rb', line 57

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

  commit('void', post)
end