Return Funds to a Customer

This code steps you through the process of refunding payments that have been made on settled transactions.

There are three outcomes when processing credit card transactions:

  1. Approved
  2. Declined
  3. Error
Refunds can only be run on 'Approved' transactions that have been settled. 'Declined' transactions cannot be refunded. As a result, in order to test the refund process, you must first pass an odd dollar amount. This will return the transaction with an 'Approved' status. Then, you can test a refund for 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

<?php

/***
* 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 refund the customer
* for $1.75.
* 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";

// Merchant's Account ID
// Merchant's Secret Key
// Transaction Mode: TEST (can also be LIVE)
$payment = new BluePay(
   
$accountID,
   
$secretKey,
   
$mode);

// First Name: Bob
// Last Name: Tester
// Address1: 123 Test St.
// Address2: Apt #500
// City: Testville
// State: IL
// Zip: 54321
// Country: USA
$payment->setCustomerInformation(
   
'Bob',
   
'Tester',
   
'123 Test St.',
   
'Apt #1009',
   
'Testville',
   
'IL',
   
'54321',
   
'USA');

// Card Number: 4111111111111111
// Card Expire: 12/15
// Card CVV2: 123
$payment->setCCInformation(
   
'4111111111111111',
   
'1215',
   
'123');

// Phone #: 123-123-1234
$payment->setPhone('1231231234');

// Email Address: [email protected]
$payment->setEmail('[email protected]');

/* RUN A $3.00 CREDIT CARD SALE */
$payment->sale('3.00');

$payment->process();

// If transaction was approved..
if ($payment->getStatus() == "APPROVED") {
   
$paymentRefund = new BluePay(
       
$accountID,
       
$secretKey,
       
$mode);

   
$paymentRefund->refund($payment->getTransID(), '1.75');

   
$paymentRefund->process();

   
// Read response from BluePay
   
echo 'Status: '. $paymentRefund->getStatus() . '<br />' .
   
'Message: '. $paymentRefund->getMessage() . '<br />' .
   
'Transaction ID: '. $paymentRefund->getTransID() . '<br />' .
   
'AVS Response: ' . $paymentRefund->getAVSResponse() . '<br />' .
   
'CVS Response: ' . $paymentRefund->getCVV2Response() . '<br />' .
   
'Masked Account: ' . $paymentRefund->getMaskedAccount() . '<br />' .
   
'Card Type: ' . $paymentRefund->getCardType() . '<br />' .
   
'Authorization Code: ' . $paymentRefund->getAuthCode() . '<br />';
} else {
    echo
$payment->getMessage();
}
?>

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.