Search code examples
phppaypalpaypal-ipn

How to Send Multiple Variables Through PayPal IPN


This is the flow of customers:

Visit Website -> Fill Out Form With Their Info -> Click "Buy Now" and Checkout with PayPal -> Be Returned Back To The Website -> Use Information Passed From Checkout From to Run PHP script on server via ajax (assuming the checkout was successful). Well, that's the plan anyways. The problem I am having is figuring out how to actually pass the variables (there are 8 total... array???. I currently have a quick checkout button on the website, which redirects the user away to PayPal to complete the transaction. I've been searching for a good tutorial on YouTube or here at S.O., but have been unsuccessful. Any ideas how I may accomplish this?

Thanks


Solution

  • In your PayPal form, simply use something like the following for your custom field..

    Example:

    <input type="hidden" name="custom" value="<?php echo $custom1.','.$custom2.','.$custom3; ?>">
    

    or;

    <input type="hidden" name="custom" value="custom1,custom2,custom3">
    

    In short the custom name is accepted by PayPal, and you would use commas to separate the variables.

    PayPal will pass the custom field back to you, in the IPN.


    EDIT:

    Here's an example of what you might do with custom:

      $custom = $_POST['custom'];
      $pattern = ",";
      $pieces = explode($pattern,$custom, 3);
      // 3 is how many custom fields there are
      $custom1 = $pieces[0];
      $custom2 = $pieces[1];
      if (isset($pieces[2])) {
          //an example checking to see if there is a third custom variable
          $custom3 = $pieces[2];
      }