I built a simple payment system that integrates paypal with wordpress in php, basically I create a list in which each list item extracts metadata from a specific page in wordress (page for each product) and dynamically generates this data as a paypal add to cart button . it worked well! but .. Then I tried to encrypt the "add to cart" button for obvious reasons. I found a php program that was supposed to do this (and from what I see on various online forums - this promise delivers most of the time), and I think I followed all the instructions in PayPal with a certificate (private, public , paypals, etc ...)
Until I get any errors from the html page - when I click the "Add to Cart" button, I get a PayPal error: "We found a problem with this shopping cart. If the problem persists, contact the seller." but I don’t have any details about why and what I am doing wrong.
I have a merchant account with paypal.
To remove unnecessary clutter and noise, I built a test page with static data to check if the button works correctly, and here it is: glad for any help
main test page:
<?php
include_once "testfunctions.php";
$themetacost='100';
$themetaname="testbook";
$themetashipping='20';
$line='';
$line.='<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank" id="payform" >
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="encrypted" value="';
$line.= buildbutton($themetacost,$themetaname,$themetashipping);
$line.='">';
$line.='<input type="image" src="https://www.paypalobjects.com/WEBSCR-640-20110429-1/he_IL/i/btn/btn_cart_SM.gif" border="0" name="submit" alt="PayPal - הדרך הקלה והבטוחה לשלם באופן מקוון!">
<img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110429-1/he_IL/i/scr/pixel.gif" width="1" height="1">
</form><br/>';
echo $line;
?>
php buildbutton and encryption features:
<?php
function buildbutton($amount,$bname,$shipping) {
$form = array('cmd' => '_cart',
'business' => 'X@XXX.CO.il',
'cert_id' => 'XXXXXXXXXXX',
'shipping' => $shipping,
'currency_code' => 'ILS',
'add'=>'1',
'item_name' => $bname,
'amount' => $amount
);
$encrypted = paypal_encrypt($form);
return $encrypted;
}
function paypal_encrypt($hash)
{
$MY_KEY_FILE = "/home/paypal/my-prvkey.pem";
$MY_CERT_FILE = "/home/paypal/my-prvkey.pem";
$PAYPAL_CERT_FILE = "/home/paypal/paypal_cert.pem";
$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";
}
if (!file_exists($OPENSSL)){
echo "error with openssl $OPENSSL not found \n";
}
$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";
}
}
?>
I tried changing the variables to numbers in order to check if there was a problem that did not help.
and this is what the source of the encrypted test page looks like:
action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank" id="payform" >
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----
MIIBdwYJKoZIhvcNAQcDoIIBaDCCAWQCAQAxggEwMIIBLAIBADCBlDCBjjELMAkG
A1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQw
EgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UE
AxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJ
KoZIhvcNAQEBBQAEgYAiFKR0WuQJcr6cQZvDCptQeDNyfipH9pDy1Q58C+ITCZWY
XRkkUOvvL3jniO1GUxsY2JleGAdZWSV1qgnO3uNjj0V3Z0AxbrAiuA0lLd8pscBT
MM+9+1RwjTOUVtOi3PASy1TC4hk6Wq01KUk1DCpbqMtqBZ6sWb5jHRxWqbL08zAr
BgkqhkiG9w0BBwEwFAYIKoZIhvcNAwcECClgCVLJPeXAgAgr8wXDhqI+og==
-----END PKCS7-----"><input type="image" src="https://www.paypalobjects.com/WEBSCR-640-20110429-1/he_IL/i/btn/btn_cart_SM.gif" border="0" name="submit" alt="PayPal - äãøê ä÷ìä åäáèåçä ìùìí áàåôï î÷ååï!">
<img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110429-1/he_IL/i/scr/pixel.gif" width="1" height="1">
</form><br/>
edit: html ( php encrypt) '_cart' '_s-xclick', :
. .
PayPal, ( ). !