Class: ActiveMerchant::Billing::PaymentezGateway

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

Overview

:nodoc:

Constant Summary collapse

STANDARD_ERROR_CODE_MAPPING =
{
  1 => :processing_error,
  6 => :card_declined,
  9 => :card_declined,
  10 => :processing_error,
  11 => :card_declined,
  12 => :config_error,
  13 => :config_error,
  19 => :invalid_cvc,
  20 => :config_error,
  21 => :card_declined,
  22 => :card_declined,
  23 => :card_declined,
  24 => :card_declined,
  25 => :card_declined,
  26 => :card_declined,
  27 => :card_declined,
  28 => :card_declined
}.freeze
CARD_MAPPING =
{
  'visa' => 'vi',
  'master' => 'mc',
  'american_express' => 'ax',
  'diners_club' => 'di'
}.freeze

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

Returns a new instance of PaymentezGateway.



44
45
46
47
# File 'lib/active_merchant/billing/gateways/paymentez.rb', line 44

def initialize(options = {})
  requires!(options, :application_code, :app_key)
  super
end

Instance Method Details

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



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

def authorize(money, payment, options = {})
  post = {}

  add_invoice(post, money, options)
  add_customer_data(post, options)

  MultiResponse.run do |r|
    r.process { store(payment, options) }
    post[:card] = { token: r.authorization }
    r.process { commit_transaction('authorize', post) }
  end
end

#capture(_money, authorization, _options = {}) ⇒ Object



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

def capture(_money, authorization, _options = {})
  post = { transaction: { id: authorization } }

  commit_transaction('capture', post)
end

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



49
50
51
52
53
54
55
56
57
# File 'lib/active_merchant/billing/gateways/paymentez.rb', line 49

def purchase(money, payment, options = {})
  post = {}

  add_invoice(post, money, options)
  add_payment(post, payment)
  add_customer_data(post, options)

  commit_transaction('debit_cc', post)
end

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



78
79
80
# File 'lib/active_merchant/billing/gateways/paymentez.rb', line 78

def refund(_money, authorization, options = {})
  void(authorization, options)
end

#scrub(transcript) ⇒ Object



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

def scrub(transcript)
  transcript
    .gsub(%r{(\\?"number\\?":)(\\?"[^"]+\\?")}, '\1[FILTERED]')
    .gsub(%r{(\\?"cvc\\?":)(\\?"[^"]+\\?")}, '\1[FILTERED]')
    .gsub(%r{(Auth-Token: )([A-Za-z0-9=]+)}, '\1[FILTERED]')
end

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



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/active_merchant/billing/gateways/paymentez.rb', line 94

def store(credit_card, options = {})
  post = {}

  add_customer_data(post, options)
  add_payment(post, credit_card)

  response = commit_card('add', post)
  if !response.success? && !(token = extract_previous_card_token(response)).nil?
    unstore(token, options)
    response = commit_card('add', post)
  end
  response
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/active_merchant/billing/gateways/paymentez.rb', line 113

def supports_scrubbing?
  true
end

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



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

def unstore(identification, options = {})
  post = { card: { token: identification }, user: { id: options[:user_id] }}
  commit_card('delete', post)
end

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



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

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

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



82
83
84
85
# File 'lib/active_merchant/billing/gateways/paymentez.rb', line 82

def void(authorization, _options = {})
  post = { transaction: { id: authorization } }
  commit_transaction('refund', post)
end