Class: ActiveMerchant::Billing::AirwallexGateway

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

Constant Summary collapse

ENDPOINTS =
{
  login: '/authentication/login',
  setup: '/pa/payment_intents/create',
  sale: '/pa/payment_intents/%{id}/confirm',
  capture: '/pa/payment_intents/%{id}/capture',
  refund: '/pa/refunds/create',
  void: '/pa/payment_intents/%{id}/cancel'
}

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

Returns a new instance of AirwallexGateway.



24
25
26
27
28
29
30
# File 'lib/active_merchant/billing/gateways/airwallex.rb', line 24

def initialize(options = {})
  requires!(options, :client_id, :client_api_key)
  @client_id = options[:client_id]
  @client_api_key = options[:client_api_key]
  super
  @access_token = setup_access_token
end

Instance Method Details

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



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

def authorize(money, payment, options = {})
  # authorize is just a purchase w/o an auto capture
  purchase(money, payment, options.merge({ auto_capture: false }))
end

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

Raises:

  • (ArgumentError)


55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/active_merchant/billing/gateways/airwallex.rb', line 55

def capture(money, authorization, options = {})
  raise ArgumentError, 'An authorization value must be provided.' if authorization.blank?

  post = {
    'request_id' => request_id(options),
    'merchant_order_id' => merchant_order_id(options),
    'amount' => amount(money)
  }
  add_descriptor(post, options)

  commit(:capture, post, authorization)
end

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



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

def purchase(money, card, options = {})
  requires!(options, :return_url)

  payment_intent_id = create_payment_intent(money, options)
  post = {
    'request_id' => request_id(options),
    'merchant_order_id' => merchant_order_id(options),
    'return_url' => options[:return_url]
  }
  add_card(post, card, options)
  add_descriptor(post, options)
  add_stored_credential(post, options)
  post['payment_method_options'] = { 'card' => { 'auto_capture' => false } } if authorization_only?(options)

  add_three_ds(post, options)
  commit(:sale, post, payment_intent_id)
end

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

Raises:

  • (ArgumentError)


68
69
70
71
72
73
74
75
76
77
78
# File 'lib/active_merchant/billing/gateways/airwallex.rb', line 68

def refund(money, authorization, options = {})
  raise ArgumentError, 'An authorization value must be provided.' if authorization.blank?

  post = {}
  post[:amount] = amount(money)
  post[:payment_intent_id] = authorization
  post[:request_id] = request_id(options)
  post[:merchant_order_id] = merchant_order_id(options)

  commit(:refund, post)
end

#scrub(transcript) ⇒ Object



102
103
104
105
106
# File 'lib/active_merchant/billing/gateways/airwallex.rb', line 102

def scrub(transcript)
  transcript.
    gsub(/(\\\"number\\\":\\\")\d+/, '\1[REDACTED]').
    gsub(/(\\\"cvc\\\":\\\")\d+/, '\1[REDACTED]')
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/active_merchant/billing/gateways/airwallex.rb', line 98

def supports_scrubbing?
  true
end

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



91
92
93
94
95
96
# File 'lib/active_merchant/billing/gateways/airwallex.rb', line 91

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

Raises:

  • (ArgumentError)


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

def void(authorization, options = {})
  raise ArgumentError, 'An authorization value must be provided.' if authorization.blank?

  post = {}
  post[:request_id] = request_id(options)
  post[:merchant_order_id] = merchant_order_id(options)
  add_descriptor(post, options)

  commit(:void, post, authorization)
end