Class: ActiveMerchant::Billing::CheckoutV2Gateway

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

Constant Summary collapse

SUCCESS_CODES =
%w{10000 10008 10011 10076 10077 10081}.freeze
SOFT_DECLINE_CODES =
%w{
  20001 20002 20003 20005 20006 20009 20010 20012 20013 20014 20017
  20018 20019 20020 20021 20022 20023 20024 20025 20026 20027 20028
  20029 20030 20031 20032 20038 20039 20040 20042 20044 20046 20051
  20052 20053 20054 20055 20056 20057 20058 20059 20060 20061 20062
  20063 20064 20065 20066 20067 20068 20075 20078 20082 20083 20084
  20085 20086 20087 20088 20089 20090 20091 20092 20093 20094 20095
  20096 20097 20098 20099 2006P 200N0 200N7 200O5 200P1 200P9 200R1
  200R3 200S4 200T2 200T3 200T5 20100 20101 20102 20103 20104 20105
  20106 20107 20108 20109 20110 20111 20112 20113 20114 20115 20116
  20117 20118 20119 20120 20121 20123 20124 20150 20151 20152 20153
  20154 20155 20156 20157 20158 20179 20182 20183 20193
}.freeze
LIVE_ACCESS_TOKEN_URL =
'https://access.checkout.com/connect/token'
TEST_ACCESS_TOKEN_URL =
'https://access.sandbox.checkout.com/connect/token'

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 = {}) ⇒ CheckoutV2Gateway

Returns a new instance of CheckoutV2Gateway.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 34

def initialize(options = {})
  @options = options
  @access_token = nil
  @response_http_code = nil

  if options.has_key?(:secret_key)
    requires!(options, :secret_key)
  else
    requires!(options, :client_id, :client_secret)
    @access_token = setup_access_token
  end

  super
end

Instance Method Details

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



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

def authorize(amount, payment_method, options = {})
  post = {}
  post[:capture] = false
  build_auth_or_purchase(post, amount, payment_method, options)
  options[:incremental_authorization] ? commit(:incremental_authorize, post, options, options[:incremental_authorization]) : commit(:authorize, post, options)
end

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



63
64
65
66
67
68
69
70
71
72
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 63

def capture(amount, authorization, options = {})
  post = {}
  post[:capture_type] = options[:capture_type] || 'Final'
  add_invoice(post, amount, options)
  add_customer_data(post, options)
  add_shipping_address(post, options)
  (post, options)

  commit(:capture, post, options, authorization)
end

#credit(amount, payment, options = {}) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 74

def credit(amount, payment, options = {})
  post = {}
  post[:instruction] = {}
  post[:instruction][:funds_transfer_type] = options[:funds_transfer_type] || 'FD'
  add_processing_channel(post, options)
  add_invoice(post, amount, options)
  add_payment_method(post, payment, options, :destination)
  add_source(post, payment, options)

  commit(:credit, post, options)
end

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



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

def purchase(amount, payment_method, options = {})
  post = {}
  build_auth_or_purchase(post, amount, payment_method, options)

  commit(:purchase, post, options)
end

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



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

def refund(amount, authorization, options = {})
  post = {}
  add_invoice(post, amount, options)
  add_customer_data(post, options)
  (post, options)

  commit(:refund, post, options, authorization)
end

#scrub(transcript) ⇒ Object



114
115
116
117
118
119
120
121
122
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 114

def scrub(transcript)
  transcript.
    gsub(/(Authorization: )[^\\]*/i, '\1[FILTERED]').
    gsub(/("number\\":\\")\d+/, '\1[FILTERED]').
    gsub(/("cvv\\":\\")\d+/, '\1[FILTERED]').
    gsub(/("cryptogram\\":\\")\w+/, '\1[FILTERED]').
    gsub(/(source\\":\{.*\\"token\\":\\")\d+/, '\1[FILTERED]').
    gsub(/("token\\":\\")\w+/, '\1[FILTERED]')
end

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



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 124

def store(payment_method, options = {})
  post = {}
  MultiResponse.run do |r|
    if payment_method.is_a?(NetworkTokenizationCreditCard)
      r.process { verify(payment_method, options) }
      break r unless r.success?

      r.params['source']['customer'] = r.params['customer']
      r.process { response(:store, true, r.params['source']) }
    else
      r.process { tokenize(payment_method, options) }
      break r unless r.success?

      token = r.params['token']
      add_payment_method(post, token, options)
      post.merge!(post.delete(:source))
      add_customer_data(post, options)
      add_shipping_address(post, options)
      r.process { commit(:store, post, options) }
    end
  end
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 110

def supports_scrubbing?
  true
end

#unstore(id, options = {}) ⇒ Object



147
148
149
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 147

def unstore(id, options = {})
  commit(:unstore, nil, options, id, :delete)
end

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



102
103
104
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 102

def verify(credit_card, options = {})
  authorize(0, credit_card, options)
end

#verify_payment(authorization, option = {}) ⇒ Object



106
107
108
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 106

def verify_payment(authorization, option = {})
  commit(:verify_payment, nil, options, authorization, :get)
end

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



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

def void(authorization, _options = {})
  post = {}
  (post, options)

  commit(:void, post, options, authorization)
end