Jump to content

Paypal upload to cart, without form?


Dragen

Recommended Posts

Hi,

I'm trying to integrate my custom shop with paypals payment options.

What I'm trying is to use the shopping cart 'upload' facility: https://www.paypal.com/IntegrationCenter/ic_standard_home.html#individual

Unfortunately Paypal seem to have a block on using Curl or Fopen etc, by checking that the url is from Paypal.

 

To try and get around this I was looking into the Header and found this topic: http://www.pdncommunity.com/pdn/board/message?board.id=basicpayments&message.id=3393

 

I've been trying to get this to work, but instead it just tries to download a file instead. Here's the code I'm using:

<?php
$paypal = '[email protected]';
$vars = 'upload=1&cmd=_cart&business=' . $paypal . '&currency_code=GBP';

$i = 1;
foreach($_SESSION['basket']['pay_sec'][$_POST['id']]['items'] as $id => $items){
$vars .= '&item_name_' . $i . '=' . $items['name'];
$vars .= '&amount_' . $i . '=' . $items['price'];
$vars .= '&quantity_' . $i . '=' . $items['quantity'];

$i++;
}

$host = "www.paypal.com";//'www.sandbox.paypal.com';
$path = "/cgi-bin/webscr";
$vars = urlencode($vars);

header("POST " . $path . " HTTP/1.1");
header("Host: " . $host);
header("Content-Type: application/x-www-form-urlencoded");
header("Content-length: " . strlen($vars));
header("Connection: close");
header($vars);
?>

Link to comment
https://forums.phpfreaks.com/topic/125612-paypal-upload-to-cart-without-form/
Share on other sites

can anyone help me with this?

I've asked on the Paypal Developers forum, but none of the moderators (or members) seem to know or have a definite answer. None of them could even tell me if using Curl should work or not..

 

 

EDIT:

If anyone's interested in my Curl code:

<?php
$paypal = '[email protected]';
$vars = 'upload=1&cmd=_cart&business=' . $paypal . '&currency_code=GBP';

$i = 1;
foreach($_SESSION['basket']['pay_sec'][$_POST['id']]['items'] as $id => $items){
$vars .= '&item_name_' . $i . '=' . $items['name'];
$vars .= '&amount_' . $i . '=' . $items['price'];
$vars .= '&quantity_' . $i . '=' . $items['quantity'];
$i++;
}
$vars = urlencode($vars);

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, 'https://www.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: text/html"));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);

$res = curl_exec($ch);
curl_close($ch);
if($res === false){
echo 'false';
}else{
echo 'true';
print_r($res);
}
?>

And that just outputs the Paypal homepage for some reason, when it should output the checkout page.

I am aware that displaying the paypal page inside my own makes it seems like a phising site, but I'm only displaying it for testing purposes. My aim is to upload my items and re-direct to the Paypal page.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.