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

Returns a new instance of PriorityGateway.



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

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

Instance Method Details

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



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/active_merchant/billing/gateways/priority.rb', line 68

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:)
end

#basic_authObject



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

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

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



104
105
106
107
108
109
110
111
112
# File 'lib/active_merchant/billing/gateways/priority.rb', line 104

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:)
end

#close_batch(batch_id) ⇒ Object



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

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

#create_jwtObject



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

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

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



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/active_merchant/billing/gateways/priority.rb', line 81

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:)
end

#get_payment_status(batch_id) ⇒ Object



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

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

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



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/active_merchant/billing/gateways/priority.rb', line 55

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:)
end

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



93
94
95
96
97
98
99
100
101
102
# File 'lib/active_merchant/billing/gateways/priority.rb', line 93

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:)
end

#request_headersObject



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

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

#request_verify_headers(jwt) ⇒ Object



49
50
51
52
53
# File 'lib/active_merchant/billing/gateways/priority.rb', line 49

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

#scrub(transcript) ⇒ Object



142
143
144
145
146
147
# File 'lib/active_merchant/billing/gateways/priority.rb', line 142

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)


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

def supports_scrubbing?
  true
end

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



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

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

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

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



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

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

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