Class: ActiveMerchant::Billing::ReachGateway

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

Constant Summary collapse

API_VERSION =
'v2.22'.freeze
STANDARD_ERROR_CODE_MAPPING =
{}
PAYMENT_METHOD_MAP =
{
  american_express: 'AMEX',
  cabal: 'CABAL',
  check: 'ACH',
  dankort: 'DANKORT',
  diners_club: 'DINERS',
  discover: 'DISC',
  elo: 'ELO',
  jcb: 'JCB',
  maestro: 'MAESTRO',
  master: 'MC',
  naranja: 'NARANJA',
  union_pay: 'UNIONPAY',
  visa: 'VISA'
}

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, #supported_countries, supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #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 = {}) ⇒ ReachGateway

Returns a new instance of ReachGateway.



33
34
35
36
# File 'lib/active_merchant/billing/gateways/reach.rb', line 33

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

Instance Method Details

#authorize(money, payment, options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/active_merchant/billing/gateways/reach.rb', line 38

def authorize(money, payment, options = {})
  request = build_checkout_request(money, payment, options)
  add_custom_fields_data(request, options)
  add_customer_data(request, options, payment)
  add_stored_credentials(request, options)
  post = { request: request, card: add_payment(payment, options) }
  if options[:stored_credential]
    MultiResponse.run(:use_first_response) do |r|
      r.process { commit('checkout', post) }
      r.process do
        r2 = get_network_payment_reference(r.responses[0])
        r.params[:network_transaction_id] = r2.message
        r2
      end
    end
  else
    commit('checkout', post)
  end
end

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



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

def capture(money, authorization, options = {})
  post = { request: { MerchantId: @options[:merchant_id], OrderId: authorization } }
  commit('capture', post)
end

#purchase(money, payment, options = {}) ⇒ Object



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

def purchase(money, payment, options = {})
  options[:capture] = true
  authorize(money, payment, options)
end

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



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/active_merchant/billing/gateways/reach.rb', line 80

def refund(amount, authorization, options = {})
  currency = options[:currency] || currency(options[:amount])
  post = {
    request: {
      MerchantId: @options[:merchant_id],
      OrderId: authorization,
      ReferenceId: options[:order_id] || options[:reference_id],
      Amount: localized_amount(amount, currency)
    }
  }
  commit('refund', post)
end

#scrub(transcript) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/active_merchant/billing/gateways/reach.rb', line 72

def scrub(transcript)
  transcript.
    gsub(%r(((MerchantId)[% \w]+[%]\d{2})[\w -]+), '\1[FILTERED]').
    gsub(%r((signature=)[\w%]+), '\1[FILTERED]\2').
    gsub(%r((Number%22%3A%22)[\d]+), '\1[FILTERED]\2').
    gsub(%r((VerificationCode%22%3A)[\d]+), '\1[FILTERED]\2')
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/active_merchant/billing/gateways/reach.rb', line 68

def supports_scrubbing?
  true
end

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



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

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



93
94
95
96
97
98
99
100
101
102
# File 'lib/active_merchant/billing/gateways/reach.rb', line 93

def void(authorization, options = {})
  post = {
    request: {
      MerchantId: @options[:merchant_id],
      OrderId: authorization
    }
  }

  commit('cancel', post)
end