1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PayPal encrypted button - I need help!!

Discussion in 'PHP' started by voodoo709, Mar 23, 2007.

  1. #1
    Hi,

    I wonder if someone could help me out, I have the following code that I use to generate encrypted paypal buttons, the item number changes so I need to generate a new encrypted button every time.


    I’m moving my .com website from a US host to one in the UK to get better search engine rankings in google.co.uk.


    Anyway the problem I have is proc_open() is disabled on the UK server so I’m looking for a way to rewrite the code using another function the will do the same job.


    Does anyone know if this would be possible using exec() or another function?


    I know the host has exec() enabled as I’ve tested my nightly backup script which dumps the database, encrypts it and sends it to my home server at 3am every morning.


    Any help would be greatly appreciated

    Thanks.




    
    <?php
    //Sample PayPal Button Encryption: Copyright 2006 StellarWebSolutions.com
    //Not for resale  - license agreement at
    //http://www.stellarwebsolutions.com/en/eula.php
    
    # private key file to use
    
    //$MY_KEY_FILE = "/usr/home/stellar/paypal/my-prvkey.pem";
    //$MY_KEY_FILE = $roor_dir."/PayPl_Tests/my-prvkey.pem";
    $MY_KEY_FILE = $roor_dir."/paypal/my-prvkey.pem";
    
    # public certificate file to use
    //$MY_CERT_FILE = "/usr/home/stellar/paypal/my-pubcert.pem";
    //$MY_CERT_FILE = $roor_dir."/PayPl_Tests/my-pubcert.pem";
    $MY_CERT_FILE = $roor_dir."/paypal/my-pubcert.pem";
    
    # Paypal's public certificate
    //$PAYPAL_CERT_FILE = "/usr/home/stellar/paypal/paypal_cert.pem";
    //$PAYPAL_CERT_FILE = $roor_dir."/PayPl_Tests/paypal_cert.pem";
    $PAYPAL_CERT_FILE = $roor_dir."/paypal/paypal_cert.pem";
    
    # path to the openssl binary
    $OPENSSL = "/usr/bin/openssl";
    
    
    $form = array('cmd' => '_xclick-subscriptions',
            'business' => 'test@test.com',
            'cert_id' => 'L36XY48X6HGEC',
            'lc' => 'UK',
            'custom' => 'test',
            'invoice' => '',
            'currency_code' => 'GBP',
    		'no_note' => '1',
    		'bn' => 'PP-SubscriptionsBF',
    		'a3' => '5.00',
    		'p3' => '1',
    		't3' => 'Y',
    		'src' => '1',
    		'sra' => '1',
            'no_shipping' => '1',
            'item_name' => 'item1',
    		'item_number' => '9876543210',
    	'amount' => '5'
    	);
    	
    	
    	
    
    
    	$encrypted = paypal_encrypt($form);
    
    
    function paypal_encrypt($hash)
    {
    	//Sample PayPal Button Encryption: Copyright 2006 StellarWebSolutions.com
    	//Not for resale - license agreement at
    	//http://www.stellarwebsolutions.com/en/eula.php
    	global $MY_KEY_FILE;
    	global $MY_CERT_FILE;
    	global $PAYPAL_CERT_FILE;
    	global $OPENSSL;
    
    	$openssl_cmd = "$OPENSSL smime -sign -signer $MY_CERT_FILE -inkey $MY_KEY_FILE " .
                    "-outform der -nodetach -binary | $OPENSSL smime -encrypt " .
                    "-des3 -binary -outform pem $PAYPAL_CERT_FILE";
    
    	$descriptors = array(
            	0 => array("pipe", "r"),
    		1 => array("pipe", "w"),
    	);
    
    	$process = proc_open($openssl_cmd, $descriptors, $pipes);
        
    	if (is_resource($process)) {
    		foreach ($hash as $key => $value) {
    			if ($value != "") {
    				//echo "Adding to blob: $key=$value\n";
    				fwrite($pipes[0], "$key=$value\n");
    			}
    		}
    		fflush($pipes[0]);
            	fclose($pipes[0]);
    
    		$output = "";
    		while (!feof($pipes[1])) {
    			$output .= fgets($pipes[1]);
    		}
    		//echo $output;
    		fclose($pipes[1]); 
    		$return_value = proc_close($process);
    		return $output;
    	}
    	return "ERROR";
    };
    ?>
    
    
    PHP:
     
    voodoo709, Mar 23, 2007 IP