RETURN FUNDS TO A CUSTOMER

Reverse Sale

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:

Approved
Declined
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 pay2amigos.php
Or, download via GitHub

<?php
/***
* Pay2amigos 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('../Pay2amigos.php');
$accountID = "Merchant's Account ID Here";
$secretKey = "Merchant's Secret Key Here";
$mode = "TEST";
$payment = new Pay2amigos(
   
$accountID,
   
$secretKey,
   
$mode
);
$payment->setCustomerInformation(array(
   
'firstName' => 'Bob',
   
'lastName' => 'Tester',
   
'addr1' => '1234 Test St.',
&nbp;  
'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' => '1225', // Card Expire: 12/25
   
'cvv2' => '123' // Card CVV2: 123
));
$payment->sale('3.00');
$payment->process();
// If transaction was approved..
if ($payment->isSuccessfulResponse()) {
   
   
$paymentRefund = new Pay2amigos(
       
$accountID,
       
$secretKey,
       
$mode
 & nbsp; 
);
   
$paymentRefund->refund(
       
$payment->getTransID(),
       
'1.75' // partial refund of $1.75
   
);
   
// Makes the API Request to process refund
   
$paymentRefund->process();
   
// Reads the response from Pay2amigos
   
echo
   
'Transaction Status: '. $paymentRefund->getStatus() . "\n" .
   
'Transaction Message: '. $paymentRefund->getMessage() . "\n" .
   
'Transaction ID: '. $paymentRefund->getTransID() . "\n" .
   
'AVS Response: ' . $paymentRefund->getAVSResponse() . "\n" .
   
'CVS Response: ' . $paymentRefund->getCVV2Response() . "\n" .
   
'Masked Account: ' . $paymentRefund->getMaskedAccount() . "\n" .
   
'Card Type: ' . $paymentRefund->getCardType() . "\n" .
   
'Authorization Code: ' . $paymentRefund->getAuthCode() . "\n";
} else {
    echo
$payment->getMessage();
}
?>
Can’t find what you’re
looking for? We can help.

Contact 855-422-9385 for Integration Support.

compress_logo-cred-ms-gold-01a
logo-cred-komen-01a
footer-steve2018-award
cnp-2018-rev
footer-tsg2018-award
compress_pillar_2017