0

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?

2 Answers 2

1

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.

4
  • I understand that the customer has to login paypal and enter payment and billing information. I just need this to get the user to the paypal page with the information set for the user to check out. I will look into using GET parameters and see if that works out. Thanks for the answer.
    – codacopia
    Jul 28, 2011 at 21:19
  • I was hesitating to ask but whatever, how about my English? Is it satisfactory? Don't hesitate with comments :) Jul 28, 2011 at 22:09
  • Thanks :) Have you solved your problem? Does passing parameters through GET work fine? Jul 31, 2011 at 21:17
  • I cannot seem to pass through GET because the values are encrypted.
    – codacopia
    Aug 1, 2011 at 4:53
0

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.

3
  • If you are going to downvote, it would be great if you could post a comment - why?
    – Sukumar
    Jul 28, 2011 at 23:14
  • I didn't down vote your answer. I am going to look into the javascript option you mentioned and see if that works out. Thanks.
    – codacopia
    Jul 31, 2011 at 21:11
  • @Presto, I was addressing the person who did downvote. Anyway, good luck with your problem.
    – Sukumar
    Jul 31, 2011 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.