Example refund code

The refund functionality offers the same advanced and simple versions as the charging code. Similarly we recommend use of the advanced method of performing refunds as it affords a greater level of end-user feedback. Here's some sample code for performing a refund using the simple method:

<?php

require_once('anchor_ccard_live.php');

$ccardno    = $_POST['cc_number'];
$ccardexp   = sprintf('%02d%02d', $_POST['cc_expmonth'], $_POST['cc_expyear']);
$amount     = 90.00;
$invoice_id = 7264;
$txnref     = "Invoice $invoice_id";

$failure    = refund_ccard($ccardno, $ccardexp, $amount, $txnref);

print "Your transaction has " . (!$failure ? 'Succeeded' : 'Failed');

if (!$failure {
    # send a receipt.
} else {
    # send an invoice.
}

?>

This is an example that uses the advanced method:

<?php

require_once('anchor_ccard_live.php');

$ccardno    = $_POST['cc_number'];
$ccardexp   = sprintf('%02d%02d', $_POST['cc_expmonth'], $_POST['cc_expyear']);
$amount     = 90.00;
$invoice_id = 7264;
$txnref     = "Invoice $invoice_id";

$result     = refund_ccard_detailed($ccardno, $ccardexp, $amount, $txnref);
$failure    = $result['summaryCode'];

if (!$failure) {
    print "Your transaction has succeeded.";
    # send a receipt.
} else {
    print "Your transaction failed: <b>" . $result['responseText'] . "</b>";
    # ask your user to retry payment.
}

?>