Note that there are some explanatory texts on larger screens.

plurals
  1. POsubmitting the form after successful paypal money transaction using php
    primarykey
    data
    text
    <p>I've made a form. Currently this form does the following operations:</p> <ol> <li>customer fills up the form (creates an order)</li> <li>clicks on "Submit" button</li> <li>all form entries are entered into a database.</li> </ol> <p>I'd like to change it to do the following operations:</p> <ol> <li>customer fills up the form</li> <li>in the end of the form there is a text box showing much this order will cost him.</li> <li>clicks on "Submit" button (if accepts the price)</li> <li>redirected to paypal</li> <li>if the payment is successful -> all form entries are entered into a database. Else -> echo "transaction failed".</li> </ol> <p>Here is what I've done so far:</p> <p><strong>"form.php" contents</strong></p> <pre><code>&lt;html&gt;&lt;head&gt;&lt;title&gt;Title&lt;/title&gt;&lt;/head&gt;&lt;body&gt; &lt;form action="php-form-processor.php" method="post"&gt; &lt;table border="0" cellspacing="5" width = "500"&gt; &lt;tr&gt; &lt;td align="right" width="160"&gt;Choose an Item:&lt;/td&gt; &lt;td align="left"&gt; &lt;select name="formItem" value="&lt;?=$varItem;?&gt;" class="input_full" &gt; &lt;option value="1"&gt;Cheese&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr bgcolor="#D0E8F5"&gt; &lt;td align="right" &gt;Item count:&lt;/td&gt; &lt;td align="left"&gt; &lt;input type="text" name="formItemCount" maxlength="50" value="&lt;?=$varItemCount = 1;?&gt;" class="input_full" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;p align="center"&gt; &lt;input type="submit" name="formSubmit" align = "center" value="Submit" /&gt; &lt;/p&gt; &lt;/form&gt;&lt;/body&gt;&lt;/html&gt; </code></pre> <p><strong>"php-form-processor.php" contents</strong></p> <pre><code>&lt;?php if($_POST['formSubmit'] == "Submit") { $varItem = $_POST['formItem']; $varItemCount = $_POST['formItemCount']; //database stuff $username = "..."; $password = "..."; $hostname = "..."; // connect and add to the database varItem and varItemCount mysql_query($sql); mysql_close($dbhandle); } ?&gt; </code></pre> <p>The form is much bigger but i've simplified the stackoverflow's version of it. The price of an order must change according to "varItem" and "varItemCount" value. Basically I want to add "Pay with PayPal" option before writing an order into the database. P.S. I've already registered paypal Sandbox account and added "Buyer" and a "Seller". </p> <p>what should I do next?</p> <p><strong>EDIT: ok, so here is a small guide how to solve the problem.</strong> Here are some advises:</p> <ul> <li>first, download paypal IPN listener wrapper: <a href="https://github.com/Quixotix/PHP-PayPal-IPN" rel="nofollow">https://github.com/Quixotix/PHP-PayPal-IPN</a></li> <li>then register SandBox account plus 1 buyer and 1 seller acc</li> <li>login as a seller and create a form (with non-hosted button!)</li> <li>place the form into your page and parse the ID or any other necessary information via "custom" input (some helpful advises can be found here: <a href="http://www.devshed.com/c/a/PHP/Creating-a-Paypal-IPN-System-in-PHP-Part-Two/" rel="nofollow">http://www.devshed.com/c/a/PHP/Creating-a-Paypal-IPN-System-in-PHP-Part-Two/</a>)</li> <li>now place redirect to this page after Form submit</li> <li>don't forget to enable IPN at paypal Seller account and enter IPNlistener link into a necessary address field</li> <li>submit a paypal form and wait for response on listener</li> <li>done</li> </ul> <p>Whole proccess looks like this:</p> <ol> <li>customer fills up the form</li> <li>after submitting the form - all entries are written into the database + ID + 1 additional field called "payed" which represents: 1 - if customer payed for an order and 0 - if not</li> <li>use header("Location: URL") to redirect from Form_Processing to Paypal_Form</li> <li>use the "session" to write order ID into a session or use POST message</li> <li>submit the PaypalForm and use "custom" field as a carier for our order ID</li> <li>set up the listener to update the database as following: if transaction was successful -> update the database column "payed" to 1 (done). Use the ID from "custom" field to select needed order i.e.:</li> </ol> <p>$sql = "UPDATE paypal_test SET payed = '1' WHERE id = '".$_POST['custom']."'";</p> <p>Now we have a database with completed and non-completed forms. Additionaly you can write a logic which will remove "old" uncompleted orders. For this reason you can create additional column called "date" and then compare: if (current_date.days - old_date.days > 7) -> remove from DB. That's it!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload