class ActiveMerchant::Billing::JetpayGateway
Constants
- ACTION_CODE_MESSAGES
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/jetpay.rb, line 154 def initialize(options = {}) requires!(options, :login) super end
Public Instance Methods
capture(money, reference, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 167 def capture(money, reference, options = {}) split_authorization = reference.split(';') transaction_id = split_authorization[0] token = split_authorization[3] commit(money, build_capture_request(transaction_id, money, options), token) end
credit(money, transaction_id_or_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 179 def credit(money, transaction_id_or_card, options = {}) if transaction_id_or_card.is_a?(String) ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE refund(money, transaction_id_or_card, options) else commit(money, build_credit_request('CREDIT', money, nil, transaction_id_or_card, nil, options)) end end
purchase(money, credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 159 def purchase(money, credit_card, options = {}) commit(money, build_sale_request(money, credit_card, options)) end
refund(money, reference, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 188 def refund(money, reference, options = {}) split_authorization = reference.split(';') transaction_id = split_authorization[0] token = split_authorization[3] credit_card = options[:credit_card] commit(money, build_credit_request('CREDIT', money, transaction_id, credit_card, token, options)) end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 200 def scrub(transcript) transcript. gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]'). gsub(%r((>)\d+(</CardNum>)), '\1[FILTERED]\2'). gsub(%r((<CVV2>)\d+(</CVV2>)), '\1[FILTERED]\2') end
supports_scrubbing()
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 196 def supports_scrubbing true end
void(reference, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 174 def void(reference, options = {}) transaction_id, approval, amount, token = reference.split(';') commit(amount.to_i, build_void_request(amount.to_i, transaction_id, approval, token, options), token) end
Private Instance Methods
add_addresses(xml, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 350 def add_addresses(xml, options) if billing_address = options[:billing_address] || options[:address] xml.tag! 'BillingAddress', [billing_address[:address1], billing_address[:address2]].compact.join(' ') xml.tag! 'BillingCity', billing_address[:city] xml.tag! 'BillingStateProv', billing_address[:state] xml.tag! 'BillingPostalCode', billing_address[:zip] xml.tag! 'BillingCountry', lookup_country_code(billing_address[:country]) xml.tag! 'BillingPhone', billing_address[:phone] end if shipping_address = options[:shipping_address] xml.tag! 'ShippingInfo' do xml.tag! 'ShippingName', shipping_address[:name] xml.tag! 'ShippingAddr' do xml.tag! 'Address', [shipping_address[:address1], shipping_address[:address2]].compact.join(' ') xml.tag! 'City', shipping_address[:city] xml.tag! 'StateProv', shipping_address[:state] xml.tag! 'PostalCode', shipping_address[:zip] xml.tag! 'Country', lookup_country_code(shipping_address[:country]) end end end end
add_credit_card(xml, credit_card)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 340 def add_credit_card(xml, credit_card) xml.tag! 'CardNum', credit_card.number, 'Tokenize' => true xml.tag! 'CardExpMonth', format_exp(credit_card.month) xml.tag! 'CardExpYear', format_exp(credit_card.year) xml.tag! 'CardName', [credit_card.first_name, credit_card.last_name].compact.join(' ') if credit_card.first_name || credit_card.last_name xml.tag! 'CVV2', credit_card.verification_value unless credit_card.verification_value.nil? || (credit_card.verification_value.length == 0) end
add_customer_data(xml, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 375 def add_customer_data(xml, options) xml.tag! 'Email', options[:email] if options[:email] xml.tag! 'UserIPAddress', options[:ip] if options[:ip] end
add_invoice_data(xml, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 380 def add_invoice_data(xml, options) xml.tag! 'OrderNumber', options[:order_id] if options[:order_id] xml.tag! 'TaxAmount', amount(options[:tax]) if options[:tax] end
add_user_defined_fields(xml, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 385 def add_user_defined_fields(xml, options) xml.tag! 'UDField1', options[:ud_field_1] if options[:ud_field_1] xml.tag! 'UDField2', options[:ud_field_2] if options[:ud_field_2] xml.tag! 'UDField3', options[:ud_field_3] if options[:ud_field_3] end
build_authonly_request(money, credit_card, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 239 def build_authonly_request(money, credit_card, options) build_xml_request('AUTHONLY') do |xml| add_credit_card(xml, credit_card) add_addresses(xml, options) add_customer_data(xml, options) add_invoice_data(xml, options) add_user_defined_fields(xml, options) xml.tag! 'TotalAmount', amount(money) xml.target! end end
build_capture_request(transaction_id, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 252 def build_capture_request(transaction_id, money, options) build_xml_request('CAPT', options, transaction_id) do |xml| xml.tag! 'TotalAmount', amount(money) add_user_defined_fields(xml, options) end end
build_credit_request(transaction_type, money, transaction_id, card, token, options)
click to toggle source
‘transaction_id` may be nil for unlinked credit transactions.
# File lib/active_merchant/billing/gateways/jetpay.rb, line 269 def build_credit_request(transaction_type, money, transaction_id, card, token, options) build_xml_request(transaction_type, options, transaction_id) do |xml| add_credit_card(xml, card) if card add_invoice_data(xml, options) add_addresses(xml, options) add_customer_data(xml, options) add_user_defined_fields(xml, options) xml.tag! 'TotalAmount', amount(money) xml.tag! 'Token', token if token xml.target! end end
build_sale_request(money, credit_card, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 226 def build_sale_request(money, credit_card, options) build_xml_request('SALE', options) do |xml| add_credit_card(xml, credit_card) add_addresses(xml, options) add_customer_data(xml, options) add_invoice_data(xml, options) add_user_defined_fields(xml, options) xml.tag! 'TotalAmount', amount(money) xml.target! end end
build_void_request(money, transaction_id, approval, token, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 259 def build_void_request(money, transaction_id, approval, token, options) build_xml_request('VOID', options, transaction_id) do |xml| xml.tag! 'Approval', approval xml.tag! 'TotalAmount', amount(money) xml.tag! 'Token', token if token xml.target! end end
build_xml_request(transaction_type, options = {}, transaction_id = nil) { |xml| ... }
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 209 def build_xml_request(transaction_type, options = {}, transaction_id = nil, &block) xml = Builder::XmlMarkup.new xml.tag! 'JetPay' do # The basic values needed for any request xml.tag! 'TerminalID', @options[:login] xml.tag! 'TransactionType', transaction_type xml.tag! 'TransactionID', transaction_id.nil? ? generate_unique_id.slice(0, 18) : transaction_id xml.tag! 'Origin', options[:origin] if options && options[:origin] if block_given? yield xml else xml.target! end end end
commit(money, request, token = nil)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 283 def commit(money, request, token = nil) response = parse(ssl_post(url, request)) success = success?(response) Response.new( success, success ? 'APPROVED' : message_from(response), response, test: test?, authorization: authorization_from(response, money, token), avs_result: { code: response[:avs] }, cvv_result: response[:cvv2] ) end
format_exp(value)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 323 def format_exp(value) format(value, :two_digits) end
lookup_country_code(code)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 391 def lookup_country_code(code) country = Country.find(code) rescue nil country&.code(:alpha3) end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 331 def message_from(response) ACTION_CODE_MESSAGES[response[:action_code]] end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 303 def parse(body) return {} if body.blank? xml = REXML::Document.new(body) response = {} xml.root.elements.to_a.each do |node| parse_element(response, node) end response end
parse_element(response, node)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 315 def parse_element(response, node) if node.has_elements? node.elements.each { |element| parse_element(response, element) } else response[node.name.underscore.to_sym] = node.text end end
success?(response)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 327 def success?(response) response[:action_code] == '000' end
url()
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 298 def url live_url = @options[:region] == 'CA' ? live_ca_url : live_us_url test? ? test_url : live_url end