0
votes

I'm using a gift certificate script for a restaurant so people can purchase gift certificates. The script captures all the needed information and sends it to Authorize.net via the AIM method. The restaurant manager receives an e-mail transmittal from Authorize.net with the transaction information in it.

All the main fields are being passed to Authorize.net. However, the fields that we would call "merchant-defined fields" are not showing up in the Authorize.net e-mail transmittal. I know that there is a way to reference these fields as MDF fields, but I can't figure out the syntax.

Can someone help me figure out what lines I'm leaving out?

Here's the form that captures the fields in question:

<form method="POST" action="cart.php">
    <fieldset>
        <div class="form-divider">
            <label>Amount</label>
            <select name="amount">
                <?php for($i=5;$i<101;$i=$i+5){ ?>
                    <option value="<?php echo $i; ?>">$<?php echo $i; ?></option>
                <?php } ?>
            </select>
        </div>
        <div class="form-divider">
            <label>Will gift certificate be mailed directly to the recipient?</label>
            <input name="gift" type="radio" value="1" onclick="$('#gift-options').show();" />
            <label>Yes</label>
            <input name="gift" type="radio" value="0" checked="checked" onclick="$('#gift-options').hide();" />
            <label>No</label>
        </div>
        <div id="gift-options">
            <div class="col1">
                <div class="form-divider">
                    <label>To</label>
                    <input name="gift-to" type="text" size="20" />
                </div>
                <div class="form-divider">
                    <label>From</label>
                    <input name="gift-from" type="text" size="20" />
                </div>
            </div>
            <div class="col2">
                <div class="form-divider">
                    <label>Ship To Address</label>
                    <textarea name="gift-address" style="width: 200px; height: 50px;"></textarea>
                </div>
                <div class="form-divider">
                    <label>Gift Message</label>
                    <textarea name="gift-message" style="width: 200px; height: 50px;"></textarea>
                </div>
            </div>
        </div>
        <div class="form-divider">
            <label>Quantity</label>
            <input name="quantity" type="text" value="1" />
        </div>
        <input type="hidden" name="action" value="add" />
    </fieldset>
    <input type="submit" value="Next Step" class="button" />
</form>

And here is "checkout" code, which gathers the data that is actually sent to Authorize.net:

<?php
require 'config.php';
session_start();
error_reporting(E_ALL);
ini_set('display_errors','On');

include('elements/loader.php');

$loader=new GiftCardLoader(true,true,true);
if($loader->checkStep(true)){ echo '<meta http-equiv="refresh" content="0;url=cart.php"> '; }

$amount=0;
foreach($loader->cart as $item){
    $amount+=($item['quantity']*$item['amount']);
}
$method=$loader->getShippingMethod();
$amount+=$method['price'];

$a = new PDAuthorizeNet;

/* Set all of the authnet info */
$a->add_field('x_login', $x_login);
$a->add_field('x_tran_key', $x_transkey);
$a->add_field('x_version', '3.1');
$a->add_field('x_type', 'AUTH_CAPTURE');
$a->add_field('x_test_request', 'FALSE'); 
$a->add_field('x_relay_response', 'FALSE');

$a->add_field('x_delim_data', 'TRUE');
$a->add_field('x_delim_char', '|');     
$a->add_field('x_encap_char', '');

/* Billing Information */
$a->add_field('x_first_name', $loader->address['billing']['x_first_name']);
$a->add_field('x_last_name', $loader->address['billing']['x_last_name']);
$a->add_field('x_address', $loader->address['billing']['x_address']);
$a->add_field('x_city', $loader->address['billing']['x_city']);
$a->add_field('x_state', $loader->address['billing']['x_state']);
$a->add_field('x_zip', $loader->address['billing']['x_zip']);
$a->add_field('x_country', $loader->address['billing']['x_country']);
$a->add_field('x_email', $loader->address['billing']['x_email']);

/* Shipping Information */
$a->add_field('x_ship_to_first_name', $loader->address['shipping']['x_first_name']);
$a->add_field('x_ship_to_last_name', $loader->address['shipping']['x_last_name']);
$a->add_field('x_ship_to_address', $loader->address['shipping']['x_address']);
$a->add_field('x_ship_to_city', $loader->address['shipping']['x_city']);
$a->add_field('x_ship_to_state', $loader->address['shipping']['x_state']);
$a->add_field('x_ship_to_zip', $loader->address['shipping']['x_zip']);
$a->add_field('x_ship_to_country', $loader->address['shipping']['x_country']);
$a->add_field('x_ship_to_email', $loader->address['shipping']['x_email']);

/* Credit Card Information */
$a->add_field('x_method', 'CC');
$a->add_field('x_card_num', $loader->sale['x_card_num']); 
$a->add_field('x_amount', $amount);
$a->add_field('x_exp_date', $loader->sale['x_exp_date']);
$a->add_field('x_card_code', $loader->sale['x_card_code']);

$billing=$loader->address['billing'];
$shipping=$loader->address['shipping'];
$body ="<h3>Order Details</h3>";
$body.="<table width='100%' cellpadding='5' border='1'>";
$body.="<tr>";
$body.="<td width='50%'>";
    $body.="<h3>Billing</h3>";
    $body.=$billing['x_first_name']." ".$billing['x_last_name']."<br />";
    $body.=$billing['x_email']."<br />";
    $body.=$billing['x_address']."<br />";
    if($billing['x_address2']!==""){
        $body.=$billing['x_address2']."<br />";
    }
    $body.=$billing['x_city'].", ".$billing['x_state']." ".$billing['x_zip']." ".$billing['x_country'];
$body.="</td>";
$body.="<td width='50%'>";
    $body.="<h3>Shipping</h3>";
    $body.=$shipping['x_first_name']." ".$shipping['x_last_name']."<br />";
    $body.=$shipping['x_email']."<br />";
    $body.=$shipping['x_address']."<br />";
    if($shipping['x_address2']!==""){
        $body.=$shipping['x_address2']."<br />";
    }
    $body.=$shipping['x_city'].", ".$shipping['x_state']." ".$shipping['x_zip']." ".$shipping['x_country'];
$body.="</td>";
$body.="</tr>";
$body.="</table>";
$body.="<p></p>";
$body.='<table width="100%" cellpadding="5" border="1">';
    $body.='<thead>';
        $body.='<th>Product</th>';
        $body.='<th>Quantity</th>';
        $body.='<th>Price</th>';
        $body.='<th>Subtotal</th>';
    $body.='</thead>';
foreach($loader->cart as $id=>$item){
    $body.='<tr>';
        $body.='<td>';
            $body.='Gift Card<br />';
            $body.='Amount: <strong>$'.$item['amount'].'</strong><br />';
            $body.='Is this a gift?: <strong>'.($item['gift']?"Yes":"No").'</strong>';
            if($item['gift']){
                    $body.='<br />To: <strong>'.$item['gift-options']['to'].'</strong><br />';
                    $body.='From: <strong>'.$item['gift-options']['from'].'</strong><br />';
                    $body.='Ship to address: <strong>'.$item['gift-options']['address'].'</strong><br />';
                    $body.='Personal Message: <strong>'.$item['gift-options']['message'].'</strong>';
            }
        $body.='</td>';
        $body.='<td>'.$item['quantity'].'</td>';
        $body.='<td>$'.number_format($item['amount'],2).'</td>';
        $body.='<td>$'.number_format($item['amount']*$item['quantity'],2).'</td>';
    $body.='</tr>';
}
$body.='<tr><td></td><td></td><td>'.$method['name'].'</td><td>$'.number_format($method['price'],2).'</td></tr>';
$body.='<tr><td></td><td></td><td>Grand Total</td><td>$'.number_format($amount,2).'</td></tr>';
$body.='</table>';

/* Respond and stuff */
switch ($a->process()) {
   case 1:  // Successs
        header('Location: return.php?success');
        mail($store_owner,"Gift Card Purchase",$body,"Content-Type: text/html; charset=ISO-8859-1\r\n");
        break;
   case 2:  // Declined
      header('Location: return.php?decline');
      break;
   case 3:  // Error 
      header('Location: return.php?error');
      break;
}

?>

Thank you for your help!!

1

1 Answers

1
votes

Based on the code I see I don't see how you can add merchant defined fields since it adds fields by name and these fields don't have names. Basically anything after field 38 is a merchant defined field so it looks like you will need to go back and hack that script to allow merchant defined fields to be added somehow. Probably by adding the ability to have merchant_field_1, merchant_field_2, etc to suit your needs.