Class: ActiveMerchant::Billing::CheckoutV2Gateway

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

Constant Summary collapse

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.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 19

def initialize(options = {})
  @options = options
  @access_token = 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



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

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



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

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



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

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, options)

  commit(:credit, post, options)
end

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



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

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



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

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



98
99
100
101
102
103
104
105
106
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 98

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



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 108

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)


94
95
96
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 94

def supports_scrubbing?
  true
end

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



131
132
133
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 131

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

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



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

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

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



90
91
92
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 90

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

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



70
71
72
73
74
75
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 70

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

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