Class: ActiveMerchant::Billing::DatatransGateway

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

Constant Summary collapse

CREDIT_CARD_SOURCE =
{
  visa: 'VISA',
  master: 'MASTERCARD'
}.with_indifferent_access
DEVICE_SOURCE =
{
  apple_pay: 'APPLE_PAY',
  google_pay: 'GOOGLE_PAY'
}.with_indifferent_access

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, #strftime_yyyymm

Methods included from PostsData

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

Constructor Details

#initialize(options = {}) ⇒ DatatransGateway

Returns a new instance of DatatransGateway.



28
29
30
31
32
# File 'lib/active_merchant/billing/gateways/datatrans.rb', line 28

def initialize(options = {})
  requires!(options, :merchant_id, :password)
  @merchant_id, @password = options.values_at(:merchant_id, :password)
  super
end

Instance Method Details

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



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

def authorize(money, payment, options = {})
  post = { refno: options.fetch(:order_id, '') }
  add_payment_method(post, payment)
  add_3ds_data(post, payment, options)
  add_currency_amount(post, money, options)
  add_billing_address(post, options)
  post[:autoSettle] = options[:auto_settle] if options[:auto_settle]
  commit('authorize', post)
end

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



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

def capture(money, authorization, options = {})
  post = { refno: options.fetch(:order_id, '') }
  transaction_id = authorization.split('|').first
  add_currency_amount(post, money, options)
  commit('settle', post, { transaction_id: })
end

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



34
35
36
# File 'lib/active_merchant/billing/gateways/datatrans.rb', line 34

def purchase(money, payment, options = {})
  authorize(money, payment, options.merge(auto_settle: true))
end

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



62
63
64
65
66
67
# File 'lib/active_merchant/billing/gateways/datatrans.rb', line 62

def refund(money, authorization, options = {})
  post = { refno: options.fetch(:order_id, '') }
  transaction_id = authorization.split('|').first
  add_currency_amount(post, money, options)
  commit('credit', post, { transaction_id: })
end

#scrub(transcript) ⇒ Object



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

def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Basic )[\w =]+), '\1[FILTERED]').
    gsub(%r((\"number\\":\\")\d+), '\1[FILTERED]\2').
    gsub(%r((\"cvv\\":\\")\d+), '\1[FILTERED]\2')
end

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



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/active_merchant/billing/gateways/datatrans.rb', line 75

def store(payment_method, options = {})
  exp_year = format(payment_method.year, :two_digits)
  exp_month = format(payment_method.month, :two_digits)

  post = {
    requests: [
      {
        type: 'CARD',
        pan: payment_method.number,
        expiryMonth: exp_month,
        expiryYear: exp_year
      }
    ]
  }
  commit('tokenize', post, { expiry_month: exp_month, expiry_year: exp_year })
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/active_merchant/billing/gateways/datatrans.rb', line 97

def supports_scrubbing?
  true
end

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



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

def unstore(authorization, options = {})
  data_alias = authorization.split('|')[2]
  commit('delete_alias', {}, { alias_id: data_alias }, :delete)
end

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



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

def verify(payment, options = {})
  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(100, payment, options) }
    r.process(:ignore_result) { void(r.authorization, options) }
  end
end

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



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

def void(authorization, options = {})
  post = {}
  transaction_id = authorization.split('|').first
  commit('cancel', post, { transaction_id: })
end