Class: ActiveMerchant::Billing::TelrGateway

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

Constant Summary collapse

CVC_CODE_TRANSLATOR =
{
  'Y' => 'M',
  'N' => 'N',
  'X' => 'P',
  'E' => 'U',
}
AVS_CODE_TRANSLATOR =
{
  'Y' => 'M',
  'P' => 'A',
  'N' => 'N',
  'X' => 'I',
  'E' => 'R'
}

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::DEBIT_CARDS, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

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

Returns a new instance of TelrGateway.



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

def initialize(options={})
  requires!(options, :merchant_id, :api_key)
  super
end

Instance Method Details

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



44
45
46
47
48
49
50
# File 'lib/active_merchant/billing/gateways/telr.rb', line 44

def authorize(amount, payment_method, options={})
  commit(:authorize, amount, options[:currency]) do |doc|
    add_invoice(doc, 'auth', amount, payment_method, options)
    add_payment_method(doc, payment_method, options)
    add_customer_data(doc, payment_method, options)
  end
end

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



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

def capture(amount, authorization, options={})
  commit(:capture) do |doc|
    add_invoice(doc, 'capture', amount, authorization, options)
  end
end

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



36
37
38
39
40
41
42
# File 'lib/active_merchant/billing/gateways/telr.rb', line 36

def purchase(amount, payment_method, options={})
  commit(:purchase, amount, options[:currency]) do |doc|
    add_invoice(doc, 'sale', amount, payment_method, options)
    add_payment_method(doc, payment_method, options)
    add_customer_data(doc, payment_method, options)
  end
end

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



65
66
67
68
69
# File 'lib/active_merchant/billing/gateways/telr.rb', line 65

def refund(amount, authorization, options={})
  commit(:refund) do |doc|
    add_invoice(doc, 'refund', amount, authorization, options)
  end
end

#scrub(transcript) ⇒ Object



88
89
90
91
92
93
# File 'lib/active_merchant/billing/gateways/telr.rb', line 88

def scrub(transcript)
  transcript.
  gsub(%r((<Number>)[^<]+(<))i, '\1[FILTERED]\2').
  gsub(%r((<CVV>)[^<]+(<))i, '\1[FILTERED]\2').
  gsub(%r((<Key>)[^<]+(<))i, '\1[FILTERED]\2')
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/active_merchant/billing/gateways/telr.rb', line 84

def supports_scrubbing?
  true
end

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



71
72
73
74
75
76
77
# File 'lib/active_merchant/billing/gateways/telr.rb', line 71

def verify(credit_card, options={})
  commit(:verify) do |doc|
    add_invoice(doc, 'verify', 100, credit_card, options)
    add_payment_method(doc, credit_card, options)
    add_customer_data(doc, credit_card, options)
  end
end

#verify_credentialsObject



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

def verify_credentials
  response = void('0')
  !['01', '04'].include?(response.error_code)
end

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



58
59
60
61
62
63
# File 'lib/active_merchant/billing/gateways/telr.rb', line 58

def void(authorization, options={})
  _, amount, currency = split_authorization(authorization)
  commit(:void) do |doc|
    add_invoice(doc, 'void', amount.to_i, authorization, options.merge(currency: currency))
  end
end