codacopia
codacopia

Reputation: 2501

Trying to Submit Paypal Form with cURL...

I have been researching how to pass a Paypal form submission automatically without a user clicking the checkout button. Here is the code I have so to do this:

<?php
$post_data['cmd'] = '_xclick';
$post_data['business'] = '[email protected]';
$post_data['item_name'] = 'The Items You are Purchasing';
$post_data['amount'] = '25';
$post_data['no_shipping'] = '1';
$post_data['no_note'] = '1';
$post_data['currency_code'] = 'USD';
$post_data['bn'] = 'PP-BuyNowBF';

foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
$post_string = implode ('&', $post_items);

$curl_connection = curl_init('https://www.paypal.com/cgi-bin/webscr');
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); 

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); 

$result = curl_exec($curl_connection);

curl_close($curl_connection); 
?>

As best as I can tell this should pass the values over to Paypal and ask the user to pay $25 for 'The Items You are Purchasing' to '[email protected].' But for some reason it is not working, do you know why?

Upvotes: 0

Views: 2598

Answers (2)

Sukumar
Sukumar

Reputation: 3587

Looking at your requirements, all you need to do is keep the post information in the last page before you want the customer to be redirected to paypal.

Something like

<!-- Display all items etc. -->

<form action='https://www.paypal.com/cgi-bin/webscr' method='POST'>
POST DATA

Submit button
</form>

You could also an extra page where you post all the information into a page and use javascript to auto submit the form.

Upvotes: 0

Ruslan Polutsygan
Ruslan Polutsygan

Reputation: 4461

As I see, you are using Buy It Now Button. It dos'n work with curl because user(customer) should take part in the payment process: log in into his(her) account on PayPal or enter payment and billing information if he doesn't have it, confirm payment and return to your 'shop' manually. How user could do this with curl? All PayPal behaviour will be stored in the curl vaiables(if we can say so) If you are tied with this payment metho and don't want the button to be clicked mannually(read form to be submitted), you may submit it automatically using javascript. Or you may redirect user to the PalPal and pass all parameters via GET. It also should work. Otherwise you should use PayPal Payments Pro. Concretely - Direct Payment. User will fill out form on your site (credit card, billing info, etc) and you could use curl to finish payment.

Sorry for bad English. I tried to be clear. I hope it will be helpfull.

Upvotes: 1

Related Questions