Paypal form - How to save fields as variables?












0















I have the following Paypal payment form:



<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="******">
<input type="hidden" name="item_name" value="******">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="amount" value="25">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input id="afield" type="text" placeholder="Name"</input>
<input id="afield" type="text" placeholder="Email Address"</input>
<!-- Saved buttons display an appropriate button image. -->
<input type="image" name="submit"
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif"
alt="PayPal - The safer, easier way to pay online">
<img alt="" width="1" height="1"
src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >




My question is, how can I get the two inputs (id: afield) so that I can save them for when the user returns to my website after paying, I can use them. I am using PHP.



Thanks










share|improve this question




















  • 1





    cookies? PHP session ? database ? chose what you want depend on your needs

    – Accountant م
    Nov 28 '18 at 18:52













  • No what I mean is, how do I actually get them as a variable in the first place? The form action is using Paypal's script: <form action="paypal.com/cgi-bin/webscr" method="post">

    – Bradley Joe
    Nov 28 '18 at 18:53













  • You shouldn't have 2 fields with the same id. Make them unique. Also, give them a name attribute. When the response comes back from PayPal it will come back in a GET or POST request. You'll have to figure that out. Once you know if it is a GET or POST request, you can access the data via $_GET['name_of_field'] or $_POST['name_of_field'] respectively. Just assign that to a variable. $myVariable = $_GET['name_of_field'];

    – waterloomatt
    Nov 28 '18 at 18:55













  • yeah you will receive them as custom field along in the IPN

    – Accountant م
    Nov 28 '18 at 18:57











  • Not sure if it is clear or not but you shouldn't try to save them at this point. The form you showed us is the outgoing request to PayPal. You'll have access to them when the response from PayPal (IPN) comes back. You can inspect the response and grab any of the data you need.

    – waterloomatt
    Nov 28 '18 at 19:03
















0















I have the following Paypal payment form:



<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="******">
<input type="hidden" name="item_name" value="******">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="amount" value="25">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input id="afield" type="text" placeholder="Name"</input>
<input id="afield" type="text" placeholder="Email Address"</input>
<!-- Saved buttons display an appropriate button image. -->
<input type="image" name="submit"
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif"
alt="PayPal - The safer, easier way to pay online">
<img alt="" width="1" height="1"
src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >




My question is, how can I get the two inputs (id: afield) so that I can save them for when the user returns to my website after paying, I can use them. I am using PHP.



Thanks










share|improve this question




















  • 1





    cookies? PHP session ? database ? chose what you want depend on your needs

    – Accountant م
    Nov 28 '18 at 18:52













  • No what I mean is, how do I actually get them as a variable in the first place? The form action is using Paypal's script: <form action="paypal.com/cgi-bin/webscr" method="post">

    – Bradley Joe
    Nov 28 '18 at 18:53













  • You shouldn't have 2 fields with the same id. Make them unique. Also, give them a name attribute. When the response comes back from PayPal it will come back in a GET or POST request. You'll have to figure that out. Once you know if it is a GET or POST request, you can access the data via $_GET['name_of_field'] or $_POST['name_of_field'] respectively. Just assign that to a variable. $myVariable = $_GET['name_of_field'];

    – waterloomatt
    Nov 28 '18 at 18:55













  • yeah you will receive them as custom field along in the IPN

    – Accountant م
    Nov 28 '18 at 18:57











  • Not sure if it is clear or not but you shouldn't try to save them at this point. The form you showed us is the outgoing request to PayPal. You'll have access to them when the response from PayPal (IPN) comes back. You can inspect the response and grab any of the data you need.

    – waterloomatt
    Nov 28 '18 at 19:03














0












0








0








I have the following Paypal payment form:



<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="******">
<input type="hidden" name="item_name" value="******">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="amount" value="25">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input id="afield" type="text" placeholder="Name"</input>
<input id="afield" type="text" placeholder="Email Address"</input>
<!-- Saved buttons display an appropriate button image. -->
<input type="image" name="submit"
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif"
alt="PayPal - The safer, easier way to pay online">
<img alt="" width="1" height="1"
src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >




My question is, how can I get the two inputs (id: afield) so that I can save them for when the user returns to my website after paying, I can use them. I am using PHP.



Thanks










share|improve this question
















I have the following Paypal payment form:



<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="******">
<input type="hidden" name="item_name" value="******">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="amount" value="25">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input id="afield" type="text" placeholder="Name"</input>
<input id="afield" type="text" placeholder="Email Address"</input>
<!-- Saved buttons display an appropriate button image. -->
<input type="image" name="submit"
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif"
alt="PayPal - The safer, easier way to pay online">
<img alt="" width="1" height="1"
src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >




My question is, how can I get the two inputs (id: afield) so that I can save them for when the user returns to my website after paying, I can use them. I am using PHP.



Thanks







php paypal






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 18:54







Bradley Joe

















asked Nov 28 '18 at 18:49









Bradley JoeBradley Joe

152




152








  • 1





    cookies? PHP session ? database ? chose what you want depend on your needs

    – Accountant م
    Nov 28 '18 at 18:52













  • No what I mean is, how do I actually get them as a variable in the first place? The form action is using Paypal's script: <form action="paypal.com/cgi-bin/webscr" method="post">

    – Bradley Joe
    Nov 28 '18 at 18:53













  • You shouldn't have 2 fields with the same id. Make them unique. Also, give them a name attribute. When the response comes back from PayPal it will come back in a GET or POST request. You'll have to figure that out. Once you know if it is a GET or POST request, you can access the data via $_GET['name_of_field'] or $_POST['name_of_field'] respectively. Just assign that to a variable. $myVariable = $_GET['name_of_field'];

    – waterloomatt
    Nov 28 '18 at 18:55













  • yeah you will receive them as custom field along in the IPN

    – Accountant م
    Nov 28 '18 at 18:57











  • Not sure if it is clear or not but you shouldn't try to save them at this point. The form you showed us is the outgoing request to PayPal. You'll have access to them when the response from PayPal (IPN) comes back. You can inspect the response and grab any of the data you need.

    – waterloomatt
    Nov 28 '18 at 19:03














  • 1





    cookies? PHP session ? database ? chose what you want depend on your needs

    – Accountant م
    Nov 28 '18 at 18:52













  • No what I mean is, how do I actually get them as a variable in the first place? The form action is using Paypal's script: <form action="paypal.com/cgi-bin/webscr" method="post">

    – Bradley Joe
    Nov 28 '18 at 18:53













  • You shouldn't have 2 fields with the same id. Make them unique. Also, give them a name attribute. When the response comes back from PayPal it will come back in a GET or POST request. You'll have to figure that out. Once you know if it is a GET or POST request, you can access the data via $_GET['name_of_field'] or $_POST['name_of_field'] respectively. Just assign that to a variable. $myVariable = $_GET['name_of_field'];

    – waterloomatt
    Nov 28 '18 at 18:55













  • yeah you will receive them as custom field along in the IPN

    – Accountant م
    Nov 28 '18 at 18:57











  • Not sure if it is clear or not but you shouldn't try to save them at this point. The form you showed us is the outgoing request to PayPal. You'll have access to them when the response from PayPal (IPN) comes back. You can inspect the response and grab any of the data you need.

    – waterloomatt
    Nov 28 '18 at 19:03








1




1





cookies? PHP session ? database ? chose what you want depend on your needs

– Accountant م
Nov 28 '18 at 18:52







cookies? PHP session ? database ? chose what you want depend on your needs

– Accountant م
Nov 28 '18 at 18:52















No what I mean is, how do I actually get them as a variable in the first place? The form action is using Paypal's script: <form action="paypal.com/cgi-bin/webscr" method="post">

– Bradley Joe
Nov 28 '18 at 18:53







No what I mean is, how do I actually get them as a variable in the first place? The form action is using Paypal's script: <form action="paypal.com/cgi-bin/webscr" method="post">

– Bradley Joe
Nov 28 '18 at 18:53















You shouldn't have 2 fields with the same id. Make them unique. Also, give them a name attribute. When the response comes back from PayPal it will come back in a GET or POST request. You'll have to figure that out. Once you know if it is a GET or POST request, you can access the data via $_GET['name_of_field'] or $_POST['name_of_field'] respectively. Just assign that to a variable. $myVariable = $_GET['name_of_field'];

– waterloomatt
Nov 28 '18 at 18:55







You shouldn't have 2 fields with the same id. Make them unique. Also, give them a name attribute. When the response comes back from PayPal it will come back in a GET or POST request. You'll have to figure that out. Once you know if it is a GET or POST request, you can access the data via $_GET['name_of_field'] or $_POST['name_of_field'] respectively. Just assign that to a variable. $myVariable = $_GET['name_of_field'];

– waterloomatt
Nov 28 '18 at 18:55















yeah you will receive them as custom field along in the IPN

– Accountant م
Nov 28 '18 at 18:57





yeah you will receive them as custom field along in the IPN

– Accountant م
Nov 28 '18 at 18:57













Not sure if it is clear or not but you shouldn't try to save them at this point. The form you showed us is the outgoing request to PayPal. You'll have access to them when the response from PayPal (IPN) comes back. You can inspect the response and grab any of the data you need.

– waterloomatt
Nov 28 '18 at 19:03





Not sure if it is clear or not but you shouldn't try to save them at this point. The form you showed us is the outgoing request to PayPal. You'll have access to them when the response from PayPal (IPN) comes back. You can inspect the response and grab any of the data you need.

– waterloomatt
Nov 28 '18 at 19:03












2 Answers
2






active

oldest

votes


















0














Here is how I have dealt with this in the past.



First step is to fix the input field:



<input id="afield" type="text" placeholder="Name" name="afield">


I have corrected your HTML syntax and called the field afield



You then need to set another hidden field called notify_url - this is the URL that PayPal will POST the transaction details back to after a payment has been made.



e.g.



<input type="hidden" name="notify_url" value="https://www.yourdomain.com/paypal.php">


Inside paypal.php you can then access $_POST['afield']



In case it helps, here is the sort of thing you need inside paypal.php - this verifies that the transaction details POSTed back from PayPal are genuine and that the payment was successful:



$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the IPN message sent from PayPal and prepend 'cmd=_notify-validate'
$req = 'cmd=_notify-validate';
if (function_exists('get_magic_quotes_gpc')) {
$get_magic_quotes_exists = true;
}
foreach ($myPost as $key => $value) {
if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
$value = urlencode(stripslashes($value));
} else {
$value = urlencode($value);
}
$req .= "&$key=$value";
}

// Step 2: POST IPN data back to PayPal to validate
$ch = curl_init('https://ipnpb.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
if ( !($res = curl_exec($ch)) ) {
curl_close($ch);
exit;
}
curl_close($ch);

if (strcmp ($res, "VERIFIED") == 0 and $_POST['payment_status'] == 'Completed') {

// payment has been verified

}





share|improve this answer































    0














    You can add a field with the name custom



    The only issue is this field can't be returned by Paypal in the answer, even in the PDT



    Only can see this field in the IPN text



    https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNandPDTVariables/#transaction-and-notification-related-variables



    https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNPDTAnAlternativetoIPN/






    share|improve this answer
























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53526163%2fpaypal-form-how-to-save-fields-as-variables%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Here is how I have dealt with this in the past.



      First step is to fix the input field:



      <input id="afield" type="text" placeholder="Name" name="afield">


      I have corrected your HTML syntax and called the field afield



      You then need to set another hidden field called notify_url - this is the URL that PayPal will POST the transaction details back to after a payment has been made.



      e.g.



      <input type="hidden" name="notify_url" value="https://www.yourdomain.com/paypal.php">


      Inside paypal.php you can then access $_POST['afield']



      In case it helps, here is the sort of thing you need inside paypal.php - this verifies that the transaction details POSTed back from PayPal are genuine and that the payment was successful:



      $raw_post_data = file_get_contents('php://input');
      $raw_post_array = explode('&', $raw_post_data);
      $myPost = array();
      foreach ($raw_post_array as $keyval) {
      $keyval = explode ('=', $keyval);
      if (count($keyval) == 2)
      $myPost[$keyval[0]] = urldecode($keyval[1]);
      }
      // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate'
      $req = 'cmd=_notify-validate';
      if (function_exists('get_magic_quotes_gpc')) {
      $get_magic_quotes_exists = true;
      }
      foreach ($myPost as $key => $value) {
      if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
      $value = urlencode(stripslashes($value));
      } else {
      $value = urlencode($value);
      }
      $req .= "&$key=$value";
      }

      // Step 2: POST IPN data back to PayPal to validate
      $ch = curl_init('https://ipnpb.paypal.com/cgi-bin/webscr');
      curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
      curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
      if ( !($res = curl_exec($ch)) ) {
      curl_close($ch);
      exit;
      }
      curl_close($ch);

      if (strcmp ($res, "VERIFIED") == 0 and $_POST['payment_status'] == 'Completed') {

      // payment has been verified

      }





      share|improve this answer




























        0














        Here is how I have dealt with this in the past.



        First step is to fix the input field:



        <input id="afield" type="text" placeholder="Name" name="afield">


        I have corrected your HTML syntax and called the field afield



        You then need to set another hidden field called notify_url - this is the URL that PayPal will POST the transaction details back to after a payment has been made.



        e.g.



        <input type="hidden" name="notify_url" value="https://www.yourdomain.com/paypal.php">


        Inside paypal.php you can then access $_POST['afield']



        In case it helps, here is the sort of thing you need inside paypal.php - this verifies that the transaction details POSTed back from PayPal are genuine and that the payment was successful:



        $raw_post_data = file_get_contents('php://input');
        $raw_post_array = explode('&', $raw_post_data);
        $myPost = array();
        foreach ($raw_post_array as $keyval) {
        $keyval = explode ('=', $keyval);
        if (count($keyval) == 2)
        $myPost[$keyval[0]] = urldecode($keyval[1]);
        }
        // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate'
        $req = 'cmd=_notify-validate';
        if (function_exists('get_magic_quotes_gpc')) {
        $get_magic_quotes_exists = true;
        }
        foreach ($myPost as $key => $value) {
        if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
        $value = urlencode(stripslashes($value));
        } else {
        $value = urlencode($value);
        }
        $req .= "&$key=$value";
        }

        // Step 2: POST IPN data back to PayPal to validate
        $ch = curl_init('https://ipnpb.paypal.com/cgi-bin/webscr');
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
        if ( !($res = curl_exec($ch)) ) {
        curl_close($ch);
        exit;
        }
        curl_close($ch);

        if (strcmp ($res, "VERIFIED") == 0 and $_POST['payment_status'] == 'Completed') {

        // payment has been verified

        }





        share|improve this answer


























          0












          0








          0







          Here is how I have dealt with this in the past.



          First step is to fix the input field:



          <input id="afield" type="text" placeholder="Name" name="afield">


          I have corrected your HTML syntax and called the field afield



          You then need to set another hidden field called notify_url - this is the URL that PayPal will POST the transaction details back to after a payment has been made.



          e.g.



          <input type="hidden" name="notify_url" value="https://www.yourdomain.com/paypal.php">


          Inside paypal.php you can then access $_POST['afield']



          In case it helps, here is the sort of thing you need inside paypal.php - this verifies that the transaction details POSTed back from PayPal are genuine and that the payment was successful:



          $raw_post_data = file_get_contents('php://input');
          $raw_post_array = explode('&', $raw_post_data);
          $myPost = array();
          foreach ($raw_post_array as $keyval) {
          $keyval = explode ('=', $keyval);
          if (count($keyval) == 2)
          $myPost[$keyval[0]] = urldecode($keyval[1]);
          }
          // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate'
          $req = 'cmd=_notify-validate';
          if (function_exists('get_magic_quotes_gpc')) {
          $get_magic_quotes_exists = true;
          }
          foreach ($myPost as $key => $value) {
          if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
          $value = urlencode(stripslashes($value));
          } else {
          $value = urlencode($value);
          }
          $req .= "&$key=$value";
          }

          // Step 2: POST IPN data back to PayPal to validate
          $ch = curl_init('https://ipnpb.paypal.com/cgi-bin/webscr');
          curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
          curl_setopt($ch, CURLOPT_POST, 1);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
          curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
          curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
          curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
          if ( !($res = curl_exec($ch)) ) {
          curl_close($ch);
          exit;
          }
          curl_close($ch);

          if (strcmp ($res, "VERIFIED") == 0 and $_POST['payment_status'] == 'Completed') {

          // payment has been verified

          }





          share|improve this answer













          Here is how I have dealt with this in the past.



          First step is to fix the input field:



          <input id="afield" type="text" placeholder="Name" name="afield">


          I have corrected your HTML syntax and called the field afield



          You then need to set another hidden field called notify_url - this is the URL that PayPal will POST the transaction details back to after a payment has been made.



          e.g.



          <input type="hidden" name="notify_url" value="https://www.yourdomain.com/paypal.php">


          Inside paypal.php you can then access $_POST['afield']



          In case it helps, here is the sort of thing you need inside paypal.php - this verifies that the transaction details POSTed back from PayPal are genuine and that the payment was successful:



          $raw_post_data = file_get_contents('php://input');
          $raw_post_array = explode('&', $raw_post_data);
          $myPost = array();
          foreach ($raw_post_array as $keyval) {
          $keyval = explode ('=', $keyval);
          if (count($keyval) == 2)
          $myPost[$keyval[0]] = urldecode($keyval[1]);
          }
          // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate'
          $req = 'cmd=_notify-validate';
          if (function_exists('get_magic_quotes_gpc')) {
          $get_magic_quotes_exists = true;
          }
          foreach ($myPost as $key => $value) {
          if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
          $value = urlencode(stripslashes($value));
          } else {
          $value = urlencode($value);
          }
          $req .= "&$key=$value";
          }

          // Step 2: POST IPN data back to PayPal to validate
          $ch = curl_init('https://ipnpb.paypal.com/cgi-bin/webscr');
          curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
          curl_setopt($ch, CURLOPT_POST, 1);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
          curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
          curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
          curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
          if ( !($res = curl_exec($ch)) ) {
          curl_close($ch);
          exit;
          }
          curl_close($ch);

          if (strcmp ($res, "VERIFIED") == 0 and $_POST['payment_status'] == 'Completed') {

          // payment has been verified

          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 28 '18 at 18:56









          ChrisChris

          2,81863058




          2,81863058

























              0














              You can add a field with the name custom



              The only issue is this field can't be returned by Paypal in the answer, even in the PDT



              Only can see this field in the IPN text



              https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNandPDTVariables/#transaction-and-notification-related-variables



              https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNPDTAnAlternativetoIPN/






              share|improve this answer




























                0














                You can add a field with the name custom



                The only issue is this field can't be returned by Paypal in the answer, even in the PDT



                Only can see this field in the IPN text



                https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNandPDTVariables/#transaction-and-notification-related-variables



                https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNPDTAnAlternativetoIPN/






                share|improve this answer


























                  0












                  0








                  0







                  You can add a field with the name custom



                  The only issue is this field can't be returned by Paypal in the answer, even in the PDT



                  Only can see this field in the IPN text



                  https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNandPDTVariables/#transaction-and-notification-related-variables



                  https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNPDTAnAlternativetoIPN/






                  share|improve this answer













                  You can add a field with the name custom



                  The only issue is this field can't be returned by Paypal in the answer, even in the PDT



                  Only can see this field in the IPN text



                  https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNandPDTVariables/#transaction-and-notification-related-variables



                  https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNPDTAnAlternativetoIPN/







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 28 '18 at 20:41









                  SuNcOSuNcO

                  53




                  53






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53526163%2fpaypal-form-how-to-save-fields-as-variables%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Lallio

                      Futebolista

                      Jornalista