title: Making MDF Fields Work in Authorize.net
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>Can someone help me figure out what lines I'm leaving out?</p>
  
  <p>Here's the form that captures the fields in question:</p>
  
  <pre><code>&lt;form method="POST" action="cart.php"&gt;
      &lt;fieldset&gt;
          &lt;div class="form-divider"&gt;
              &lt;label&gt;Amount&lt;/label&gt;
              &lt;select name="amount"&gt;
                  &lt;?php for($i=5;$i&lt;101;$i=$i+5){ ?&gt;
                      &lt;option value="&lt;?php echo $i; ?&gt;"&gt;$&lt;?php echo $i; ?&gt;&lt;/option&gt;
                  &lt;?php } ?&gt;
              &lt;/select&gt;
          &lt;/div&gt;
          &lt;div class="form-divider"&gt;
              &lt;label&gt;Will gift certificate be mailed directly to the recipient?&lt;/label&gt;
              &lt;input name="gift" type="radio" value="1" onclick="$('#gift-options').show();" /&gt;
              &lt;label&gt;Yes&lt;/label&gt;
              &lt;input name="gift" type="radio" value="0" checked="checked" onclick="$('#gift-options').hide();" /&gt;
              &lt;label&gt;No&lt;/label&gt;
          &lt;/div&gt;
          &lt;div id="gift-options"&gt;
              &lt;div class="col1"&gt;
                  &lt;div class="form-divider"&gt;
                      &lt;label&gt;To&lt;/label&gt;
                      &lt;input name="gift-to" type="text" size="20" /&gt;
                  &lt;/div&gt;
                  &lt;div class="form-divider"&gt;
                      &lt;label&gt;From&lt;/label&gt;
                      &lt;input name="gift-from" type="text" size="20" /&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="col2"&gt;
                  &lt;div class="form-divider"&gt;
                      &lt;label&gt;Ship To Address&lt;/label&gt;
                      &lt;textarea name="gift-address" style="width: 200px; height: 50px;"&gt;&lt;/textarea&gt;
                  &lt;/div&gt;
                  &lt;div class="form-divider"&gt;
                      &lt;label&gt;Gift Message&lt;/label&gt;
                      &lt;textarea name="gift-message" style="width: 200px; height: 50px;"&gt;&lt;/textarea&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="form-divider"&gt;
              &lt;label&gt;Quantity&lt;/label&gt;
              &lt;input name="quantity" type="text" value="1" /&gt;
          &lt;/div&gt;
          &lt;input type="hidden" name="action" value="add" /&gt;
      &lt;/fieldset&gt;
      &lt;input type="submit" value="Next Step" class="button" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And here is "checkout" code, which gathers the data that is actually sent to Authorize.net:</p>
  
  <pre><code>&lt;?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-&gt;checkStep(true)){ echo '&lt;meta http-equiv="refresh" content="0;url=cart.php"&gt; '; }
  
  $amount=0;
  foreach($loader-&gt;cart as $item){
      $amount+=($item['quantity']*$item['amount']);
  }
  $method=$loader-&gt;getShippingMethod();
  $amount+=$method['price'];
  
  $a = new PDAuthorizeNet;
  
  /* Set all of the authnet info */
  $a-&gt;add_field('x_login', $x_login);
  $a-&gt;add_field('x_tran_key', $x_transkey);
  $a-&gt;add_field('x_version', '3.1');
  $a-&gt;add_field('x_type', 'AUTH_CAPTURE');
  $a-&gt;add_field('x_test_request', 'FALSE'); 
  $a-&gt;add_field('x_relay_response', 'FALSE');
  
  $a-&gt;add_field('x_delim_data', 'TRUE');
  $a-&gt;add_field('x_delim_char', '|');     
  $a-&gt;add_field('x_encap_char', '');
  
  /* Billing Information */
  $a-&gt;add_field('x_first_name', $loader-&gt;address['billing']['x_first_name']);
  $a-&gt;add_field('x_last_name', $loader-&gt;address['billing']['x_last_name']);
  $a-&gt;add_field('x_address', $loader-&gt;address['billing']['x_address']);
  $a-&gt;add_field('x_city', $loader-&gt;address['billing']['x_city']);
  $a-&gt;add_field('x_state', $loader-&gt;address['billing']['x_state']);
  $a-&gt;add_field('x_zip', $loader-&gt;address['billing']['x_zip']);
  $a-&gt;add_field('x_country', $loader-&gt;address['billing']['x_country']);
  $a-&gt;add_field('x_email', $loader-&gt;address['billing']['x_email']);
  
  /* Shipping Information */
  $a-&gt;add_field('x_ship_to_first_name', $loader-&gt;address['shipping']['x_first_name']);
  $a-&gt;add_field('x_ship_to_last_name', $loader-&gt;address['shipping']['x_last_name']);
  $a-&gt;add_field('x_ship_to_address', $loader-&gt;address['shipping']['x_address']);
  $a-&gt;add_field('x_ship_to_city', $loader-&gt;address['shipping']['x_city']);
  $a-&gt;add_field('x_ship_to_state', $loader-&gt;address['shipping']['x_state']);
  $a-&gt;add_field('x_ship_to_zip', $loader-&gt;address['shipping']['x_zip']);
  $a-&gt;add_field('x_ship_to_country', $loader-&gt;address['shipping']['x_country']);
  $a-&gt;add_field('x_ship_to_email', $loader-&gt;address['shipping']['x_email']);
  
  /* Credit Card Information */
  $a-&gt;add_field('x_method', 'CC');
  $a-&gt;add_field('x_card_num', $loader-&gt;sale['x_card_num']); 
  $a-&gt;add_field('x_amount', $amount);
  $a-&gt;add_field('x_exp_date', $loader-&gt;sale['x_exp_date']);
  $a-&gt;add_field('x_card_code', $loader-&gt;sale['x_card_code']);
  
  $billing=$loader-&gt;address['billing'];
  $shipping=$loader-&gt;address['shipping'];
  $body ="&lt;h3&gt;Order Details&lt;/h3&gt;";
  $body.="&lt;table width='100%' cellpadding='5' border='1'&gt;";
  $body.="&lt;tr&gt;";
  $body.="&lt;td width='50%'&gt;";
      $body.="&lt;h3&gt;Billing&lt;/h3&gt;";
      $body.=$billing['x_first_name']." ".$billing['x_last_name']."&lt;br /&gt;";
      $body.=$billing['x_email']."&lt;br /&gt;";
      $body.=$billing['x_address']."&lt;br /&gt;";
      if($billing['x_address2']!==""){
          $body.=$billing['x_address2']."&lt;br /&gt;";
      }
      $body.=$billing['x_city'].", ".$billing['x_state']." ".$billing['x_zip']." ".$billing['x_country'];
  $body.="&lt;/td&gt;";
  $body.="&lt;td width='50%'&gt;";
      $body.="&lt;h3&gt;Shipping&lt;/h3&gt;";
      $body.=$shipping['x_first_name']." ".$shipping['x_last_name']."&lt;br /&gt;";
      $body.=$shipping['x_email']."&lt;br /&gt;";
      $body.=$shipping['x_address']."&lt;br /&gt;";
      if($shipping['x_address2']!==""){
          $body.=$shipping['x_address2']."&lt;br /&gt;";
      }
      $body.=$shipping['x_city'].", ".$shipping['x_state']." ".$shipping['x_zip']." ".$shipping['x_country'];
  $body.="&lt;/td&gt;";
  $body.="&lt;/tr&gt;";
  $body.="&lt;/table&gt;";
  $body.="&lt;p&gt;&lt;/p&gt;";
  $body.='&lt;table width="100%" cellpadding="5" border="1"&gt;';
      $body.='&lt;thead&gt;';
          $body.='&lt;th&gt;Product&lt;/th&gt;';
          $body.='&lt;th&gt;Quantity&lt;/th&gt;';
          $body.='&lt;th&gt;Price&lt;/th&gt;';
          $body.='&lt;th&gt;Subtotal&lt;/th&gt;';
      $body.='&lt;/thead&gt;';
  foreach($loader-&gt;cart as $id=&gt;$item){
      $body.='&lt;tr&gt;';
          $body.='&lt;td&gt;';
              $body.='Gift Card&lt;br /&gt;';
              $body.='Amount: &lt;strong&gt;$'.$item['amount'].'&lt;/strong&gt;&lt;br /&gt;';
              $body.='Is this a gift?: &lt;strong&gt;'.($item['gift']?"Yes":"No").'&lt;/strong&gt;';
              if($item['gift']){
                      $body.='&lt;br /&gt;To: &lt;strong&gt;'.$item['gift-options']['to'].'&lt;/strong&gt;&lt;br /&gt;';
                      $body.='From: &lt;strong&gt;'.$item['gift-options']['from'].'&lt;/strong&gt;&lt;br /&gt;';
                      $body.='Ship to address: &lt;strong&gt;'.$item['gift-options']['address'].'&lt;/strong&gt;&lt;br /&gt;';
                      $body.='Personal Message: &lt;strong&gt;'.$item['gift-options']['message'].'&lt;/strong&gt;';
              }
          $body.='&lt;/td&gt;';
          $body.='&lt;td&gt;'.$item['quantity'].'&lt;/td&gt;';
          $body.='&lt;td&gt;$'.number_format($item['amount'],2).'&lt;/td&gt;';
          $body.='&lt;td&gt;$'.number_format($item['amount']*$item['quantity'],2).'&lt;/td&gt;';
      $body.='&lt;/tr&gt;';
  }
  $body.='&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;'.$method['name'].'&lt;/td&gt;&lt;td&gt;$'.number_format($method['price'],2).'&lt;/td&gt;&lt;/tr&gt;';
  $body.='&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;Grand Total&lt;/td&gt;&lt;td&gt;$'.number_format($amount,2).'&lt;/td&gt;&lt;/tr&gt;';
  $body.='&lt;/table&gt;';
  
  /* Respond and stuff */
  switch ($a-&gt;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;
  }
  
  ?&gt;
  </code></pre>
  
  <p>Thank you for your help!!</p>