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_bank(params, auth_code) ⇒ Object
- #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
- #add_type_merchant_refund(params, 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(succeeded, response) ⇒ Object
- #parse(body) ⇒ Object
- #post_data(params) ⇒ Object
- #purchase(amount, credit_card, options = {}) ⇒ Object
- #purchases ⇒ Object
- #refund(amount, credit_card, 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_bank(params, auth_code) ⇒ Object
126 127 128 129 130 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 126 def add_bank(params, auth_code) params['authCode'] = auth_code params['authOnly'] = false params['availableAuthAmount'] = 0 end |
#add_credit_card(params, credit_card, action, options) ⇒ Object
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 157 158 159 160 161 162 163 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 132 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] card_details['avsZip'] = [:billing_address][:zip] 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
341 342 343 344 345 346 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 341 def add_pos_data() = {} ['panCaptureMethod'] = [:pan_capture_method] end |
#add_purchases_data(options) ⇒ Object
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 348 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
373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 373 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
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 173 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] params['taxExempt'] = false params['tenderType'] = [:tender_type] end |
#add_type_merchant_refund(params, options) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 194 def add_type_merchant_refund(params, ) params['cardPresent'] = [:card_present] params['clientReference'] = [:client_ref] params['created'] = [:created] params['creatorName'] = [:creator_name] params['currency'] = [:currency] params['customerCode'] = [:customer_code] params['enteredAmount'] = [:amount] params['id'] = 0 params['invoice'] = [:invoice] params['isDuplicate'] = false params['merchantId'] = @options[:merchant_id] params['paymentToken'] = [:payment_token] params['posData'] = add_pos_data([:pos_data]) if [:pos_data] params['purchases'] = add_purchases_data([:purchases][0]) if [:purchases] params['reference'] = [:reference] params['requireSignature'] = false params['risk'] = add_risk_data([:risk]) if [:risk] params['settledAmount'] = [:settled_amt] params['settledCurrency'] = [:settled_currency] params['settledDate'] = [:created] params['shipToCountry'] = [:ship_to_country] params['shouldGetCreditCardLevel'] = [:should_get_credit_card_level] params['source'] = [:source] params['status'] = [:status] params['tax'] = [:tax] params['taxExempt'] = [:tax_exempt] params['tenderType'] = [:tender_type] params['type'] = [:type] end |
#authorization_from(response) ⇒ Object
326 327 328 329 330 331 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 326 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
285 286 287 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 285 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
297 298 299 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 297 def batch_url test? ? self.test_url_batch : self.live_url_batch end |
#capture(amount, authorization, options = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 81 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'] = [:tender_type] commit('capture', params: params, jwt: ) end |
#close_batch(batch_id, options) ⇒ Object
111 112 113 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 111 def close_batch(batch_id, ) commit('close_batch', params: batch_id, jwt: ) end |
#commit(action, params: '', iid: '', card_number: nil, jwt: '') ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 230 def commit(action, params: '', iid: '', card_number: nil, jwt: '') response = begin case action when 'void' 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' 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, (success, response), response, authorization: success && response['code'] != '204' ? (response) : nil, error_code: success || response['code'] == '204' || response == '' ? nil : error_from(response), test: test? ) end |
#create_jwt(options) ⇒ Object
115 116 117 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 115 def create_jwt() commit('create_jwt', params: @options[:merchant_id], jwt: ) end |
#error_from(response) ⇒ Object
333 334 335 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 333 def error_from(response) response['errorCode'] end |
#exp_date(credit_card) ⇒ Object
165 166 167 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 165 def exp_date(credit_card) "#{format(credit_card.month, :two_digits)}/#{format(credit_card.year, :two_digits)}" end |
#get_hash(string) ⇒ Object
385 386 387 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 385 def get_hash(string) JSON.parse(string.gsub('=>', ':')) end |
#get_payment_status(batch_id, options) ⇒ Object
107 108 109 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 107 def get_payment_status(batch_id, ) commit('get_payment_status', params: batch_id, jwt: ) end |
#handle_response(response) ⇒ Object
260 261 262 263 264 265 266 267 268 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 260 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
293 294 295 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 293 def jwt_url test? ? self.test_url_jwt : self.live_url_jwt end |
#message_from(succeeded, response) ⇒ Object
318 319 320 321 322 323 324 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 318 def (succeeded, response) if succeeded response['status'] else response['authMessage'] end end |
#parse(body) ⇒ Object
301 302 303 304 305 306 307 308 309 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 301 def parse(body) 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
337 338 339 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 337 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
169 170 171 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 169 def purchases [{ taxRate: '0.0000', additionalTaxRate: nil, discountRate: nil }] end |
#refund(amount, credit_card, options) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 71 def refund(amount, credit_card, ) params = {} # refund amounts must be negative params['amount'] = ('-' + localized_amount(amount.to_f, [:currency])).to_f add_bank(params, [:auth_code]) add_credit_card(params, credit_card, 'refund', ) unless [:auth_code] add_type_merchant_refund(params, ) 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
119 120 121 122 123 124 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 119 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
311 312 313 314 315 316 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 311 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
103 104 105 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 103 def supports_scrubbing? true end |
#url(action, params, ref_number: '', credit_card_number: nil) ⇒ Object
270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 270 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
98 99 100 101 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 98 def verify(credit_card, ) jwt = [:jwt_token] commit('verify', card_number: credit_card.number, jwt: jwt) end |
#verify_url ⇒ Object
289 290 291 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 289 def verify_url test? ? self.test_url_verify : self.live_url_verify end |
#void(authorization, options) ⇒ Object
94 95 96 |
# File 'lib/active_merchant/billing/gateways/priority.rb', line 94 def void(, ) commit('void', iid: get_hash()['id'], jwt: ) end |