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'
}
TEST_NETWORK_TRANSACTION_IDS =

Provided by Airwallex for testing purposes

{
  visa: '123456789012345',
  master: 'MCC123ABC0101'
}

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.


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

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


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

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)

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

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


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

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)

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

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


108
109
110
111
112
# File 'lib/active_merchant/billing/gateways/airwallex.rb', line 108

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

#supports_scrubbing?Boolean

Returns:

  • (Boolean)

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

def supports_scrubbing?
  true
end

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


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

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)

86
87
88
89
90
91
92
93
94
95
# File 'lib/active_merchant/billing/gateways/airwallex.rb', line 86

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