Class: ActiveMerchant::Billing::FlexChargeGateway

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

Constant Summary collapse

ENDPOINTS_MAPPING =
{
  authenticate: 'oauth2/token',
  purchase: 'evaluate',
  sync: 'outcome',
  refund: 'orders/%s/refund',
  store: 'tokenize',
  inquire: 'orders/%s',
  capture: 'capture',
  void: 'orders/%s/cancel'
}
SUCCESS_MESSAGES =
%w(APPROVED CHALLENGE SUBMITTED SUCCESS PROCESSING CAPTUREREQUIRED).freeze
NO_ERROR_KEYS =
%w(TraceId access_token token_expires).freeze

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 Versionable

#fetch_version, included

Methods included from CreditCardFormatting

#expdate, #format, #strftime_yyyymm, #strftime_yyyymmdd_last_day

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

Constructor Details

#initialize(options = {}) ⇒ FlexChargeGateway

Returns a new instance of FlexChargeGateway.



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

def initialize(options = {})
  requires!(options, :app_key, :app_secret, :site_id, :mid)
  super
end

Instance Method Details

#add_metadata(post, options) ⇒ Object



123
124
125
126
# File 'lib/active_merchant/billing/gateways/flex_charge.rb', line 123

def (post, options)
  post[:Source] = 'Spreedly'
  post[:ExtraData] = options[:extra_data] if options[:extra_data].present?
end

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



53
54
55
56
# File 'lib/active_merchant/billing/gateways/flex_charge.rb', line 53

def authorize(money, credit_card, options = {})
  options[:transactionType] = 'Authorization'
  purchase(money, credit_card, options)
end

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



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

def capture(money, authorization, options = {})
  order_id, currency = authorization.split('#')
  post = {
    idempotencyKey: options[:idempotency_key] || SecureRandom.uuid,
    orderId: order_id,
    amount: money,
    currency:
  }

  commit(:capture, post, authorization)
end

#inquire(authorization, options = {}) ⇒ Object



118
119
120
121
# File 'lib/active_merchant/billing/gateways/flex_charge.rb', line 118

def inquire(authorization, options = {})
  order_id, _currency = authorization.split('#')
  commit(:inquire, {}, order_id, :get)
end

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



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/active_merchant/billing/gateways/flex_charge.rb', line 36

def purchase(money, credit_card, options = {})
  post = { transactionType: options.fetch(:transactionType, 'Purchase') }

  add_merchant_data(post, options)
  add_base_data(post, options)
  add_invoice(post, money, credit_card, options)
  add_mit_data(post, options)
  add_payment_method(post, credit_card, address(options), options)
  add_address(post, credit_card, address(options), :billingInformation)
  add_address(post, credit_card, options[:shipping_address], :shippingInformation)
  add_customer_data(post, options)
  add_three_ds(post, options)
  (post, options)

  commit(:purchase, post, nil, :post, options)
end

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



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

def refund(money, authorization, options = {})
  order_id, _currency = authorization.split('#')
  self.money_format = :dollars
  commit(:refund, { amountToRefund: localized_amount(money, 2).to_f }, order_id)
end

#scrub(transcript) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/active_merchant/billing/gateways/flex_charge.rb', line 103

def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Bearer )[a-zA-Z0-9._-]+)i, '\1[FILTERED]').
    gsub(%r(("AppKey\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
    gsub(%r(("AppSecret\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
    gsub(%r(("accessToken\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
    gsub(%r(("mid\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
    gsub(%r(("siteId\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
    gsub(%r(("environment\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
    gsub(%r(("number\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
    gsub(%r(("cardNumber\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
    gsub(%r(("verification_value\\?":\\?")\d+), '\1[FILTERED]').
    gsub(%r(("verificationValue\\?":\\?")\d+), '\1[FILTERED]')
end

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



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/active_merchant/billing/gateways/flex_charge.rb', line 81

def store(credit_card, options = {})
  first_name, last_name = names_from_address(address(options), credit_card)

  post = {
    payment_method: {
      credit_card: {
        first_name:,
        last_name:,
        month: credit_card.month,
        year: credit_card.year,
        number: credit_card.number,
        verification_value: credit_card.verification_value
      }.compact
    }
  }
  commit(:store, post)
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/active_merchant/billing/gateways/flex_charge.rb', line 99

def supports_scrubbing?
  true
end

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



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

def void(authorization, options = {})
  order_id, _currency = authorization.split('#')
  commit(:void, {}, order_id)
end