I am dynamically enrypting my Paypal buttons but when clicking on the "Subscribe" button I am getting an error from Paypal: "Dispatch Error, please check logfile for more information".
The code I am using to generate my button:
<form id="suf" onsubmit="return newUser();" action="<?php echo $PPBtnURL; ?>" method="POST">
<?php
$form = array();
$form['business']=$PPbtnUser;
$form['itemname']=$_POST['item_name'];
$form['itemnumber']=$_POST['item_number'];
$form['currency_code']="USD";
$skip_a2 = ($res['a2'] <= $res['a1']);
foreach($res as $k=>$v){
if($skip_a2 && ($k == "a2" || $k=="p2" || $k=="t2")){continue;}
if($k == "trial1" || $k == "trial2"){continue;}
$form[$k]=$v;
}
$form['src']=1;
$form['rm']=2;
$form['return']="https://www.mysite.com/signup2.php";
$form['cancel_return']="https://www.mysite.com/";
$form['bname']=$_POST['bname'];
$form['fname']=$_POST['fname'];
$form['lname']=$_POST['lname'];
$form['pwone']=$_POST['pwone'];
$form['pwtwo']=$_POST['pwtwo'];
$encrypted = paypal_encrypt($form);
function paypal_encrypt($hash){
global $MY_KEY_FILE;
global $MY_CERT_FILE;
global $PAYPAL_CERT_FILE;
global $OPENSSL;
// private key file to use
$MY_KEY_FILE = "/home/mysite/mysite.com/prvkey.pem";
// public certificate file to use
$MY_CERT_FILE = "/home/mysite/mysite.com/a62ecbe3015a2165c8859b953753038a-pubcert.pem";
// Paypal's public certificate
$PAYPAL_CERT_FILE = "/home/mysite/mysite.com/paypal_cert.pem";
// path to the openssl binary
$OPENSSL = "/usr/bin/openssl";
if (!file_exists($MY_KEY_FILE)) {
echo "ERROR: MY_KEY_FILE $MY_KEY_FILE not found\n";
}
if (!file_exists($MY_CERT_FILE)) {
echo "ERROR: MY_CERT_FILE $MY_CERT_FILE not found\n";
}
if (!file_exists($PAYPAL_CERT_FILE)) {
echo "ERROR: PAYPAL_CERT_FILE $PAYPAL_CERT_FILE not found\n";
}
//Assign Build Notation for PayPal Support
$hash['bn']= 'StellarWebSolutions.PHP_EWP2';
$data = "";
foreach ($hash as $key => $value) {
if ($value != "") {
$data .= "$key=$value\n";
}
}
$openssl_cmd = "($OPENSSL smime -sign -signer $MY_CERT_FILE -inkey $MY_KEY_FILE " .
"-outform der -nodetach -binary <<_EOF_\n$data\n_EOF_\n) | " .
"$OPENSSL smime -encrypt -des3 -binary -outform pem $PAYPAL_CERT_FILE";
exec($openssl_cmd, $output, $error);
if(!$error){
return implode("\n",$output);
}else{
return "ERROR: encryption failed";
}
};
?>
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="encrypted" value="<?PHP echo $encrypted; ?>">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
I followed the steps and used most of the example code here .
What might be causing this error? I have no errors from PHP.
Bonus question: What logfile is Paypal referring to?
Bit late now, but if it helps: I was getting that same error after following that same tutorial and although I can't see the issue in your code I found that I would get this error whenever there was something in the $form being passed into paypal_encrypt() that PayPal didn't like.
tl;dr: invalid data in $form can trigger this "helpful" error
Also, be aware that you are passing data from $_POST directly into the $openssl_cmd without escaping it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.