Class: ActiveMerchant::Billing::PriorityGateway
- 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
Instance Method Summary collapse
- #add_credit_card(params, credit_card, action, options) ⇒ Object
- #add_pos_data(options) ⇒ Object
- #add_purchases_data(options) ⇒ Object
- #add_risk_data(options) ⇒ Object
- #add_type_merchant_purchase(params, merchant, is_settle_funds, options) ⇒ Object
- #authorization_from(response) ⇒ Object
- #authorize(amount, credit_card, options = {}) ⇒ Object
- #base_url ⇒ Object
- #basic_auth ⇒ Object
- #batch_url ⇒ Object
- #capture(amount, authorization, options = {}) ⇒ Object
- #close_batch(batch_id, options) ⇒ Object
- #commit(action, params: '', iid: '', card_number: nil, jwt: '') ⇒ Object
- #create_jwt(options) ⇒ Object
- #error_from(response) ⇒ Object
- #exp_date(credit_card) ⇒ Object
- #get_hash(string) ⇒ Object
- #get_payment_status(batch_id, options) ⇒ Object
- #handle_response(response) ⇒ Object
-
#initialize(options = {}) ⇒ PriorityGateway
constructor
A new instance of PriorityGateway.
- #jwt_url ⇒ Object
- #message_from(response) ⇒ Object
- #parse(body) ⇒ Object
- #post_data(params) ⇒ Object
- #purchase(amount, credit_card, options = {}) ⇒ Object
- #purchases ⇒ Object
- #refund(amount, authorization, options = {}) ⇒ Object
- #request_headers ⇒ Object
- #request_verify_headers(jwt) ⇒ Object
- #scrub(transcript) ⇒ Object
- #success_from(response, action) ⇒ Object
- #supports_scrubbing? ⇒ Boolean
- #url(action, params, ref_number: '', credit_card_number: nil) ⇒ Object
- #verify(credit_card, options) ⇒ Object
- #verify_url ⇒ Object
- #void(authorization, options = {}) ⇒ Object
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
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( = {}) requires!(, :merchant_id, :key, :secret) super end |
Instance Method Details
#add_credit_card(params, credit_card, action, options) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 125 def add_credit_card(params, credit_card, action, ) return unless credit_card&.is_a?(CreditCard) card_details = {} card_details['expiryMonth'] = format(credit_card.month, :two_digits).to_s card_details['expiryYear'] = format(credit_card.year, :two_digits).to_s card_details['expiryDate'] = exp_date(credit_card) card_details['cardType'] = credit_card.brand card_details['last4'] = credit_card.last_digits card_details['cvv'] = credit_card.verification_value card_details['number'] = credit_card.number card_details['entryMode'] = ['entryMode'].blank? ? 'Keyed' : ['entryMode'] case action when 'purchase' card_details['avsStreet'] = [:billing_address][:address1] if [:billing_address] card_details['avsZip'] = [:billing_address][:zip] if [:billing_address] when 'refund' card_details['cardId'] = [:card_id] card_details['cardPresent'] = [:card_present] card_details['hasContract'] = [:has_contract] card_details['isCorp'] = [:is_corp] card_details['isDebit'] = [:is_debit] card_details['token'] = [:token] else card_details end params['cardAccount'] = card_details end |
#add_pos_data(options) ⇒ Object
298 299 300 301 302 303 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 298 def add_pos_data() = {} ['panCaptureMethod'] = [:pan_capture_method] end |
#add_purchases_data(options) ⇒ Object
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 305 def add_purchases_data() purchases = {} purchases['dateCreated'] = [:date_created] purchases['iId'] = [:i_id] purchases['transactionIId'] = [:transaction_i_id] purchases['transactionId'] = [:transaction_id] purchases['name'] = [:name] purchases['description'] = [:description] purchases['code'] = [:code] purchases['unitOfMeasure'] = [:unit_of_measure] purchases['unitPrice'] = [:unit_price] purchases['quantity'] = [:quantity] purchases['taxRate'] = [:tax_rate] purchases['taxAmount'] = [:tax_amount] purchases['discountRate'] = [:discount_rate] purchases['discountAmount'] = [:discount_amt] purchases['extendedAmount'] = [:extended_amt] purchases['lineItemId'] = [:line_item_id] purchase_arr = [] purchase_arr[0] = purchases purchase_arr end |
#add_risk_data(options) ⇒ Object
330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 330 def add_risk_data() risk = {} risk['cvvResponseCode'] = [:cvv_response_code] risk['cvvResponse'] = [:cvv_response] risk['cvvMatch'] = [:cvv_match] risk['avsResponse'] = [:avs_response] risk['avsAddressMatch'] = [:avs_address_match] risk['avsZipMatch'] = [:avs_zip_match] risk end |
#add_type_merchant_purchase(params, merchant, is_settle_funds, options) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 166 def add_type_merchant_purchase(params, merchant, is_settle_funds, ) params['cardPresent'] = false params['cardPresentType'] = 'CardNotPresent' params['isAuth'] = true params['isSettleFunds'] = is_settle_funds params['isTicket'] = false params['merchantId'] = merchant params['mxAdvantageEnabled'] = false params['paymentType'] = 'Sale' params['purchases'] = purchases params['shouldGetCreditCardLevel'] = true params['shouldVaultCard'] = true params['source'] = [:source] params['sourceZip'] = [:billing_address][:zip] if [:billing_address] params['taxExempt'] = false params['tenderType'] = 'Card' end |
#authorization_from(response) ⇒ Object
283 284 285 286 287 288 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 283 def (response) { 'payment_token' => response['paymentToken'], 'id' => response['id'] } end |
#authorize(amount, credit_card, options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 61 def (amount, credit_card, = {}) params = {} params['amount'] = localized_amount(amount.to_f, [:currency]) params['authOnly'] = true add_credit_card(params, credit_card, 'purchase', ) add_type_merchant_purchase(params, @options[:merchant_id], false, ) commit('purchase', params: params, jwt: ) end |
#base_url ⇒ Object
242 243 244 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 242 def base_url test? ? test_url : live_url end |
#basic_auth ⇒ Object
34 35 36 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 34 def basic_auth Base64.strict_encode64("#{@options[:key]}:#{@options[:secret]}") end |
#batch_url ⇒ Object
254 255 256 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 254 def batch_url test? ? self.test_url_batch : self.live_url_batch end |
#capture(amount, authorization, options = {}) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 80 def capture(amount, , = {}) params = {} params['amount'] = localized_amount(amount.to_f, [:currency]) params['authCode'] = [:authCode] params['merchantId'] = @options[:merchant_id] params['paymentToken'] = get_hash()['payment_token'] params['shouldGetCreditCardLevel'] = true params['source'] = [:source] params['tenderType'] = 'Card' commit('capture', params: params, jwt: ) end |
#close_batch(batch_id, options) ⇒ Object
110 111 112 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 110 def close_batch(batch_id, ) commit('close_batch', params: batch_id, jwt: ) end |
#commit(action, params: '', iid: '', card_number: nil, jwt: '') ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 187 def commit(action, params: '', iid: '', card_number: nil, jwt: '') response = begin case action when 'void' parse(ssl_request(:delete, url(action, params, ref_number: iid), nil, request_headers)) when 'verify' parse(ssl_get(url(action, params, credit_card_number: card_number), request_verify_headers(jwt))) when 'get_payment_status', 'create_jwt' parse(ssl_get(url(action, params, ref_number: iid), request_headers)) when 'close_batch' parse(ssl_request(:put, url(action, params, ref_number: iid), nil, request_headers)) else parse(ssl_post(url(action, params), post_data(params), request_headers)) end rescue ResponseError => e parse(e.response.body) end success = success_from(response, action) response = { 'code' => '204' } if response == '' Response.new( success, (response), response, authorization: success ? (response) : nil, error_code: success || response == '' ? nil : error_from(response), test: test? ) end |
#create_jwt(options) ⇒ Object
114 115 116 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 114 def create_jwt() commit('create_jwt', params: @options[:merchant_id], jwt: ) end |
#error_from(response) ⇒ Object
290 291 292 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 290 def error_from(response) response['errorCode'] || response['status'] end |
#exp_date(credit_card) ⇒ Object
158 159 160 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 158 def exp_date(credit_card) "#{format(credit_card.month, :two_digits)}/#{format(credit_card.year, :two_digits)}" end |
#get_hash(string) ⇒ Object
342 343 344 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 342 def get_hash(string) JSON.parse(string.gsub('=>', ':')) end |
#get_payment_status(batch_id, options) ⇒ Object
106 107 108 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 106 def get_payment_status(batch_id, ) commit('get_payment_status', params: batch_id, jwt: ) end |
#handle_response(response) ⇒ Object
217 218 219 220 221 222 223 224 225 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 217 def handle_response(response) if response.code != '204' && (200...300).cover?(response.code.to_i) response.body elsif response.code == '204' || response == '' response.body = { 'code' => '204' } else raise ResponseError.new(response) end end |
#jwt_url ⇒ Object
250 251 252 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 250 def jwt_url test? ? self.test_url_jwt : self.live_url_jwt end |
#message_from(response) ⇒ Object
277 278 279 280 281 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 277 def (response) return response['details'][0] if response['details'] && response['details'][0] response['authMessage'] || response['message'] || response['status'] end |
#parse(body) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 258 def parse(body) return body if body['code'] == '204' JSON.parse(body) rescue JSON::ParserError = 'Invalid JSON response received from Priority Gateway. Please contact Priority Gateway if you continue to receive this message.' += " (The raw response returned by the API was #{body.inspect})" { 'message' => } end |
#post_data(params) ⇒ Object
294 295 296 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 294 def post_data(params) params.to_json end |
#purchase(amount, credit_card, options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 51 def purchase(amount, credit_card, = {}) params = {} params['amount'] = localized_amount(amount.to_f, [:currency]) params['authOnly'] = false add_credit_card(params, credit_card, 'purchase', ) add_type_merchant_purchase(params, @options[:merchant_id], true, ) commit('purchase', params: params, jwt: ) end |
#purchases ⇒ Object
162 163 164 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 162 def purchases [{ taxRate: '0.0000', additionalTaxRate: nil, discountRate: nil }] end |
#refund(amount, authorization, options = {}) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 71 def refund(amount, , = {}) params = {} params['merchantId'] = @options[:merchant_id] params['paymentToken'] = get_hash()['payment_token'] || [:payment_token] # refund amounts must be negative params['amount'] = ('-' + localized_amount(amount.to_f, [:currency])).to_f commit('refund', params: params, jwt: ) end |
#request_headers ⇒ Object
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
118 119 120 121 122 123 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 118 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 |
#success_from(response, action) ⇒ Object
270 271 272 273 274 275 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 270 def success_from(response, action) success = response['status'] == 'Approved' || response['status'] == 'Open' if response['status'] success = response['code'] == '204' if action == 'void' success = !response['bank'].empty? if action == 'verify' && response['bank'] success end |
#supports_scrubbing? ⇒ Boolean
102 103 104 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 102 def supports_scrubbing? true end |
#url(action, params, ref_number: '', credit_card_number: nil) ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 227 def url(action, params, ref_number: '', credit_card_number: nil) case action when 'void' base_url + "/#{ref_number}?force=true" when 'verify' (verify_url + '?search=') + credit_card_number.to_s[0..6] when 'get_payment_status', 'close_batch' batch_url + "/#{params}" when 'create_jwt' jwt_url + "/#{params}/token" else base_url + '?includeCustomerMatches=false&echo=true' end end |
#verify(credit_card, options) ⇒ Object
97 98 99 100 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 97 def verify(credit_card, ) jwt = [:jwt_token] commit('verify', card_number: credit_card.number, jwt: jwt) end |
#verify_url ⇒ Object
246 247 248 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 246 def verify_url test? ? self.test_url_verify : self.live_url_verify end |
#void(authorization, options = {}) ⇒ Object
93 94 95 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 93 def void(, = {}) commit('void', iid: get_hash()['id'], jwt: ) end |