A PayPal sample code with PHP Pear

Times ago, because we entered the web2.0/e-commerce generation all custemers want an e-shop, I was looking for some Pear/PayPal PHP script without success.
Becouse i love pear for speeding up code development etc i wrote my little pear/paypal library, here an example.

$database = new Database($yourconfig);
$order = database->getOrder((int)$order_id);
if($order->status != 'Payable'){
$conf = array('ssl_verify_peer' => false, 'ssl_verify_host' => false);
$req =& new HTTP_Request2("https://api-3t.sandbox.paypal.com/nvp/", HTTP_Request2::METHOD_POST, $conf);
if(empty($order->token) || $order->token_expire < time()){//Create new token
	$SetExpressCheckout = array(
		"USER" => "info_1283974049_biz_api2.XXXXX.com",
		"PWD" => "XXXXX",
		"VERSION"=> "63.0",
		"RETURNURL"=> base_url()."order/paypalreturn/",
		"CANCELURL" => base_url()."order/paypalcancel/",
		"METHOD"=> "SetExpressCheckout",
		"HDRIMG" => "http://example.org/logo.png",
		"LANDINGPAGE" => "billing",
		"CHANNELTYPE" => "merchant",
		"NOSHIPPING" => '1',
		"PAYMENTREQUEST_0_AMT" => (string)$order->price,
		"PAYMENTREQUEST_0_DESC" => 'Order description',
	$body = $req->send()->getBody();
	$body = responseParse($body);
	$database->set_token((int)$order->id, (string)$body['TOKEN'], (int)time()+7200);//Add 2h expire time
}else //Use cached token

One Reply to “A PayPal sample code with PHP Pear”

  1. You post interesting posts here. Your page deserves much more visitors.
    It can go viral if you give it initial boost, i know useful tool that can help you, just type in google:
    svetsern traffic tips

Leave a Reply

Your e-mail address will not be published. Required fields are marked *