473,413 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

paypal and php

anfetienne
424 256MB
ok i have a form that users fill in and that form submits the details securely to paypal for payment.....the reason for this is so users dont have to fill out everything twice (i hate it and i guess many people do).

there is one problem i have with paypal though.....i'd like to send a confirmation email out with all the details of the purchase and also a username and password to a online resource centre that i created. paypal doesn't have this function it only allows for invoices of purchase which is a standard when you purchase something using paypal.....is there anyway i can get the email address out of the form to store into a database so that i can use it in my coding to send an email?

as it is a paypal form all details usually go straight to paypal.....is there anyway i can double the email address and save it to a database so i can send the needed email?

thanks
Apr 21 '09 #1
35 3183
anfetienne
424 256MB
ok new question......when someone fills in a form....can the value of a field populate a var without the form being submitted?
Apr 21 '09 #2
Markus
6,050 Expert 4TB
@anfetienne
Um, through AJAX I guess you could. Strange question, though.
Apr 21 '09 #3
Markus
6,050 Expert 4TB
@anfetienne
Are you submitting the form to paypal?

I guess you could, using javascript, when the submit button is hit, use AJAX to send the email address to a php page and store that in a database, and then when that request is done, use javascript to resubmit the same form to paypal.
Apr 21 '09 #4
anfetienne
424 256MB
i have no clue on how to use ajax.....is there not a way that i could do it all with php?
Apr 21 '09 #5
Markus
6,050 Expert 4TB
You could have the form submit to a php page (of yours), take the form data, process it, and then use cURL to post the data to paypal.

Something like below:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.     # The data we want to POST.
  4.     $paypal_post = array('username' => 'markus', 'info' => 'is the daddy!');
  5.  
  6.     # cURL Handle.
  7.     $handle = curl_init('http://localhost/test.2.php');
  8.  
  9.     # Set the POST option.
  10.     curl_setopt($handle, CURLOPT_POST, TRUE);
  11.  
  12.     # Load the POST data into cURL
  13.     curl_setopt($handle, CURLOPT_POSTFIELDS, $paypal_post);
  14.  
  15.     # We'll get any output from the page.
  16.     curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
  17.  
  18.     # Store the return from curl_exec()
  19.     $return = curl_exec($handle);
  20.  
  21.     echo $return;
  22.  
  23. ?>
Apr 22 '09 #6
anfetienne
424 256MB
so $handle is the url that i redirect back to so it can transfer to paypal?
Apr 22 '09 #7
Markus
6,050 Expert 4TB
@anfetienne
curl_init() should point to the location you want to POST data (in your case, paypal's site).
Apr 22 '09 #8
anfetienne
424 256MB
ok i understand that but to get the items into an array would i do something like this?

e.g.

$var1 = $_POST['name']
$var2 = $_POST['email']
$var3 = $_POST['country']

$paypal_post = array('name' => '$var1', 'email' => '$var2', 'country' => '$var3');
Apr 22 '09 #9
Markus
6,050 Expert 4TB
Just pass it the POST array.

Expand|Select|Wrap|Line Numbers
  1. curl_setopt($handle, CURLOPT_POSTFIELDS, $_POST);
  2.  
:)
Apr 22 '09 #10
anfetienne
424 256MB
so if i use

$var1 = $_POST['name']
$var2 = $_POST['email']
$var3 = $_POST['country']

i can use......without needing to use array()

curl_setopt($handle, CURLOPT_POSTFIELDS, $_POST);
Apr 22 '09 #11
Markus
6,050 Expert 4TB
@anfetienne
Exactly.

- mark.
Apr 22 '09 #12
anfetienne
424 256MB
thanks again markus

I am going to make the file I need and ill get back to you with the results
Apr 22 '09 #13
Markus
6,050 Expert 4TB
@anfetienne
OK. Good luck :)

- mark.
Apr 22 '09 #14
anfetienne
424 256MB
hi,

I have tried the coding but the result is just a blank page that looks like its loading something but nothing actually happens.

you can see the form at http://theauctionwinners.com/test1/

and the coding that i used for the curl is this

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $on0 = $_POST['on0'];
  4. $firstName = $_POST['first_name'];
  5. $lastName = $_POST['last_name'];
  6. $address1 = $_POST['address1'];
  7. $address2 = $_POST['address2'];
  8. $city = $_POST['city'];
  9. $state = $_POST['state'];
  10. $zip = $_POST['zip'];
  11. $os0 = $_POST['os0'];
  12. $email = $_POST['email'];
  13. $upload = $_POST['upload'];
  14. $cmd = $_POST['cmd'];
  15. $business = $_POST['business'];
  16. $itemName1 = $_POST['item_name_1'];
  17. $quantity1 = $_POST['quantity_1'];
  18. $amount1 = $_POST['amount_1'];
  19. $shipping1 = $_POST['shipping_1'];
  20. $itemNumber1 = $_POST['item_number_1'];
  21. $country = $_POST['country'];
  22. $currencyCode = $_POST['currency_code'];
  23. $noShipping = $_POST['no_shipping'];
  24. $return = $_POST['return'];
  25. $bn = $_POST['bn'];
  26. $addressOverride = $_POST['address_override'];
  27.  
  28.  
  29. # cURL Handle.
  30. $handle = curl_init('https://www.paypal.co.uk/cgi-bin/webscr');
  31.  
  32. # Set the POST option.
  33. curl_setopt($handle, CURLOPT_POST, TRUE);
  34.  
  35. # Load the POST data into cURL
  36. curl_setopt($handle, CURLOPT_POSTFIELDS, $_POST);
  37.  
  38. # We'll get any output from the page.
  39. curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
  40.  
  41. # Store the return from curl_exec()
  42. $return = curl_exec($handle);
  43.  
  44. echo $return;
  45.  
  46. ?>
  47.  
Apr 24 '09 #15
Markus
6,050 Expert 4TB
Well apparently you cannot cURL data to paypal - it won't allow it. Shame.

You may have to build a query string (GET) and then redirect to that url once you have processed the information.

Expand|Select|Wrap|Line Numbers
  1.  
  2. // Process your information
  3. // and then ...
  4. $firstname = $_POST['first_name'];
  5. $secondname = $_POST['second_name'];
  6. // etc
  7.  
  8. $query_string = "?first_name={$first_name}&second_name={$second_name}";
  9. $query_string = urlencode($query_string);
  10.  
  11. header("Location: http://paypal.com/{$query_string}");
  12.  
  13.  
Apr 24 '09 #16
anfetienne
424 256MB
so basically use $firstname = $_GET['first_name'];

then process it using

$firstname = $_POST['first_name'];
Apr 24 '09 #17
Markus
6,050 Expert 4TB
@anfetienne
No, not quite. You don't need to use GET, you just build up the query string (paypal will use GET on their side).
Apr 24 '09 #18
anfetienne
424 256MB
ahhhh i see.....ok thanks markus.

i'll try it out and come back with the results
Apr 24 '09 #19
anfetienne
424 256MB
hi,

here are my results....no luck on getting data to paypal....my guess is the link is wrong

Not Found
The requested URL /cgi-bin/webscr?on0=shipping+To:&first_name=sdfsd&last_name =fsdfsdf&address1=dsfsdf&address2=sdfsdf&city=sdfs df&state=sdfsdf&zip=sdfsdf&os0=Anguilla&email=anf. etienne@googlemail.com&upload=1&cmd=_cart&business =john@future-resourcings.com&item_name_1=Adam+Ginsberg's+The+Cl osely+Guarded+Secrets+Of+An+Ebay+Millionaire+-+Make+Money+On+eBay+-+FAST+TRACK+DVD+Home+Study+Course+(Inc+VAT)&quanti ty_1=1&amount_1=97.00&shipping_1=35.7&item_number_ 1=TAW-AG_2008-AI&country=AI&currency_code=GBP&no_shipping=2&retu rn=http://www.theauctionwinners.com/main&bn=TheAuctionWinners_ShopCart_WPS_GB&address_ override=1 was not found on this server.

Apache/1.3.33 Server at www.paypal.co.uk Port 20006
Apr 27 '09 #20
anfetienne
424 256MB
hi,

I have found a sample cURL code to link it to paypal, could someone explain it to me so i can grasp it a lil to edit it?

Expand|Select|Wrap|Line Numbers
  1. <CODE><?
  2. $sendTo = "http://www.paypal.com/cgi-bin/webscr";
  3. $header[] = "Content-type: text/html";
  4.  
  5. $dataArray[] = 'business=info@WEBSITE.com.au';
  6. $dataArray[] = 'cmd=xclick';
  7. $dataArray[] = 'amount=1.00';
  8.  
  9. $post = implode($dataArray, '&');
  10. $post = urlencode($post);
  11.  
  12.  
  13. $ch = curl_init();
  14. curl_setopt($ch, CURLOPT_CONNECTIONTIMEOUT, 30);
  15. curl_setopt($ch, CURLOPT_FAILONERROR, false);
  16. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  17. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  18. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  19. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  20. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  21. curl_setopt($ch, CURLOPT_POST, true);
  22. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  23.  
  24. die();
  25. ?></CODE>
  26.  
Apr 27 '09 #21
anfetienne
424 256MB
i have changed the coding and tested to suit my needs this is the code and below it is the result

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $on0 = $_POST['on0'];
  3. $firstName = $_POST['first_name'];
  4. $lastName = $_POST['last_name'];
  5. $address1 = $_POST['address1'];
  6. $address2 = $_POST['address2'];
  7. $city = $_POST['city'];
  8. $state = $_POST['state'];
  9. $zip = $_POST['zip'];
  10. $os0 = $_POST['os0'];
  11. $email = $_POST['email'];
  12. $upload = $_POST['upload'];
  13. $cmd = $_POST['cmd'];
  14. $business = $_POST['business'];
  15. $itemName1 = $_POST['item_name_1'];
  16. $quantity1 = $_POST['quantity_1'];
  17. $amount1 = $_POST['amount_1'];
  18. $shipping1 = $_POST['shipping_1'];
  19. $itemNumber1 = $_POST['item_number_1'];
  20. $country = $_POST['country'];
  21. $currencyCode = $_POST['currency_code'];
  22. $noShipping = $_POST['no_shipping'];
  23. $return = $_POST['return'];
  24. $bn = $_POST['bn'];
  25. $addressOverride = $_POST['address_override'];
  26.  
  27. $sendTo = "https://www.paypal.com/cgi-bin/webscr";
  28. $header[] = "Content-type: text/html";
  29.  
  30. $dataArray[] = "cmd='{$cmd}'";
  31. $dataArray[] = "on0='{$on0}'";
  32. $dataArray[] = "first_name='{$firstName}'";
  33. $dataArray[] = "last_name='{$lastName}'";
  34. $dataArray[] = "address1='{$address1}'";
  35. $dataArray[] = "address2='{$address2}'";
  36. $dataArray[] = "city='{$city}'";
  37. $dataArray[] = "state='{$state}'";
  38. $dataArray[] = "zip='{$zip}'";
  39. $dataArray[] = "os0='{$os0}'";
  40. $dataArray[] = "email='{$email}'";
  41. $dataArray[] = "upload='{$upload}'";
  42. $dataArray[] = "business='{$business}'";
  43. $dataArray[] = "item_name_1='{$itemName1}'";
  44. $dataArray[] = "quantity_1='{$quantity1}'";
  45. $dataArray[] = "amount_1='{$amount1}'";
  46. $dataArray[] = "shipping_1='{$shipping1}'";
  47. $dataArray[] = "item_number_1='{$itemNumber1}'";
  48. $dataArray[] = "country='{$country}'";
  49. $dataArray[] = "currency_code='{$currencyCode}'";
  50. $dataArray[] = "no_shipping='{$noShipping}'";
  51. $dataArray[] = "return='{$return}'";
  52. $dataArray[] = "bn='{$bn}'";
  53. $dataArray[] = "address_override='{$addressOverride}'";
  54.  
  55. $post = implode('&', $dataArray);
  56. $post = urlencode($post);
  57.  
  58. $ch = curl_init('http://www.paypal.co.uk/cgi-bin/webscr');
  59. curl_setopt($ch, CURLOPT_CONNECTIONTIMEOUT, 30);
  60. curl_setopt($ch, CURLOPT_FAILONERROR, false);
  61. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  62. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  63. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  64. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  65. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  66. curl_setopt($ch, CURLOPT_POST, true);
  67. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  68.  
  69. die();
  70. ?>
  71.  
THE RESULTS.....

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in /var/www/vhosts/theauctionwinners.com/httpdocs/test1/data.php on line 70
Apr 27 '09 #22
Markus
6,050 Expert 4TB
@anfetienne
Okay, using that, we should be able to get it to work - not promising anything though.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // Url to post data to.
  4. $sendTo = "http://www.paypal.com/cgi-bin/webscr";
  5.  
  6. // The content-type http header.
  7. $header[] = "Content-type: text/html";
  8.  
  9. // This should reflect the data you want to send.
  10. // PSEUDOCODE:
  11. // - $dataArray[] = 'param1=' . $_POST['param1'];
  12. // - $dataArray[] = 'param2=' . $_POST['param2'];
  13. $dataArray[] = 'business=info@WEBSITE.com.au';
  14. $dataArray[] = 'cmd=xclick';
  15. $dataArray[] = 'amount=1.00';
  16.  
  17. // Implode the array into GET formatting.
  18. $post = implode($dataArray, '&');
  19. // Encode it to avoid any issues.
  20. $post = urlencode($post);
  21.  
  22. // Initialize the cURL, with the url to open as the parameter.
  23. $ch = curl_init($sendTo);
  24. // Sets the pages timeout.
  25. curl_setopt($ch, CURLOPT_CONNECTIONTIMEOUT, 30);
  26. // Self explanatory.
  27. curl_setopt($ch, CURLOPT_FAILONERROR, false);
  28. // Security
  29. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  30. // Again
  31. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  32. // Follow any header redirects in the $header array.
  33. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  34. // Return any output from $sendTo - defaults to false
  35. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  36. // Set the headers
  37. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  38. // Are we going to post ?
  39. curl_setopt($ch, CURLOPT_POST, true);
  40. // Set the post fields.
  41. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  42.  
  43. // Execute!
  44. curl_exec($ch);
  45.  
  46.  
  47. ?>
The comments should explain it enough.
Apr 27 '09 #23
Markus
6,050 Expert 4TB
Remove the FOLLOWLOCATION option - you don't need it, I don't think.
Apr 27 '09 #24
anfetienne
424 256MB
ok i understand what you're getting at.....do you recommend me using the psuedocode for the data array?
Apr 27 '09 #25
Markus
6,050 Expert 4TB
@anfetienne
You've done it anyway. :)

Pseudo-code is just an example (kinda) and you implemented it.

Does it work?
Apr 27 '09 #26
anfetienne
424 256MB
i've implemented it this way?

$dataArray[] = "cmd='{$cmd}'";
Apr 27 '09 #27
Markus
6,050 Expert 4TB
@anfetienne
That's fine.


Mark.
Apr 27 '09 #28
anfetienne
424 256MB
no joy it still runs a blank page and acts as if its loading......i tried it with the 2nd method you said but that wouldn't work because the paypal url is incorrect and i dont think they allow the use of that code so it forces $_GET on their side
Apr 27 '09 #29
jeddiki
290 100+
I needed to do a similar thing last month.

But I just used a form to post the details directly to paypal
and then we got the details back from paypal using
an ipn script.

This is the form we used:

Expand|Select|Wrap|Line Numbers
  1. <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
  2. <input type="hidden" name="rm" value="2">
  3. <input type="hidden" name="cmd" value="_xclick-subscriptions">
  4. ...
  5. <input type="hidden" name="notify_url" value="http://www.oursite.com/ipn_proc.php">
Why are you trying to save the data before it goes through paypal ?
Is it because you don't trust the paypal system?

Most of the dat that comes back from the ipn is data that is stored by paypal anyway.

Hope this helps.
Apr 27 '09 #30
anfetienne
424 256MB
its helpful except this isn't for a shopping cart and unfortunately paypal aren't all too forgiving when it comes to using ipn's on a simple buy now button.....if there was a way i could use ipn script to get the data back after using buy now i would :( i've not found a way to do that that's why i need to get the data either before using php or during using javascript/ajax...only prolem is im not ajax literate and the best way using php paypal seem to not allow
Apr 27 '09 #31
anfetienne
424 256MB
markus can you tell me what you think to this?

http://developer.apple.com/internet/...mlhttpreq.html
Apr 27 '09 #32
jeddiki
290 100+
So you are trying to collect the following data from a potential client ?

# $firstName = $_POST['first_name'];
# $lastName = $_POST['last_name'];
# $address1 = $_POST['address1'];
# $address2 = $_POST['address2'];
# $city = $_POST['city'];
# $state = $_POST['state'];
# $zip = $_POST['zip'];

Paypal holds all that data, so you don't have to ask for it.

IMHO if you try and collect it - I don't think you will get any sign ups.
Apr 27 '09 #33
anfetienne
424 256MB
it works if you have a shopping cart...im just trying to change it for a buy now button....there are no sign ups and as i said i cant use ipn with a buy now unfortunately
Apr 27 '09 #34
jeddiki
290 100+
OK - just trying to help

That cURL stuff is what I have trouble with as well !!

I mention it a bit in my post:

"Can I convert this script to use different tool ?"

Do you have any clue on that ?
Apr 27 '09 #35
anfetienne
424 256MB
so far the best way is curl....next would be to have javascript pass variables to php somehow in the background
Apr 27 '09 #36

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Stephane | last post by:
Hi, I'm trying to use PayPal and its Instant Payment Notification. In short, when a payment is made, PayPal send a post to my server and I post it back to PayPal. I'm using WebRequest to do...
2
by: Tommy | last post by:
I have written some code to use paypal for users to make purchases from my site. I am using the paypal instant payment notification. When i get the notification from paypal I send the user an...
7
by: Alan Silver | last post by:
Hello, I've just been looking at the free PayPal component from ComponentOne and am somewhat amazed how insecure it is. They include all the transaction details in plain text in the querystring,...
3
by: Yourself | last post by:
Hi, I'm trying to post data to PayPal for a shopping cart, basically I want to replicate a form like the following, but create the variables dynamically from code behind: <form...
0
by: PayPal Security Measures! | last post by:
<P><A href="http://www.paypal.com/cgi-bin/webscr?cmd=_home" target=_blank><IMG src="https://www.paypal.com/en_US/i/logo/paypal_logo.gif" border=0></A</P> <TABLE cellSpacing=0 cellPadding=0...
1
by: MehtabKhan | last post by:
Any one who tell me what’s wrong with this code. When I pass values to pay pal by using www.sandbox.paypal.com/cgi-bin/webscr all the code are working well. The orders are generating accurately....
0
by: micahel | last post by:
Please chat with me by cnbbiz2008@hotmail.com to get the price and more photos, we take supplier paypal as payment. please see the photo album below for our product list. trainers supplier...
0
by: Nicodemus | last post by:
Do You Belive? \ cheapbbc@sina.com wrote in news:aecf26b6-4c75-4d87-b09c-a7380875e0f3 @w34g2000prm.googlegroups.com:
0
by: micahel | last post by:
Please chat with me by cnbbiz2008@hotmail.com to get the price and more photos, we take supplier paypal as payment. please see the photo album below for our product list. trainers supplier...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.