Problem with encryption of the dynamic add to cart paypal button with php

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";
//inserting some test data
$themetacost='100';
$themetaname="testbook";
$themetashipping='20';
//building the paypal button
$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) {
//Sample PayPal Button Encryption: Copyright 2006-2010 StellarWebSolutions.com
//Not for resale  - license agreement at
//http://www.stellarwebsolutions.com/en/eula.php
//Updated: 2010 02 01



$form = array('cmd' => '_cart',
        'business' => 'X@XXX.CO.il', // changed from the original
        'cert_id' => 'XXXXXXXXXXX',// changed from the original
    'shipping' => $shipping,
        //'invoice' => '', //check what this is
        'currency_code' => 'ILS',
        //'no_shipping' => '0', //refers to shipping address
        'add'=>'1',
    'item_name' => $bname,
    'amount' => $amount
    );


    $encrypted = paypal_encrypt($form); 

return $encrypted;
}
function paypal_encrypt($hash)
{
    //Sample PayPal Button Encryption: Copyright 2006-2010 StellarWebSolutions.com
    //Not for resale - license agreement at
    //http://www.stellarwebsolutions.com/en/eula.php
    # private key file to use //

$MY_KEY_FILE = "/home/paypal/my-prvkey.pem";
# public certificate file to use
$MY_CERT_FILE = "/home/paypal/my-prvkey.pem";// 

# Paypal public certificate
$PAYPAL_CERT_FILE = "/home/paypal/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";
    }
        if (!file_exists($OPENSSL)){
                echo "error with openssl $OPENSSL not found \n";
        }


    //Assign Build Notation for PayPal Support
    //$hash['bn']= 'StellarWebSolutions.PHP_EWP2'; //this is not needed cause i dont have a ewp

    $data = "";
    foreach ($hash as $key => $value) {
        if ($value != "") {
            //echo "Adding to blob: $key=$value\n";
            $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, ( ). !

+3
2

cmd _s-xclick. PayPal .  

, " . , ". . " " ? .

API- . https://merchant.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ButtonMgrAPIIntro , API . , , .

, . Lorefold

+2

, OpenSSL .

Paypal, Paypal.

0

All Articles