class ActiveMerchant::Billing::JetpayV2Gateway
Constants
- ACTION_CODE_MESSAGES
- API_VERSION
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 151 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_v2.rb, line 164 def capture(money, reference, options = {}) transaction_id, _, _, token = reference.split(';') commit(money, build_capture_request(money, transaction_id, options), token) end
credit(money, payment, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 174 def credit(money, payment, options = {}) commit(money, build_credit_request(money, nil, payment, options)) end
purchase(money, payment, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 156 def purchase(money, payment, options = {}) commit(money, build_sale_request(money, payment, options)) end
refund(money, reference, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 178 def refund(money, reference, options = {}) transaction_id, _, _, token = reference.split(';') commit(money, build_credit_request(money, transaction_id, token, options), token) end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 195 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
store(credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 187 def store(credit_card, options = {}) commit(nil, build_store_request(credit_card, options)) end
supports_scrubbing()
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 191 def supports_scrubbing true end
verify(credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 183 def verify(credit_card, options = {}) authorize(0, credit_card, options) end
void(reference, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 169 def void(reference, options = {}) transaction_id, _, amount, token = reference.split(';') commit(amount.to_i, build_void_request(amount.to_i, transaction_id, options), token) end
Private Instance Methods
add_addresses(xml, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 380 def add_addresses(xml, options) if billing_address = options[:billing_address] || options[:address] xml.tag! 'Billing' do xml.tag! 'Address', [billing_address[:address1], billing_address[:address2]].compact.join(' ') xml.tag! 'City', billing_address[:city] xml.tag! 'StateProv', billing_address[:state] xml.tag! 'PostalCode', billing_address[:zip] xml.tag! 'Country', lookup_country_code(billing_address[:country]) xml.tag! 'Phone', billing_address[:phone] xml.tag! 'Email', options[:email] if options[:email] end end if shipping_address = options[:shipping_address] xml.tag! 'Shipping' do xml.tag! 'Name', shipping_address[:name] 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]) xml.tag! 'Phone', shipping_address[:phone] end end end
add_credit_card(xml, credit_card)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 366 def add_credit_card(xml, credit_card) xml.tag! 'CardNum', credit_card.number, 'CardPresent' => false, 'Tokenize' => true xml.tag! 'CardExpMonth', format_exp(credit_card.month) xml.tag! 'CardExpYear', format_exp(credit_card.year) if credit_card.first_name || credit_card.last_name xml.tag! 'CardName', [credit_card.first_name, credit_card.last_name].compact.join(' ') end unless credit_card.verification_value.nil? || (credit_card.verification_value.length == 0) xml.tag! 'CVV2', credit_card.verification_value end end
add_customer_data(xml, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 406 def add_customer_data(xml, options) 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_v2.rb, line 410 def add_invoice_data(xml, options) xml.tag! 'OrderNumber', options[:order_id] if options[:order_id] if tax_amount = options[:tax_amount] xml.tag! 'TaxAmount', tax_amount, {'ExemptInd' => options[:tax_exempt] || 'false'} end end
add_payment(xml, payment)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 354 def add_payment(xml, payment) return unless payment if payment.is_a? String token = payment _, _, _, token = payment.split(';') if payment.include? ';' xml.tag! 'Token', token if token else add_credit_card(xml, payment) end end
add_purchase_order(xml, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 417 def add_purchase_order(xml, options) if purchase_order = options[:purchase_order] xml.tag! 'Billing' do xml.tag! 'CustomerPO', purchase_order end end end
add_user_defined_fields(xml, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 425 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, payment, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 240 def build_authonly_request(money, payment, options) build_xml_request('AUTHONLY', options) do |xml| add_payment(xml, payment) 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(money, transaction_id, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 253 def build_capture_request(money, transaction_id, options) build_xml_request('CAPT', options, transaction_id) do |xml| add_invoice_data(xml, options) add_purchase_order(xml, options) add_user_defined_fields(xml, options) xml.tag! 'TotalAmount', amount(money) xml.target! end end
build_credit_request(money, transaction_id, payment, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 271 def build_credit_request(money, transaction_id, payment, options) build_xml_request('CREDIT', options, transaction_id) do |xml| add_payment(xml, payment) 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.target! end end
build_sale_request(money, payment, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 227 def build_sale_request(money, payment, options) build_xml_request('SALE', options) do |xml| add_payment(xml, payment) 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_store_request(credit_card, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 284 def build_store_request(credit_card, options) build_xml_request('TOKENIZE', options) do |xml| add_payment(xml, credit_card) add_addresses(xml, options) add_customer_data(xml, options) xml.target! end end
build_void_request(money, transaction_id, options)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 264 def build_void_request(money, transaction_id, options) build_xml_request('VOID', options, transaction_id) do |xml| xml.tag! 'TotalAmount', amount(money) 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_v2.rb, line 204 def build_xml_request(transaction_type, options = {}, transaction_id = nil, &block) xml = Builder::XmlMarkup.new xml.tag! 'JetPay', 'Version' => API_VERSION do # 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] || 'INTERNET' xml.tag! 'IndustryInfo', 'Type' => options[:industry_info] || 'ECOMMERCE' xml.tag! 'Application', (options[:application] || 'n/a'), {'Version' => options[:application_version] || '1.0'} xml.tag! 'Device', (options[:device] || 'n/a'), {'Version' => options[:device_version] || '1.0'} xml.tag! 'Library', 'VirtPOS SDK', 'Version' => '1.5' xml.tag! 'Gateway', 'JetPay' xml.tag! 'DeveloperID', options[:developer_id] || 'n/a' 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_v2.rb, line 294 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 => AVSResult.new(:code => response[:avs]), :cvv_result => CVVResult.new(response[:cvv2]), :error_code => success ? nil : error_code_from(response) ) end
error_code_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 350 def error_code_from(response) response[:action_code] end
format_exp(value)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 333 def format_exp(value) format(value, :two_digits) end
lookup_country_code(code)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 431 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_v2.rb, line 341 def message_from(response) ACTION_CODE_MESSAGES[response[:action_code]] end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 313 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_v2.rb, line 325 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_v2.rb, line 337 def success?(response) response[:action_code] == '000' end
url()
click to toggle source
# File lib/active_merchant/billing/gateways/jetpay_v2.rb, line 309 def url test? ? test_url : live_url end