Class: ActiveMerchant::Billing::PriorityGateway

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

Constant Summary

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

Returns a new instance of PriorityGateway.



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

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

Instance Method Details

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



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/active_merchant/billing/gateways/priority.rb', line 64

def authorize(amount, credit_card, options = {})
  params = {}
  params['authOnly'] = true
  params['isSettleFunds'] = false

  add_merchant_id(params)
  add_amount(params, amount, options)
  add_auth_purchase_params(params, options)
  add_credit_card(params, credit_card, 'purchase', options)

  commit('purchase', params: params)
end

#basic_authObject



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

def basic_auth
  Base64.strict_encode64("#{@options[:api_key]}:#{@options[:secret]}")
end

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



100
101
102
103
104
105
106
107
108
# File 'lib/active_merchant/billing/gateways/priority.rb', line 100

def capture(amount, authorization, options = {})
  params = {}
  add_merchant_id(params)
  add_amount(params, amount, options)
  params['paymentToken'] = payment_token(authorization) || options[:payment_token]
  add_auth_purchase_params(params, options)

  commit('capture', params: params)
end

#close_batch(batch_id) ⇒ Object



126
127
128
# File 'lib/active_merchant/billing/gateways/priority.rb', line 126

def close_batch(batch_id)
  commit('close_batch', params: batch_id)
end

#create_jwtObject



130
131
132
# File 'lib/active_merchant/billing/gateways/priority.rb', line 130

def create_jwt
  commit('create_jwt', params: @options[:merchant_id])
end

#credit(amount, credit_card, options = {}) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/active_merchant/billing/gateways/priority.rb', line 77

def credit(amount, credit_card, options = {})
  params = {}
  params['authOnly'] = false
  params['isSettleFunds'] = true
  amount = -amount

  add_merchant_id(params)
  add_amount(params, amount, options)
  add_credit_params(params, credit_card, options)
  commit('credit', params: params)
end

#get_payment_status(batch_id) ⇒ Object



122
123
124
# File 'lib/active_merchant/billing/gateways/priority.rb', line 122

def get_payment_status(batch_id)
  commit('get_payment_status', params: batch_id)
end

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



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/active_merchant/billing/gateways/priority.rb', line 51

def purchase(amount, credit_card, options = {})
  params = {}
  params['authOnly'] = false
  params['isSettleFunds'] = true

  add_merchant_id(params)
  add_amount(params, amount, options)
  add_auth_purchase_params(params, options)
  add_credit_card(params, credit_card, 'purchase', options)

  commit('purchase', params: params)
end

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



89
90
91
92
93
94
95
96
97
98
# File 'lib/active_merchant/billing/gateways/priority.rb', line 89

def refund(amount, authorization, options = {})
  params = {}
  add_merchant_id(params)
  params['paymentToken'] = payment_token(authorization) || options[:payment_token]

  # refund amounts must be negative
  params['amount'] = ('-' + localized_amount(amount.to_f, options[:currency])).to_f

  commit('refund', params: params)
end

#request_headersObject



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

def request_headers
  {
    'Content-Type' => 'application/json',
    'Authorization' => "Basic #{basic_auth}"
  }
end

#request_verify_headers(jwt) ⇒ Object



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

def request_verify_headers(jwt)
  {
    'Authorization' => "Bearer #{jwt}"
  }
end

#scrub(transcript) ⇒ Object



138
139
140
141
142
143
# File 'lib/active_merchant/billing/gateways/priority.rb', line 138

def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
    gsub(%r((number\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
    gsub(%r((cvv\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]')
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/active_merchant/billing/gateways/priority.rb', line 134

def supports_scrubbing?
  true
end

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



116
117
118
119
120
# File 'lib/active_merchant/billing/gateways/priority.rb', line 116

def verify(credit_card, _options = {})
  jwt = create_jwt.params['jwtToken']

  commit('verify', card_number: credit_card.number, jwt: jwt)
end

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



110
111
112
113
114
# File 'lib/active_merchant/billing/gateways/priority.rb', line 110

def void(authorization, options = {})
  params = {}

  commit('void', params: params, iid: payment_id(authorization))
end