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
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 19

def initialize(options = {})
  @options = options
  @access_token = nil
  begin
    requires!(options, :secret_key)
  rescue ArgumentError
    requires!(options, :client_id, :client_secret)
    @access_token = setup_access_token
  end
  super
end

Instance Method Details

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


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

def authorize(amount, payment_method, options = {})
  post = {}
  post[:capture] = false
  build_auth_or_purchase(post, amount, payment_method, options)

  options[:incremental_authorization].to_s.casecmp('true').zero? ? commit(:incremental_authorize, post, payment_method) : commit(:authorize, post)
end

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


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

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

  commit(:capture, post, authorization)
end

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


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

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

  commit(:purchase, post)
end

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


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

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

  commit(:refund, post, authorization)
end

#scrub(transcript) ⇒ Object


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

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]')
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)

80
81
82
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 80

def supports_scrubbing?
  true
end

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


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

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

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


76
77
78
# File 'lib/active_merchant/billing/gateways/checkout_v2.rb', line 76

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

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


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

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

  commit(:void, post, authorization)
end