Level 2 & Level 3 Processing

This code steps you through an example of passing Level 2 & Level 3 data with a transaction.

There are three outcomes when processing credit card transactions:

  1. Approved
  2. Declined
  3. Error

'Approved' transactions can be charged against customers' credit cards. 'Declined' transactions can't be charged. As a result, in order to test the process of charging a customer's credit card, you must first pass an odd dollar amount. This returns the transaction with an 'Approved' status. You can then charge the credit card to complete the transaction.

An error could result from a variety of conditions such as missing data, invalid card numbers, and expiration dates provided in invalid formats.

The following sample code calls a routine from our Code Library.
Download BluePay.php
Or, download via GitHub

##
# BluePay Ruby Sample code.
#
# This code sample runs a Credit Card sales transaction,
# including sample Level 2 and 3 processing information,
# against a customer using test payment information.
# If using TEST mode, odd dollar amounts will return
# an approval and even dollar amounts will return a decline.
##

require_relative "../../lib/bluepay.rb"

ACCOUNT_ID = "Merchant's Account ID here"
SECRET_KEY = "Merchant's Secret Key here"
MODE = "TEST" 

payment = BluePay.new(
  account_id: ACCOUNT_ID, 
  secret_key: SECRET_KEY, 
  mode: MODE
)

payment.set_customer_information(
  first_name: "Bob",
  last_name: "Tester",
  address1: "123 Test St.",
  address2: "Apt #500",
  city: "Testville",
  state: "IL",
  zip_code: "54321",
  country: "USA",
  phone: "123-123-1234", 
  email: "[email protected]
)

payment.set_cc_information(
  cc_number: "4111111111111111", # Customer Credit Card Number
  cc_expiration: "1225", # Card Expiration Date: MMYY
  cvv2: "123" # Card CVV2
)

# Set Level 2 Information
payment.invoice_id = "123456789"
payment.amount_tax = "0.91"

# Set Level 3 line item information. Repeat for each item up to 99.
payment.add_line_item(
  quantity: "1", # The number of units of item. Max: 5 digits
  unit_cost: "3.00", # The cost per unit of item. Max: 9 digits decimal
  descriptor: "test1", # Description of the item purchased. Max: 26 character
  commodity_code: "123412341234", # Commodity Codes can be found at http://www.census.gov/svsd/www/cfsdat/2002data/cfs021200.pdf. Max: 12 characters
  product_code: "432143214321", # Merchant-defined code for the product or service being purchased. Max: 12 characters
  measure_units: "EA", # The unit of measure of the item purchase. Normally EA. Max: 3 characters
  tax_rate: "7%", # Tax rate for the item. Max: 4 digits
  tax_amount: "0.21", # Tax amount for the item. unit_cost * quantity * tax_rate = tax_amount. Max: 9 digits.
  item_discount: "0.00", # The amount of any discounts on the item. Max: 12 digits.
  line_item_total: "3.21" # The total amount for the item including taxes and discounts.
)

payment.add_line_item(
  quantity: "2",
  unit_cost: "5.00",
  descriptor: "test2",
  commodity_code: "123412341234",
  product_code: "098709870987",
  measure_units: "EA",
  tax_rate: "7%",
  tax_amount: "0.70",
  item_discount: "0.00",
  line_item_total: "10.70"
)

payment.sale(amount: "13.91") # Sale Amount: $13.91

# Makes the API Request with BluePay
payment.process

# If transaction was successful reads the responses from BluePay
if payment.successful_transaction? 
  puts "TRANSACTION STATUS: " + payment.get_status
  puts "TRANSACTION MESSAGE: " + payment.get_message
  puts "TRANSACTION ID: " + payment.get_trans_id
  puts "AVS RESPONSE: " + payment.get_avs_code
  puts "CVV2 RESPONSE: " + payment.get_cvv2_code
  puts "MASKED PAYMENT ACCOUNT: " + payment.get_masked_account
  puts "CARD TYPE: " + payment.get_card_type
  puts "AUTH CODE: " + payment.get_auth_code
else
  puts payment.get_message
end
Can’t find what you’re
looking for? We can help.

Contact 800-350-2684 for Integration Support.

  • Microsoft Gold Partner Badge
  • Susan G. Komen for the Cure Supporter
  • 2018 American Business Awards Gold Stevie® Winner Badge for Best Payment and Electronic Commerce Solution
  • 2018 CNP Awards Customer Choice Winner Badge for Best E-Commerce Platform/Gateway
  • 2017 TSG Gateway Awards Winner Badge for Best Onboarding Process
  • Best in Biz Awards 2018 Silver Winner Badge for Business Development Department of the Year
BluePay Processing, LLC is a registered ISO of Wells Fargo Bank, N.A., Concord, CA, 94524 U.S.A.
BluePay Canada ULC, is a Registered ISO/MSP of Peoples Trust Company, Vancouver, Canada.