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 39 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 65 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) add_address(post, options) commit('purchase', post) end
refund(amount, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 56 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 89 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 81 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 85 def supports_scrubbing? true end
verify(credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 74 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 48 def void(authorization, options = {}) post = {} post[:status] = 'VOID' post[:transactionId] = authorization commit('void', post) end
Private Instance Methods
add_address(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 115 def add_address(post, options) if address = options[:billing_address] post[:billingFirstName] = address[:first_name] if address[:first_name] post[:billingLastName] = address[:last_name] if address[:last_name] post[:billingCompanyName] = address[:company] if address[:company] post[:billingPhone] = address[:phone_number] if address[:phone_number] post[:billingAddress] = address[:address1] if address[:address1] post[:billingCity] = address[:city] if address[:city] post[:billingState] = address[:state] if address[:state] post[:billingCountry] = address[:country] if address[:country] post[:billingZip] = address[:zip] if address[:zip] end end
add_invoice(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/pay_junction_v2.rb, line 99 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 104 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 129 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 201 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 156 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 191 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 173 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 165 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 148 def ssl_invoke(action, params) if %w[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 185 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 169 def url(params = {}) test? ? "#{test_url}/#{params[:transactionId]}" : "#{live_url}/#{params[:transactionId]}" end