Cancel a Transaction

This code steps you through the process of cancelling a credit card transaction.

You can cancel a transaction if it has not yet been settled. If a transaction has already been settled, then you must issue a refund instead.
For that Go to: Reverse a sale

This code cancels single transactions; it doesn't cancel recurring payments.
For that Go to: Cancel recurring payments

There are three outcomes when processing credit card transactions:

  1. Approved
  2. Declined
  3. Error

'Approved' transactions can be canceled. 'Declined' transactions cannot be canceled. As a result, in order to test the cancellation of a transaction, you must first pass an odd dollar amount. This will return the transaction with an 'Approved' status. Now, you can test the cancellation of that 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 PHP Sample Code
* This code sample runs a $3.00 Credit Card Sale transaction
* against a customer using test payment information.
* If approved, a 2nd transaction is run to cancel this transaction
* If using TEST mode, odd dollar amounts will return
* an approval and even dollar amounts will return a decline.
$accountID = "Merchant's Account ID Here";
$secretKey = "Merchant's Secret Key Here";
$mode = "TEST";
$payment = new BluePay(
'firstName' => 'Bob',
'lastName' => 'Tester',
'addr1' => '1234 Test St.',
'addr2' => 'Apt #500',
'city' => 'Testville',
'state' => 'IL',
'zip' =>'54321',
'country' => 'USA',
'phone' => '1231231234',
'email' => '[email protected]'
'cardNumber' => '4111111111111111', // Card Number: 4111111111111111
'cardExpire' => '1225', // Card Expire: 12/25
'cvv2' => '123' // Card CVV2: 123
'amount' => '3.00'
// If transaction was approved..
if ($payment->isSuccessfulResponse()) {
$cancelPayment = new BluePay(
'masterID' => $payment->getTransID()
// Read response from BluePay
'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 {

Can’t find what you’re
looking for? We can help.

Contact 800-350-2684 for Integration Support.

  • Microsoft Gold Partner Badge
  • 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
  • Best in Biz Awards 2018 Silver Winner Badge for Business Development Department of the Year
  • TSG Gateway Awards 2019 BluePay
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.