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

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, :key, :secret)
  super
end

Instance Method Details

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



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

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, credit_card, 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[:key]}:#{@options[:secret]}")
end

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



86
87
88
89
90
91
92
93
94
# File 'lib/active_merchant/billing/gateways/priority.rb', line 86

def capture(amount, authorization, options = {})
  params = {}
  add_merchant_id(params)
  add_amount(params, amount, options)
  params['paymentToken'] = payment_token(authorization) || options[:payment_token]
  params['tenderType'] = options[:tender_type].present? ? options[:tender_type] : 'Card'

  commit('capture', params: params)
end

#close_batch(batch_id) ⇒ Object



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

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

#create_jwtObject



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

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

#get_payment_status(batch_id) ⇒ Object



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

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
# 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, credit_card, options)

  commit('purchase', params: params)
end

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



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

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



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

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)


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

def supports_scrubbing?
  true
end

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



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

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

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

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



96
97
98
99
100
# File 'lib/active_merchant/billing/gateways/priority.rb', line 96

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

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