craigtolputt Posted March 5, 2010 Share Posted March 5, 2010 Hi Guys, I have been going mad with this one and not sure if its even possible but here goes. I have a form with some input fields and once the user has filled in their name etc it then gives them a total cost based on how many people they have selected from a dropdown. Then they click confirm and pay and it sends them to paypal and lets them pay. But at the same time i need the inputted data saved to a database. I have all the script necessary to do both actions but cant get them working together??? does anyone know how i can submit the data to both destinations?? cheers Craig Quote Link to comment https://forums.phpfreaks.com/topic/194225-submitting-form-data-to-paypal-and-saving-it-to-a-db/ Share on other sites More sharing options...
PravinS Posted March 5, 2010 Share Posted March 5, 2010 There are few options 1) You can save data bafore sending it to paypal and can have a flag. When payment is done and customer is redirected to site you can check payment status flag from paypal, if it is "Success" then you can update your database flag as done or something. 2) You can have data in session, then after successful payment database can be updated. Quote Link to comment https://forums.phpfreaks.com/topic/194225-submitting-form-data-to-paypal-and-saving-it-to-a-db/#findComment-1021854 Share on other sites More sharing options...
craigtolputt Posted March 5, 2010 Author Share Posted March 5, 2010 Thanks, I think what i want is to have the data saved first with a status of complete = 0 then once the payment is successful then it updates the database status complete = 1. Shall i post the code that i am using here so that you can see what i have? thanks again craig Quote Link to comment https://forums.phpfreaks.com/topic/194225-submitting-form-data-to-paypal-and-saving-it-to-a-db/#findComment-1021943 Share on other sites More sharing options...
craigtolputt Posted March 5, 2010 Author Share Posted March 5, 2010 Heres the code i use <?php //include the connect script include "connect.php"; $name_attendee_1 = $_POST{"name_attendee_1"}; mysql_query("INSERT INTO info (id, name1, complete) VALUES ('','".$name_attendee_1."','0')"); mysql_close($conn) ?> <?php define('PayPalAddress','info@mydomain.com'); define('ProductPath','receipt.pdf'); define('ProductDescription','The Phoenix Lunch Group Reservation'); define('ProductPrice','23.95'); define('ProductDownloadExpire','0'); define('OrderFormURL','http://www.mydomain.com/index.php'); define('OrderFormURLCancel','mydomain.com'); $SandBox = 'sandbox.'; // uncomment this line to get sandbox/test mode # Optional settings for email. define('emailFrom','mydomain.com'); define('emailSubject','Thank you! Your Place has been Reserved.'); define('emailMessage',"Thank you! You can download your receipt here: [DOWNLOAD] --- Please don't hesistate to contact us with any additional questions! "); if(!$_POST && !$_GET['download']){ // this is the order form. // if there was any post here - it's probably call from PayPal. ?> <!--*****************************************************RETURN CONTENT*****************************************************--> <? if($_GET['status']) { ?> <div id="PayPalOrder-Main" align="center"> <h1>Order Complete!</h1> <div id="PayPalOrder-Product"> <h2>Your order is now complete<br />Please check your mailbox! (SPAM folder too)</h2> </div> </div> <? } else { ?> <!--*****************************************************RETURN CONTENT*****************************************************--> <!--*****************************************************FORM***************************************************************--> <form name="form" action="https://www.<?php echo $SandBox;?>paypal.com/cgi-bin/webscr" method="post" target="_top"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="<?=PayPalAddress?>"> <input type="hidden" name="item_name" value="<?=ProductDescription?>"> <input type="hidden" name="return" value="<?=OrderFormURL?>"> <input type="hidden" name="cancel_return" value="<?=OrderFormURLCancel?>"> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="lc" value="US"> <input type="hidden" name="bn" value="PP-BuyNowBF"> <input type="hidden" name="notify_url" value="<?=OrderFormURL?>"> <!--*****************************************************FORM***************************************************************--> <!--*****************************************************COLUMN THREE*******************************************************--> <div class="col3" > <div id="tick-3"></div> <div class="top"><p class="step">Step 3</legend> </div> <div class="middle3"> <fieldset id="step_3"> <p style="font-size:17px; width:293px; margin-bottom:15px;">You have selected <input type="text" id="attending" class="attending" name="attending" readonly="true"/> Guests.</p> <div id="nobox"> <p style="font-size:17px; width:293px; margin-bottom:15px;">You have selected <span style="color:#ac1f1f">No</span> special requirements for this event.</p> </div> <div id="yesbox"> <p style="font-size:17px; width:293px; margin-bottom:15px;">You have selected <span style="color:#ac1f1f">Special Requirements</span> for this event.</p> </div> <p style="font-size:17px; width:280px; margin-bottom:15px;">Total cost <span style="color:#ac1f1f;font-family: Georgia, serif;font-style: italic;font-size: 20px;top:-10px;font-weight:bolder;">£</span><input type="text" id="ProductPrice" name="amount" class="ProductPrice" readonly="true"/>.</p> <p style="font-size:17px; width:280px; margin-bottom:15px;">We look forward to seeing you on <span style="color:#ac1f1f">Thursday 29th April</span>.</p> <label for="rock" style="font-size:17px; width:240px;">Please tick the box to confirm.</label><input type="checkbox" id="rock" class="styled"> </input> </fieldset> </div> <div class="botmid"></div> <div class="bottom" align="center"><input type="submit" id="payNowSubmit" class="payBtn"></div> </div> <!--*****************************************************COLUMN THREE*******************************************************--> </form> </div> <? } ?> </body> </html> <? } elseif($_GET['download']) { // first - please check, if that file didn't expire... if(constant('ProductDownloadExpire')>0){ // there is some expiration date. $fstat=stat('download/'.addslashes($_GET['download'])); // print_r($fstat); // this would show all info we have. // how much need to add? // need to calculate number of seconds, so in 1 day, there is 24 hours, // in hour there is 60 minutes and there is 60 seconds in a minute. $allowedTime=ProductDownloadExpire*24*60*60; // add these values, to have maximum allowed file time: $allowedTime = $allowedTime+$fstat['mtime']; // now - if allowed time is exceeded - less than current time, // file will be not sent to user. if($allowedTime<time()){ die('File Expired!'); exit; } } if(file_exists('download/'.addslashes($_GET['download']))){ header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Type: $ctype"); // change, added quotes to allow spaces in filenames, by Rajkumar Singh header("Content-Disposition: attachment; filename=\"".basename(ProductPath)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize('download/'.addslashes($_GET['download']))); readfile('download/'.addslashes($_GET['download'])); exit(); } else { die("File doesn't exists!"); } } else { // there is POST sent, probably this is PayPal verification... $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; // send verification request to PayPal... $fp = fsockopen('www.'.$SandBox.'paypal.com', 80, $errno, $errstr, 30); if (!$fp) { // no result? Probably some error... die('Problem with connection to PayPal, is "fsockopen" allowed?'); } else { // there was connection... fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp($res, "VERIFIED") == 0) { if($_POST['payment_status'] == 'Completed' || $_POST['payment_status'] == 'Pending'){ if($_POST['mc_currency'] == 'GBP'){ // price is good, currency is good. We can complete this order... // wasn't order completed? if(file_exists('download/tkey_'.$_POST['txn_id'].'.txt')){ header("location: ".OrderFormURL."?status=complete"); exit; } // done? Add file with transaction ID, so it can't be generated again // - example by page refresh, etc $f = fopen('download/tkey_'.$_POST['txn_id'].'.txt', 'w'); fwrite($f, 'ok'); fclose($f); /* POST variables which are sent from PayPal: $_POST['item_name'] - name of our product $_POST['payment_status'] - status of payment $_POST['mc_gross'] - total amount sent by customer $_POST['mc_currency'] - currency - example GBP $_POST['txn_id'] - transaction ID $_POST['payer_email'] - customer's email, which was used to pay for this order */ // create download link for this user. $UniqueId=md5(microtime()); $DownloadLink=OrderFormURL."?download=".$UniqueId; if(!copy('download/'.ProductPath,'download/'.$UniqueId)) die('Problem when creating unique copy, is copy() function allowed?'); // we will send an email to customer now if(mail($_POST['payer_email'],emailSubject,str_replace('[DOWNLOAD]',$DownloadLink,emailMessage),'From: '.emailFrom.' <'.PayPalAddress.'>')){ // done? Add file with transaction ID, so it can't be generated again // - example by page refresh, etc $f = fopen('download/tkey_'.$_POST['txn_id'].'.txt', 'w'); fwrite($f, 'ok'); fclose($f); header("location: ".OrderFormURL."?status=complete"); } else { die("Problem when sending an email..."); } } } } elseif (strcmp ($res, "INVALID") == 0) { // some problems. Skip it. } } // endof WHILE fclose ($fp); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/194225-submitting-form-data-to-paypal-and-saving-it-to-a-db/#findComment-1021950 Share on other sites More sharing options...
craigtolputt Posted March 10, 2010 Author Share Posted March 10, 2010 Does any one here know how i can get this form to save the data and submit it to paypal its driving me mad. Please if you do know i would really love to learn how this is done. thanks Craig Quote Link to comment https://forums.phpfreaks.com/topic/194225-submitting-form-data-to-paypal-and-saving-it-to-a-db/#findComment-1024313 Share on other sites More sharing options...
hcdarkmage Posted March 10, 2010 Share Posted March 10, 2010 You can get the API information from https://www.x.com/docs/DOC-1374. These should help you create the Paypal API for submitting the information you need. They used to have documentation to go with it, but I don't remember where to find it. Quote Link to comment https://forums.phpfreaks.com/topic/194225-submitting-form-data-to-paypal-and-saving-it-to-a-db/#findComment-1024316 Share on other sites More sharing options...
aeroswat Posted March 10, 2010 Share Posted March 10, 2010 You can get the API information from https://www.x.com/docs/DOC-1374. These should help you create the Paypal API for submitting the information you need. They used to have documentation to go with it, but I don't remember where to find it. From what I understand, when I used to develop an online store, you have to pay a fee to use the paypal API Quote Link to comment https://forums.phpfreaks.com/topic/194225-submitting-form-data-to-paypal-and-saving-it-to-a-db/#findComment-1024317 Share on other sites More sharing options...
hcdarkmage Posted March 10, 2010 Share Posted March 10, 2010 From what I understand, when I used to develop an online store, you have to pay a fee to use the paypal API When I was creating APIs for working with PayPal, I never had to pay any fees. I have never had that problem. I know that a fee is taken when you GET money through PayPal, like a paycheck, but I never had to pay a fee to use the API. Quote Link to comment https://forums.phpfreaks.com/topic/194225-submitting-form-data-to-paypal-and-saving-it-to-a-db/#findComment-1024319 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.