paypal and php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anfetienne
    Contributor
    • Feb 2009
    • 424

    paypal and php

    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
  • anfetienne
    Contributor
    • Feb 2009
    • 424

    #2
    ok new question......w hen someone fills in a form....can the value of a field populate a var without the form being submitted?

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Originally posted by anfetienne
      ok new question......w hen someone fills in a form....can the value of a field populate a var without the form being submitted?
      Um, through AJAX I guess you could. Strange question, though.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by anfetienne
        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
        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.

        Comment

        • anfetienne
          Contributor
          • Feb 2009
          • 424

          #5
          i have no clue on how to use ajax.....is there not a way that i could do it all with php?

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            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:

            Code:
            <?php
            
            	# The data we want to POST.
            	$paypal_post = array('username' => 'markus', 'info' => 'is the daddy!');
            	
            	# cURL Handle.
            	$handle = curl_init('http://localhost/test.2.php');
            	
            	# Set the POST option.
            	curl_setopt($handle, CURLOPT_POST, TRUE);
            	
            	# Load the POST data into cURL
            	curl_setopt($handle, CURLOPT_POSTFIELDS, $paypal_post);
            	
            	# We'll get any output from the page.
            	curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
            	
            	# Store the return from curl_exec()
            	$return = curl_exec($handle);
            	
            	echo $return;
            
            ?>

            Comment

            • anfetienne
              Contributor
              • Feb 2009
              • 424

              #7
              so $handle is the url that i redirect back to so it can transfer to paypal?

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                Originally posted by anfetienne
                so $handle is the url that i redirect back to so it can transfer to paypal?
                curl_init() should point to the location you want to POST data (in your case, paypal's site).

                Comment

                • anfetienne
                  Contributor
                  • Feb 2009
                  • 424

                  #9
                  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');

                  Comment

                  • Markus
                    Recognized Expert Expert
                    • Jun 2007
                    • 6092

                    #10
                    Just pass it the POST array.

                    Code:
                    curl_setopt($handle, CURLOPT_POSTFIELDS, $_POST);
                    :)

                    Comment

                    • anfetienne
                      Contributor
                      • Feb 2009
                      • 424

                      #11
                      so if i use

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

                      i can use......withou t needing to use array()

                      curl_setopt($ha ndle, CURLOPT_POSTFIE LDS, $_POST);

                      Comment

                      • Markus
                        Recognized Expert Expert
                        • Jun 2007
                        • 6092

                        #12
                        Originally posted by anfetienne
                        so if i use

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

                        i can use......withou t needing to use array()

                        curl_setopt($ha ndle, CURLOPT_POSTFIE LDS, $_POST);
                        Exactly.

                        - mark.

                        Comment

                        • anfetienne
                          Contributor
                          • Feb 2009
                          • 424

                          #13
                          thanks again markus

                          I am going to make the file I need and ill get back to you with the results

                          Comment

                          • Markus
                            Recognized Expert Expert
                            • Jun 2007
                            • 6092

                            #14
                            Originally posted by anfetienne
                            thanks again markus

                            I am going to make the file I need and ill get back to you with the results
                            OK. Good luck :)

                            - mark.

                            Comment

                            • anfetienne
                              Contributor
                              • Feb 2009
                              • 424

                              #15
                              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

                              Code:
                              <?php
                              
                              $on0 = $_POST['on0'];
                              $firstName = $_POST['first_name'];
                              $lastName = $_POST['last_name'];
                              $address1 = $_POST['address1'];
                              $address2 = $_POST['address2'];
                              $city = $_POST['city'];
                              $state = $_POST['state'];
                              $zip = $_POST['zip'];
                              $os0 = $_POST['os0'];
                              $email = $_POST['email'];
                              $upload = $_POST['upload'];
                              $cmd = $_POST['cmd'];
                              $business = $_POST['business'];
                              $itemName1 = $_POST['item_name_1'];
                              $quantity1 = $_POST['quantity_1'];
                              $amount1 = $_POST['amount_1'];
                              $shipping1 = $_POST['shipping_1'];
                              $itemNumber1 = $_POST['item_number_1'];
                              $country = $_POST['country'];
                              $currencyCode = $_POST['currency_code'];
                              $noShipping = $_POST['no_shipping'];
                              $return = $_POST['return'];
                              $bn = $_POST['bn'];
                              $addressOverride = $_POST['address_override'];
                              
                              
                              # cURL Handle.
                              $handle = curl_init('https://www.paypal.co.uk/cgi-bin/webscr');
                              
                              # Set the POST option.
                              curl_setopt($handle, CURLOPT_POST, TRUE);
                              
                              # Load the POST data into cURL
                              curl_setopt($handle, CURLOPT_POSTFIELDS, $_POST);
                              
                              # We'll get any output from the page.
                              curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
                              
                              # Store the return from curl_exec()
                              $return = curl_exec($handle);
                              
                              echo $return;
                              
                              ?>

                              Comment

                              Working...