Charge a Customer

This code steps you through the process of charging a customer's credit card.

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

Run a Credit Card Payment

<?php
/**
* BluePay PHP Sample Code
*
* This code sample runs a $3.00 Credit Card Sale transaction
* 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.
*
*/

include('BluePay.php');
 
$accountID = "Merchant's Account ID Here";
$secretKey = "Merchant's Secret Key Here";
$mode = "TEST";
 
$payment = new BluePay(
   
$accountID,
   
$secretKey,
   
$mode
);

$payment->setCustomerInformation(array(
   
'firstName' => 'Bob',
   
'lastName' => 'Tester',
   
'addr1' => '1234 Test St.',
   
'addr2' => 'Apt #500',
   
'city' => 'Testville',
   
'state' => 'IL',
   
'zip' =>'54321',
   
'country' => 'USA',
   
'phone' => '1231231234',
   
'email' => '[email protected]'
));
 
$payment->setCCInformation(array(
   
'cardNumber' => '4111111111111111', // Card Number: 4111111111111111
   
'cardExpire' => '1215', // Card Expire: 12/15
   
'cvv2' => '123' // Card CVV2: 123
));
 
$payment->sale('3.00'); // Sale Amount: $3.00
 
// Makes the API request with BluePAy
$payment->process();
 
// Reads the response from BluePay
if($payment->isSuccessfulResponse()){
    echo
   
'Transaction Status: '. $payment->getStatus() . "\n" .
   
'Transaction Message: '. $payment->getMessage() . "\n" .
   
'Transaction ID: '. $payment->getTransID() . "\n" .
   
'AVS Response: ' . $payment->getAVSResponse() . "\n" .
   
'CVS Response: ' . $payment->getCVV2Response() . "\n" .
   
'Masked Account: ' . $payment->getMaskedAccount() . "\n" .
   
'Card Type: ' . $payment->getCardType() . "\n" .
   
'Authorization Code: ' . $payment->getAuthCode() . "\n";
} else{
    echo
$payment->getMessage() . "\n";
}
?>

Run an ACH payment

<?php
/**
  * BluePay PHP Sample Code
  *
  * This code sample runs a $3.00 ACH Sale transaction
  * against a customer using test payment information.
  *
  */
include('BluePay.php');

$accountID = "Merchant's Account ID Here";
$secretKey = "Merchant's Secret Key Here";
$mode = "TEST";

$payment = new BluePay(
   
$accountID,
   
$secretKey,
   
$mode
);

$payment->setCustomerInformation(array(
   
'firstName' => 'Bob',
   
'lastName' => 'Tester',
   
'addr1' => '1234 Test St.',
   
'addr2' => 'Apt #500',
   
'city' => 'Testville',
   
'state' => 'IL',
   
'zip' =>'54321',
   
'country' => 'USA',
   
'phone' => '1231231234',
   
'email' => '[email protected]'
));

$payment->setACHInformation(array(
   
'routingNumber' =>'123123123', // Routing Number: 123123123
   
'accountNumber' => '1234567890', // Account Number: 1234567890
   
'accountType' => 'C', // Account Type: Checking
   
'documentType' => 'WEB' // ACH Document Type: WEB
));

$payment->sale('3.00'); // Sale Amount: $3.00

// Makes the API Request with BluePay
$payment->process();

// Read response from BluePay
if($payment->isSuccessfulResponse()){
    echo
   
'Status: '. $payment->getStatus() . "\n" .
   
'Message: '. $payment->getMessage() . "\n" .
   
'Transaction ID: '. $payment->getTransID() . "\n" .
   
'Masked Account: ' . $payment->getMaskedAccount() . "\n" .
   
'Customer Bank: ' . $payment->getBank() . "\n";
} else{
    echo
$payment->getMessage() . "\n";
}
?>
BluePay Processing, LLC is a registered ISO of Wells Fargo Bank, N.A., Walnut Creek, CA, U.S.A.
BluePay Canada ULC, is a Registered ISO/MSP of Peoples Trust Company, Vancouver, Canada.