Jump to content
Larry Ullman's Book Forums

airbrushtutor

Members
  • Posts

    9
  • Joined

  • Last visited

airbrushtutor's Achievements

Newbie

Newbie (1/14)

1

Reputation

  1. Added this code after the if (isset($_POST['payment_status'])) closing bracket: else { // the POST conditions failed $ps = $_POST['payment_status']; $re = $_POST['receiver_email']; $mcgross = $_POST['mc_gross']; $mccurr = $_POST['mc_currency']; $txn_id = $_POST['txn_id']; fwrite($file, "-----------------------------------\n"); fwrite($file, "DEBUG - the post variables failed. Print them here:\n"); fwrite($file, $ps . "\n" . $re . "\n" . $mcgross . "\n" . $mccurr . "\n" . $txn_id . "\n"); fwrite($file, "Currency constant: " . CURRENCY . "\n"); fwrite($file, "contact email: " . $contact_email . "\n"); fwrite($file, "test item: " . $test_item . "\n"); fwrite($file, "-----------------------------------"); } This allowed me to see that the POST conditional was failing. I had three errors: 2nd - I hadn't uploaded the latest local version of all files to the server - so when the post failed I could see that the constant for CURRENCY was just the string CURRENCY - so i uploaded the latest config file and the query went through. This script is working correctly now - and it is updating the SQL orders table successfully. I've added a bit of simple information to the txt file - just so it prints the SQL INSERT statement so i can see what's going on there aswell. all good now - hope this helps someone!
  2. Hi guys - having trouble with the IPN script. have been working on it for about 2 days and have searched the forum but i've come to a dead end. My script is almost exactly the same as the book - all of the file writing is the same, problem i'm having is that it's not adding the order to the DB.. here's my PHP: // This script needs to respond to paypal's IPN to confirm the IPN and update the database. require('includes/config.inc.php'); /******************************************* // Test item to set a price for the script to check. - cost of Dru Blair course - change this before upload. CURRENCY set in config.inc.php $contact_email set in config.inc.php as mitchl@airbrushtutor.com. delete below on successful test. ********************************************/ $contact_email = 'mitchl-facilitator@airbrushtutor.com'; $test_item = 1799.00; // Open a text file - the text file must be writable by PHP! $file = fopen('../ipn.txt', 'a'); // Write the POST data to the file: fwrite($file, "Received:\n"); fwrite($file, print_r($_POST, true)); fwrite($file, "\n"); // Append command validate to the beggining of the response URL to paypal $req = 'cmd=_notify-validate'; // Add each received key=value pair to the request foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // Open a socket connection to PayPal. // If connection failed then trigger error if (!$fp) { trigger_error('Could not connect for the IPN!'); } else { // The connection was successful so send the request/ confirmation to paypal $header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Host: www.sandbox.paypal.com\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; fputs($fp, $header . $req); // Write the PayPal request to the text file: fwrite($file, "Sent:\n"); fwrite($file, "$header\n"); fwrite($file, "$req\n"); // Read in the response while (!feof($fp)) { $response = fgets($fp, 1024); // Write the PayPal response to the text file: fwrite($file, "Received:\n"); fwrite($file, "$response\n"); // if the response is verified, then process the response if (strcmp ($response, "VERIFIED") == 0) { // Check for the values posted from Paypal if (isset($_POST['payment_status']) && ($_POST['payment_status'] == 'Completed') && ($_POST['receiver_email'] == $contact_email) && ($_POST['mc_gross'] == $test_item) && ($_POST['mc_currency'] == CURRENCY) && (!empty($_POST['txn_id']))) { // Check for the transaction in the database - in case this is a repeat order. require(MYSQL); $txn_id = mysqli_real_escape_string($dbc, $_POST['txn_id']); $query = "SELECT id FROM orders WHERE transaction_id='$txn_id'"; $result = mysqli_query($dbc, $query); if (mysqli_num_rows($result) == 0) { // The transaction hasn't taken place already so move forward $uid = (isset($_POST['custom'])) ? (int)$_POST['custom'] : 0; $status = mysqli_real_escape_string($dbc, $_POST['payment_status']); $amount = (float)$_POST['mc_gross']; $product_id = (isset($_POST['prod_id'])) ? (int)$_POST['prod_id'] : 0; $query = "INSERT INTO orders (user_id, transaction_id, payment_status, payment_amount, product_id) VALUES ($uid, '$txn_id', '$status', $amount, $product_id)"; $result = mysqli_query($dbc, $query); } // mysqli_num_rows($result) else { // There was a problem inserting the data $err_msg = 'Couldn\'t insert the data to the database?\n'; $err_msg .= $response; trigger_error($err_msg); } } // if isset payment status } // if strcmp($response, "VERIFIED"); elseif (strcmp($response, "UNVERIFIED") == 0) { $err_msg1 = 'The response from paypal was unverified.'; $err_msg1 .= $response; trigger_error($err_msg1); //require an error log to communicate with paypal } } // while feof(); fclose($fp); } // if ($fp); // Inidicate the end of this transaction in the text file: fwrite($file, "--------------\n"); fclose($file); And here's the response we're printing.. Received: Array ( [mc_gross] => 1799.00 [protection_eligibility] => Ineligible [payer_id] => 922YH4PA9T7YE [tax] => 0.00 [payment_date] => 03:20:23 Jul 12, 2013 PDT [payment_status] => Completed [charset] => windows-1252 [first_name] => Sean [mc_fee] => 52.47 [notify_version] => 3.7 [custom] => 5000 [payer_status] => verified [business] => mitchl-facilitator@airbrushtutor.com [quantity] => 1 [verify_sign] => ACtqhM7JEDsuNzaiyzdEn6QdfOeaAlk0RD3wQcEKNrTTKnrBwGTiA.GH [payer_email] => mastercard@airbrushtutor.com [txn_id] => 8D649478MW552273Y [payment_type] => instant [btn_id] => 2793904 [last_name] => Seaman [receiver_email] => mitchl-facilitator@airbrushtutor.com [payment_fee] => 52.47 [shipping_discount] => 0.00 [insurance_amount] => 0.00 [receiver_id] => SEWT5HDKJVNLE [txn_type] => web_accept [item_name] => Dru Blair Portrait 2 [discount] => 0.00 [mc_currency] => USD [item_number] => 8 [residence_country] => US [test_ipn] => 1 [handling_amount] => 0.00 [shipping_method] => Default [transaction_subject] => 5000 [payment_gross] => 1799.00 [shipping] => 0.00 [ipn_track_id] => 6ca82ff4dac16 ) Sent: POST /cgi-bin/webscr HTTP/1.0 Host: www.sandbox.paypal.com Content-Type: application/x-www-form-urlencoded Content-Length: 928 cmd=_notify-validate&mc_gross=1799.00&protection_eligibility=Ineligible&payer_id=922YH4PA9T7YE&tax=0.00&payment_date=03%3A20%3A23+Jul+12%2C+2013+PDT&payment_status=Completed&charset=windows-1252&first_name=Sean&mc_fee=52.47&notify_version=3.7&custom=5000&payer_status=verified&business=mitchl-facilitator%40airbrushtutor.com&quantity=1&verify_sign=ACtqhM7JEDsuNzaiyzdEn6QdfOeaAlk0RD3wQcEKNrTTKnrBwGTiA.GH&payer_email=mastercard%40airbrushtutor.com&txn_id=8D649478MW552273Y&payment_type=instant&btn_id=2793904&last_name=Seaman&receiver_email=mitchl-facilitator%40airbrushtutor.com&payment_fee=52.47&shipping_discount=0.00&insurance_amount=0.00&receiver_id=SEWT5HDKJVNLE&txn_type=web_accept&item_name=Dru+Blair+Portrait+2&discount=0.00&mc_currency=USD&item_number=8&residence_country=US&test_ipn=1&handling_amount=0.00&shipping_method=Default&transaction_subject=5000&payment_gross=1799.00&shipping=0.00&ipn_track_id=6ca82ff4dac16 Received: HTTP/1.1 200 OK Received: Date: Fri, 12 Jul 2013 10:20:29 GMT Received: Server: Apache Received: X-Frame-Options: SAMEORIGIN Received: Set-Cookie: c9MWDuvPtT9GIMyPc3jwol1VSlO=f2OfwB8GwOiWiUWvKnQyQ3ZH8gsM6GPmLgUhoJYvPM59gbb9NKy4E8gO2l9aG9PBFz3FFHLN4jPEqxU3gvGMRjV2GixklFEXo-8nwRPNxCgdS_k2MtjfeAQxv1prTa1tMkwA1W%7cpd56RwTeJP9KYj2t4igaX2ZV6ckVUcZ_sLbmIyEng4DCfF5FRYGI2-DvbiDscHY1s2GWwW%7cgRV0QHM3y5s3kVYjzfgRpDTdawpJ8CkuCVw77ph6dKZKMaaB91WLDGQMyWG5Xe-5UtEox0%7c1373624429; domain=.paypal.com; path=/; Secure; HttpOnly Received: Set-Cookie: cookie_check=yes; expires=Mon, 10-Jul-2023 10:20:29 GMT; domain=.paypal.com; path=/; Secure; HttpOnly Received: Set-Cookie: navcmd=_notify-validate; domain=.paypal.com; path=/; Secure; HttpOnly Received: Set-Cookie: navlns=0.0; expires=Thu, 07-Jul-2033 10:20:29 GMT; domain=.paypal.com; path=/; Secure; HttpOnly Received: Set-Cookie: Apache=10.72.109.11.1373624429227530; path=/; expires=Sun, 05-Jul-43 10:20:29 GMT Received: Connection: close Received: Content-Type: text/html; charset=UTF-8 Received: Received: VERIFIED --------------Can't work it out - i'm just going through the debug motions and writing the SQL query to the text file to see what that's printing.. If you can offer any help would be appreciated - otherwise i'll post when i find the solution. any help appreciated.
  3. The problem still persists - however there is a workaround. The problem i get is when trying to create a sandbox button by clicking on the jpeg to create a button, it would redirect to the regular paypal and ask you to sign in. However on the right hand side of the page is a sidebar where there is a link to 'edit buttons' - looks like the same function but this in fact shows there are three default buttons in the sand box, from there you can edit them and access your script. Also make sure you clear paypal cookies/ cache from your browser as this can cause trouble. What a pain in the butt.
  4. Is there another place we could look for an updated version of the paypal side of things? I can't get sandbox to work - i mean i've gone in and created three test accounts - that's all good. i can type the url into the address bar and the sandbox site is displayed, when i log in with the fake merchant account it takes me to the faux 'paypal' sandbox site. All good, so i click on the merchant tools button and there is the option to create a paypal button. Click that and it redirects to the regular paypal and asks you to sign in. the fake account no longer works and you simply have to create a real button if you can even get paypal to load the user friendly version of their site. I've been at this all day and it just doesn't work full stop. I don't think i'll find any solutions, just wanted to let others know i've had this problem, maybe you are also? if there is an update to this anywhere that i haven't seen would be appreciated if you could let me know
  5. There's a few questions that would have to be answered for clarification - but if you have turned on the mod_rewrite feature and you're rewriting your URLS then you will likely get problems like this. The trick i used to get around it on my own website is a html tag that goes within the <head> tag of your html markup called <base href="www.yourdomain.com">. That's assuming this was a problem due to apache's mod_rewrite. Your browser looks for the CSS and image files based on what is shown in the url, however as long as you set this tag then it creates a base directory for the browser to look at for all links on the page. I'm no developer, but this is my basic understanding and fixed my similar problem.
  6. Just wondering if there's an errata section or a 'log' of code changes that we can refer to for this book? Just hovering around page 95 and writing the registration script, i've found changes to the online code and wondering if this is documented anywhere for quick reference? If not, i can just do some research instead of bugging anyone with questions. Does such a section exist? thanks:)
  7. Perfect:) thanks for that Larry! I'll continue on and see what more i can keep learning:) cheers mate!
  8. Hi guys and girls, have just started the book and come to my first question regarding some MySQL syntax - in relation to the 'KEY' index. I understand what PRIMARY and UNIQUE keys are, however this is the first time i've come across the lone "KEY date_created (date_created)" syntax such as the code on page 51. I also noticed it doesn't have to match i.e. 'KEY date_created (creation_date)'? I've done quite a few searches on the net and even this forum but can't seem to find the answers or even hints.. normally for PHP i'd use the manual however the SQL manual doesn't seem to be anywhere near as friendly and all searches just bring up explanations of the UNIQUE or PRIMARY key syntax. Was hoping someone could point me in the direction of where to find out about this syntax? Probably would be best if you could guide me to something as helpful as the PHP manual but for MySQL? when i search the MySQL site i get results returning to me in Chinese, which isn't my strongest language:) thanks in advance for the guidance!
×
×
  • Create New...