title: Paypal Payment Data Transfer(PDT) Error 4002
body: <p>I'm working on integrating my website with paypal and getting it to work in sandbox mode. I am working in Codeigniter (PHP). I have gotten IPN notifications working perfectly but can't seem to figure out where I'm going wrong with PDT(need this to show a proper confirmation page and return). I have checked the identity token numerous times, made sure the htaccess file doesn't limit access on the call back, made sure the email is verified for the business field, made sure everything is going to sandbox and not the live site, and made sure auto-return is enabled with the correct paramters, and even asked technical support(without receiving any useful help). But I keep getting a return ($response) of "FAIL" with an error code of 4002. Any help in how to debug this will be greatly appreciated.</p>
  
  <p>Here is my form:</p>
  
  <pre><code>&lt;form class="paypal login" action="http://########.com/paypal/purchase" method="post" id="paypal_form"&gt;    
      &lt;fieldset id="inputs"&gt;
          &lt;input type="hidden" name="first_name" value=""&gt; 
          &lt;input type="hidden" name="last_name" value=""&gt;
          &lt;input type="hidden" name="email" value=""&gt;
          &lt;input type="hidden" name="quantity" value=""&gt;
          &lt;input type="hidden" name="order_tc_id" value="###########"&gt;
      &lt;/fieldset&gt;
      &lt;fieldset id="actions"&gt;
          &lt;input type="submit" id="paypal-btn" class="paypal-order" alt="Order" value="Purchase"/&gt;
      &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is where it goes:</p>
  
  <pre><code>$querystring = '?';
  $querystring .= "business=".urlencode("paypal@#######.net")."&amp;";
  $querystring .= "cmd=".urlencode("_xclick")."&amp;";
  $querystring .= "amount=".urlencode(krw_usd($items_no_tax_price))."&amp;";
  $querystring .= "rm=".urlencode(2)."&amp;";
  $querystring .= "quantity=".urlencode($quant)."&amp;";
  $querystring .= "first_name=".urlencode($first_name)."&amp;";
  $querystring .= "last_name=".urlencode($last_name)."&amp;";
  $querystring .= "email=".urlencode($email)."&amp;";
  $querystring .= "currency_code=".urlencode("USD")."&amp;";
  $querystring .= "return=".urlencode(stripslashes($return_url))."&amp;";
  $querystring .= "cancel_return=".urlencode(stripslashes($cancel_url))."&amp;";
  $querystring .= "notify_url=".urlencode(stripslashes($notify_url));
  
  header('location:https://www.sandbox.paypal.com/cgi-bin/webscr'.$querystring);
  </code></pre>
  
  <p>And here is the return url:</p>
  
  <pre><code>$request = curl_init();
  
  curl_setopt_array($request, array
  (
    CURLOPT_URL =&gt; 'https://www.sandbox.paypal.com/cgi-bin/webscr',
    CURLOPT_POST =&gt; 1,
    CURLOPT_POSTFIELDS =&gt; http_build_query(array
      (
        'cmd' =&gt; '_notify-synch',
        'tx' =&gt; $tx,
        'at' =&gt; '#############################',
      )),
    CURLOPT_RETURNTRANSFER =&gt; 1,
    CURLOPT_HEADER =&gt; 0,
  ));
  
  $response = curl_exec($request);
  $status   = curl_getinfo($request, CURLINFO_HTTP_CODE);
  
  curl_close($request);
  
  $response = substr($response, 7);
  $response = urldecode($response);
  
  preg_match_all('/^([^=\s]++)=(.*+)/m', $response, $m, PREG_PATTERN_ORDER);
  $response = array_combine($m[1], $m[2]);
  
  if(isset($response['charset']) AND strtoupper($response['charset']) !== 'UTF-8')
  {
    foreach($response as $key =&gt; &amp;$value)
    {
      $value = mb_convert_encoding($value, 'UTF-8', $response['charset']);
    }
    $response['charset_original'] = $response['charset'];
    $response['charset'] = 'UTF-8';
  }
  
  ksort($response);
  
  foreach($response as $k=&gt;$v)
  {
      echo "Key: " . $k . ", Value: " . $v;
      echo "&lt;br&gt;";
  }
  </code></pre>