class ActiveMerchant::Billing::PayJunctionV2Gateway
Public Class Methods
new(options={})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 15 def initialize(options={}) requires!(options, :api_login, :api_password, :api_key) super end
Public Instance Methods
capture(amount, authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 37 def capture(amount, authorization, options={}) post = {} post[:status] = 'CAPTURE' post[:transactionId] = authorization add_invoice(post, amount, options) commit('capture', post) end
credit(amount, payment_method, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 63 def credit(amount, payment_method, options={}) post = {} post[:action] = 'REFUND' add_invoice(post, amount, options) add_payment_method(post, payment_method) commit('credit', post) end
purchase(amount, payment_method, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 20 def purchase(amount, payment_method, options={}) post = {} add_invoice(post, amount, options) add_payment_method(post, payment_method) commit('purchase', post) end
refund(amount, authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 54 def refund(amount, authorization, options={}) post = {} post[:action] = 'REFUND' post[:transactionId] = authorization add_invoice(post, amount, options) commit('refund', post) end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 87 def scrub(transcript) transcript. gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]'). gsub(%r((X-Pj-Application-Key: )[\w-]+), '\1[FILTERED]'). gsub(%r((cardNumber=)\d+), '\1[FILTERED]'). gsub(%r((cardCvv=)\d+), '\1[FILTERED]') end
store(payment_method, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 79 def store(payment_method, options = {}) verify(payment_method, options) end
supports_scrubbing?()
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 83 def supports_scrubbing? true end
verify(credit_card, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 72 def verify(credit_card, options={}) MultiResponse.run(:use_first_response) do |r| r.process { authorize(100, credit_card, options) } r.process(:ignore_result) { void(r.authorization, options) } end end
void(authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 46 def void(authorization, options={}) post = {} post[:status] = 'VOID' post[:transactionId] = authorization commit('void', post) end
Private Instance Methods
add_invoice(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 97 def add_invoice(post, money, options) post[:amountBase] = amount(money) if money post[:invoiceNumber] = options[:order_id] if options[:order_id] end
add_payment_method(post, payment_method)
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 102 def add_payment_method(post, payment_method) if payment_method.is_a? Integer post[:transactionId] = payment_method else post[:cardNumber] = payment_method.number post[:cardExpMonth] = format(payment_method.month, :two_digits) post[:cardExpYear] = format(payment_method.year, :four_digits) post[:cardCvv] = payment_method.verification_value end end
commit(action, params)
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 113 def commit(action, params) response = begin parse(ssl_invoke(action, params)) rescue ResponseError => e parse(e.response.body) end success = success_from(response) Response.new( success, message_from(response), response, authorization: success ? authorization_from(response) : nil, error_code: success ? nil : error_from(response), test: test? ) end
error_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 183 def error_from(response) response['response']['code'] if response['response'] end
headers()
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 139 def headers { 'Authorization' => 'Basic ' + Base64.encode64("#{@options[:api_login]}:#{@options[:api_password]}").strip, 'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8', 'Accept' => 'application/json', 'X-PJ-Application-Key' => @options[:api_key].to_s } end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 173 def message_from(response) return response['response']['message'] if response['response'] response['errors']&.inject('') { |message, error| error['message'] + '|' + message } end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 156 def parse(body) JSON.parse(body) rescue JSON::ParserError message = 'Invalid JSON response received from PayJunctionV2Gateway. Please contact PayJunctionV2Gateway if you continue to receive this message.' message += " (The raw response returned by the API was #{body.inspect})" { 'errors' => [{ 'message' => message }] } end
post_data(params)
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 148 def post_data(params) params.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&') end
ssl_invoke(action, params)
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 131 def ssl_invoke(action, params) if ['purchase', 'authorize', 'refund', 'credit'].include?(action) ssl_post(url(), post_data(params), headers) else ssl_request(:put, url(params), post_data(params), headers) end end
success_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 168 def success_from(response) return response['response']['approved'] if response['response'] false end
url(params={})
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 152 def url(params={}) test? ? "#{test_url}/#{params[:transactionId]}" : "#{live_url}/#{params[:transactionId]}" end