PHP - Anybody Worked With Authorize.net's Api?
I'm looking to build my own ecommerce site and i just looked at their sample code to test transactions. See below.
Code: [Select] <?php require_once 'anet_php_sdk/AuthorizeNet.php'; // Make sure this path is correct. $transaction = new AuthorizeNetAIM('YOUR_API_LOGIN_ID', 'YOUR_TRANSACTION_KEY'); $transaction->amount = '9.99'; $transaction->card_num = '4007000000027'; $transaction->exp_date = '10/16'; $response = $transaction->authorizeAndCapture(); if ($response->approved) { echo "<h1>Success! The test credit card has been charged!</h1>"; echo "Transaction ID: " . $response->transaction_id; } else { echo $response->error_message; } ?> I was under the impression handling credit cards was MUCH harder to deal with. Couldn't you just store the $_POST['creditcardnumber'] in a database(not very secure AT ALL)? I would of thought they would have to make you mess with the form submission so their card number is encrpted through the $_POST and Authorize.net is the only one that has the decryption key. Also, doesn't like EVERY credit card processing form require the name on the card? Am i missing something?? Similar TutorialsI've hit a six-foot-thick brick wall and have no idea what to do. Trying to integrate for payments and this is a scary new realm for me Hopefully somebody here can help me figure this out, as I'm a complete and utter newbie on shopping carts etc. Authorize.net has been no help, and they say "we have no developers" on staff to answer questions. I'm getting an error 13 and nothing gets around it. The basic result is that an error 13 occurs when the API id and transaction key are incorrect (but they are) or if the 'gateway URL' is incorrect. I've checked and it is. But they also say its in the in the cURL section of the code and if this is wrong, it could generate the error. No idea where that's supposed to be. did a search. Question: To install, test, etc, it looks like I need something called cURL extensions and SimpleXML enabled. I don't know if this is, and the client's hosting company has not gotten back to me (hosted out of country, too). I looked for a php.ini file, and see nothing. Is it safe/possible to put my own php.ini file on the html_public folder? If so, how do I set up the cURL and SimpleXML extensions? (Assuming this is even contributing to the problem) And any help beyond this is greatly appreciated, if you've worked with authorize.net integration. I'm working with classes and don't know much about them. It's pulling data from authorize.net when a transaction is run. Maybe this is a general thing someone can help with? I include an AIM.class.php file in the page that process the transaction, 'registration4.php'. In the AIM.class.php I have this code that does print the transaction id to the page. The variable $pstr_trimmed looks like it gets used over and over for each 'case' : Code: [Select] case 7: echo "Transaction ID: "; echo $pstr_trimmed; /* thought I could just add $trans_id_variable = $pstr_trimmed; (didn't work */ break; But I don't know how to use that to type echo "$trans_id_variable" on register4.php or to insert it into my database? Code: [Select] <?php require("AIM2.class.php"); // here the data is set and the card processed, then... if (!$approval = $aim->processCard("Workshops", $final_total)){ echo "<strong>Oops!</strong><br>Error proccessing credit card: " . print_r($aim->errorStack,1); $appcodedesc = "Error processing credit card."; $approval = 0; }else{ // If we made it this far, the card was successfully charged // here the code echoes "Transaction ID: 1111111 Payment Approved" echo "<strong><h3>Payment Approved</h3></strong><br>Successfully charged the credit card. Add the attendee(s) name(s) below and submit. On the next page, you can print for your records. Please note that these are secure pages for payment processing, and pressing the back button in your browser, will bring up an expired page<br><br>"; // Approval code: " . $approval; //echo $pstr_trimmed; echo "and the new variable?"; // but here's where I was hoping to take that transaction id and set it as a variable to put into the database. echo $trans_id_test; echo" should be before this"; $approval = 1; $appcodedesc = "Payment Approved"; Hi All. I'm a web page noob that cobbled some HTML and PHP together to create a web interface for some Raspberry Pi s used for monitoring and control around the house. The pages have worked fine a few years but I have encountered an issue since upgrading one of the RPi s to the latest software. In this instance one Pi (named RPi2) has a LAMP server and one page on that server interacts with a database on another Pi (named RPi3) that has a relay drive for hot water heating power. The web page basically allows the user to check/uncheck power to hot water and writes a new line to the database when ever there is a change. A python script reacts to change in database value to switch a relay. When I updated the software on RPi3 with Buster/PHP 7 the page on RPi2 addressing the database on RPi3 stop functioning.
In my pursuit of a resolution I tried directing the webpage to a db table on the localhost (RPi2) which still has PHP 5 and it worked as expected. I created a clean LAMP install for a test with PHP 7 and tested the page with a local db table and it does not function correctly. I'm thinking there is an issue with variable type assignment between PHP and the database but I really don't know. I inserted a Var_Dump() line as a debugging measure and get a result of string(1) "1" but the usual results of Var_Dump() I see on PHP help sites do not have a character in parenthesis, maybe unrelated to my problem.
The page is simple checkbox with update button that should show last/current state value "onoff", stored as 0 or 1 in db table, anytime the update button it pressed then a new line is written to db table with value of "onoff" reflecting checkbox checked or unchecked. The problem is database is not reliably updated and regardless of value in database the page always refreshes to have the checkbox checked, even if the checkbox is unchecked and update is hit the checkbox becomes checked.
The two relevant pages of code are below This is hws.php <!DOCTYPE html> <html> <title>HWS Control</title> <link rel="icon" href="home-button.png"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="w3.css"> <body> <nav class="w3-sidenav w3-collapse w3-white w3-card-2 w3-animate-left" style="width:200px;" id="nav01"> <a href="javascript:void(0)" onclick="w3_close()" class="w3-closenav w3-large w3-hide-large">Close ×</a> <a class="w3-xlarge" href="index.php">Home</a> <a class="w3-xlarge" href="active.php">Zone Control</a> <a class="w3-xlarge" href="actions.php">Monitor Actions</a> <a class="w3-xlarge" href="table_mon.php">Monitor Log</a> <a class="w3-xlarge" href="table_temp.php">Hotwater</a> </nav> <div class="w3-main" style="margin-left:200px"> <header class="w3-container w3-teal"> <span class="w3-opennav w3-xlarge w3-hide-large" onclick="w3_open()">☰</span> <h2>HWS Power</h2> </header> <div class="w3-container"> <?php $servername = "192.168.0.34"; $username = "xxxxxxxx"; $password = "xxxxxxx"; $dbname = "Temp"; $conn = mysqli_connect($servername, $username, $password, $dbname); if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } $thesql = "SELECT onoff FROM state ORDER BY id DESC LIMIT 1"; $result = mysqli_query($conn, $thesql) or die(mysqli_error($conn)); $row_result = mysqli_fetch_assoc($result); $onoff = $row_result['onoff']; mysqli_close($conn); ?> <form action="hwsupdate.php" method="post" class="w3-container w3-card-4"> <p> <input type="checkbox" class="w3-check" checked="checked" id="onoff" name= "onoff1" value="1"> <label class="w3-validate"> HWS Power</label> </p> <script> document.getElementById("onoff").checked = <?php echo $onoff?>; </script> <input type="submit" value="Update" class="w3-btn w3-round-xxlarge" > <h3></h3> </form> </div> <footer class="w3-container w3-teal"id="foot01" > </footer> </div><script> function w3_open() { document.getElementById("nav01").style.display = "block"; } function w3_close() { document.getElementById("nav01").style.display = "none"; } </script> <script src="ge.js"></script> </body> </html>
and this is hwsupdate.php <?php $servername = "192.168.0.34"; $username = "xxxxxx"; $password = "xxxxxxxxx"; $dbname = "Temp"; $conn = mysqli_connect($servername, $username, $password, $dbname); if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } $onoff = $_POST['onoff1']; $sql="INSERT INTO state (onoff) VALUES ('$onoff')"; if (mysqli_query($conn, $sql)) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); } mysqli_close($conn); header("Location: hws.php"); ?>
Any guidance to resolution would be greatly appreciated. <?php include("classes/DomDocumentParser.php"); //this could be the problem it appears in the error file $alreadyCrawled() = array(); $crawling = array(); $startUrl = "https://imagimedia.co.za"; //Get variable from input $hnam = str_replace("http://", "", "$startUrl"); $hnam = str_replace("https://", "", "$hnam"); $hnam = str_replace("www.", "", "$hnam"); $hnam = substr($hnam, 0, -6); function createLink($src, $url) { $scheme = parse_url($url)["scheme"]; $host = parse_url($url)["host"]; if(substr($src, 0, 2) == "//") { $src = $scheme.":".$src; } else if(substr($src, 0, 1) == "/") { $src = $scheme."://".$host.$src; } else if(substr($src, 0, 2) == "./") { $src = $scheme."://".$host.dirname(parse_url($url)["path"]).substr($src, 1); } else if(substr($src, 0, 3) == "../") { $src = $scheme."://".$host."/".substr($src, 3); } else if (substr($src, 0, 4) != "http") { $src = $scheme."://".$host."/".$src; } return $src; } function followLinks($url) { global $hnam; global $alreadyCrawled; global $crawling; $parser = new DomDocumentParser($url); $linkList = $parser->getLinks(); foreach($linkList as $link) { $href = $link->getAttribute("href"); if(strpos($href, "#") !== false) { continue; } else if(substr($href, 0, 11) == "javascript:") { continue; } $href = createLink($href, $url); if(strpos($href, "$hnam") == false) { continue; } //this could be the problem if(!in_array($href, $alreadyCrawled)) { $alreadyCrawled[] = $href; $crawling[] = $href; //insert $href } echo $href."<br />"; } array_shift($crawling); foreach($crawling as $site) { followLinks($site); } } followLinks($startUrl); ?> include file <?php class DomDocumentParser { private $doc; public function __construct($url) { $options = array( 'http'=>array('method'=>"GET", 'header'=>"User-Agent: imagimediaBot/0.1\n") ); $context = stream_context_create($options); $this->doc = new DomDocument(); @$this->doc->loadHTML(file_get_contents($url, false, $context)); } public function getLinks() { return $this->doc->getElementsByTagName("a"); } } ?> Edited December 19, 2020 by guymclarenza added include file I am making a time clock, and I was wondering what is the best way to calculate the number of hours an employee worked? I have a table called "statuses" it holds names of punch types: - id = the auto_inc - status = "in/out/break/lunch" text statuses - paid = whether or not the punch is paid or not (true/false) I have another table called "logging" This table holds the information about the punch type: - id = the auto_inc - owner = the member id - ip = members ip - inout = the punch type from the statuses table - location = the city/state of where the punch took place - date = the time the member punched Maybe I am over thinking this, but what is the best way to calculate the hours a person has worked? Right now I am getting all the punches for for a particular member between a date range. then loop through the data to display it and passing it to a method in a class called Calc. I want to then add the times from punch in to punch out, then the next punch in to punch out. Any suggestions? |