I am working to integrate my site with PayPal and make it work in sandbox mode. I work in Codeigniter (PHP). I received IPN notifications perfectly, but I canβt understand where I am mistaken in the PDT (I need this to show the correct confirmation page and return). I checked the identification token many times, made sure that the htaccess file does not restrict access to the callback, made sure that the email was checked for the business field, make sure everything goes to the sandbox, and not on the site, and the correct autostart is turned on with the correct ones parameters, and even asked for technical support (without getting any useful help). But I keep getting the βFAILβ response ($ response) with error code 4002. Any help on how to debug this would be greatly appreciated.
Here is my form:
<form class="paypal login" action="http://########.com/paypal/purchase" method="post" id="paypal_form"> <fieldset id="inputs"> <input type="hidden" name="first_name" value=""> <input type="hidden" name="last_name" value=""> <input type="hidden" name="email" value=""> <input type="hidden" name="quantity" value=""> <input type="hidden" name="order_tc_id" value="###########"> </fieldset> <fieldset id="actions"> <input type="submit" id="paypal-btn" class="paypal-order" alt="Order" value="Purchase"/> </fieldset> </form>
This is where it goes:
$querystring = '?'; $querystring .= "business=".urlencode(" paypal@ #######.net")."&"; $querystring .= "cmd=".urlencode("_xclick")."&"; $querystring .= "amount=".urlencode(krw_usd($items_no_tax_price))."&"; $querystring .= "rm=".urlencode(2)."&"; $querystring .= "quantity=".urlencode($quant)."&"; $querystring .= "first_name=".urlencode($first_name)."&"; $querystring .= "last_name=".urlencode($last_name)."&"; $querystring .= "email=".urlencode($email)."&"; $querystring .= "currency_code=".urlencode("USD")."&"; $querystring .= "return=".urlencode(stripslashes($return_url))."&"; $querystring .= "cancel_return=".urlencode(stripslashes($cancel_url))."&"; $querystring .= "notify_url=".urlencode(stripslashes($notify_url)); header('location:https://www.sandbox.paypal.com/cgi-bin/webscr'.$querystring);
And here is the return URL:
$request = curl_init(); curl_setopt_array($request, array ( CURLOPT_URL => 'https://www.sandbox.paypal.com/cgi-bin/webscr', CURLOPT_POST => 1, CURLOPT_POSTFIELDS => http_build_query(array ( 'cmd' => '_notify-synch', 'tx' => $tx, 'at' => '#############################', )), CURLOPT_RETURNTRANSFER => 1, CURLOPT_HEADER => 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 => &$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=>$v) { echo "Key: " . $k . ", Value: " . $v; echo "<br>"; }
source share