PHP - Moved: Google Checkout Response Check
This topic has been moved to Other Libraries and Frameworks.
http://www.phpfreaks.com/forums/index.php?topic=306254.0 Similar Tutorialshi, I'm integrating google checkout on my website using php. anyone have any idea if google checkout take payment on website just like paypal payment pro??? Looking forward. Best regards Hi, I was wondering if someone can help. I am trying to implement a server to server Google checkout system on my website. I have built my own custom shopping basket which meets my needs however I need to get my data in the correct format to send off for the payment to be taken by Google checkout. At present I have a sql table called basket which stores all of the items that a user adds to thier basket. The google checkout examle requires the data in the below format: Code: [Select] $item_1 = new GoogleItem("product name ", // Item name "With S/N", // Item description $total_count, // Quantity 10.99); // Unit price $item_1->SetURLDigitalContent('http://example.com/download.php?id=15', 'S/N: 123.123123-3213', "Download Item1"); $cart->AddItem($item_1); The above code is obviously for just the one item. Is it best to store the basket in a sql database and if so how would I go about retrieving the information from the database and then sending it to google in the above format bearing in mind there can be multiple items in the cart? Thanks in advance Edd Hi, Firstly, apologies if this is in the wrong place in the forum to post this. I have a website, I use PHP in various places to pull/push info from/to a mySQL database, i'm fairly happy with PHP and its uses. I've recently started to use the Google checkout widget on the site for a proposed webstore (to go live at a later date), this has the ability to 'sell' download URL's or keys. I like the idea of a customer being able to purchase multiple MP3 downloads and them being given a URL that gives them the links for the MP3's selected. This is probably beyond anything i've ever done with PHP though so I need to understand the architecture........I understand that, given a list of items from the store, I can run a query to display a list of stored URL's for those items - and I'm sure I can find code that will give me a random URL that will 'expire' after an amount of time. My question is, how to get the list of items ordered from the google checkout?? I'm sure this has something to do with API's - but I don't know what they are, presumably there is some kind of table in Google that I can tap into to get the product info?? any help would be very much appreciated. ....oh, and i'm sure people are going to ask "why are you using Google checkout", the answer being, for me, it seems simple, effective and free! (but i'm open to suggestions.) Darren Why am I getting that error on Google reCAPTCHA V2 response? Hello, it's my first time posting here and I'm not good with such stuff as the one I'm posting right now I have been trying to solve this issue for 2 days by now so I could use some help lol This error "Please solve the captcha." is showing even if the captcha is verified so it's showing in the both cases (verified/unverified). Thanks in advance.
<?php require_once 'db/setting.php'; require_once 'db/odbc.php'; session_start(); error_reporting(0); if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { $protocol = 'https://'; } else { $protocol = 'http://'; } $currentDomain = $protocol.$_SERVER[HTTP_HOST]; $API["secret_key"] = "xx"; $API["api_key"] = "xx"; $API["callback"] = $currentDomain."/vote-reward-tok.php?return={RETURNEDCODE}"; $API["API_Domain"] = "http://api.top-kal.com"; $secretKey = 'xxx'; $captcha = $_POST['g-recaptcha-response']; $ip = $_SERVER['REMOTE_ADDR']; $responseData=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&responseData=".$captcha."&remoteip=".$ip); $responseKeys = json_decode($responseData,true); $config["db_username"] = "sa"; $config["db_password"] = "********"; $config["db_database_account"] = "kal_auth"; $config["db_database_player"] = "kal_db"; $config["db_server"] = "NAME\SQLEXPRESS"; $config["db_driver"] = "SQL Server"; $config["Reward_Name"] = "Vote Coin"; $config["MinLvl_Require"] = 30; $config["Reward_Index"] = 447; $config["Reward_Amount"] = 10; $config["Reward_Bound"] = false;
function insertRewards($account_unique_id){ global $config; $connect = odbc_connect('Driver={'.$config["db_driver"].'};Server='.$config["db_server"].';Database='.$config["db_database_player"].';', $config['db_username'] ,$config['db_password']); if(!$connect) return false; $query = odbc_exec($connect,"SELECT Top 1 [IID] FROM [Item] Where [IID] < 1 order by IID Desc"); if(!$query) return false; $data = odbc_fetch_array($query); if($data && !empty($data) && isset($data["IID"])) odbc_exec($connect,"INSERT INTO [Item] ([PID],[IID],[Index],[Prefix],[Info],[Num])VALUES ($account_unique_id,".($data["IID"]+1).",".$config["Reward_Index"].",0,".(16+($config["Reward_Bound"] ? 128 : 0)).",".$config["Reward_Amount"].")"); } function checkCharacters($accountUID){ global $config; $connect = odbc_connect('Driver={'.$config["db_driver"].'};Server='.$config["db_server"].';Database='.$config["db_database_player"].';', $config['db_username'] ,$config['db_password']); if(!$connect) return array("error" => "failed to connect to database players."); $query = odbc_exec($connect,"SELECT [Level] FROM [Player] WHERE [UID] = $accountUID ORDER BY [Level] DESC"); if(!$query) return array("error" => "failed to find characters in this account id."); while($r = odbc_fetch_array($query)){ if($r["Level"] >= $config["MinLvl_Require"]) return array("success" => $accountUID); } return array("error" => "You should have one character at least higher than level : ".$config["MinLvl_Require"]." to vote."); } function checkAccount($accountID){ global $config; $connect = odbc_connect('Driver={'.$config["db_driver"].'};Server='.$config["db_server"].';Database='.$config["db_database_account"].';', $config['db_username'] ,$config['db_password']); if(!$connect) return array("error" => "failed to connect to database accounts."); $query = odbc_exec($connect,"SELECT TOP 1 [UID] FROM [Login] WHERE [ID] = '$accountID'"); if(!$query) return array("error" => "this account id not exists."); $data = odbc_fetch_array($query); if(!$data || empty($data) || !isset($data["UID"])) return array("error" => "this account id not exists."); if($config["MinLvl_Require"] > 0) return checkCharacters($data["UID"]); return array("success" => $data["UID"]); } >> Submitting Function $response = array("error" => false , "success" => false , 'redirect' => false); function post_content($query){ $query_array = array();foreach( $query as $key => $key_value )$query_array[] = urlencode( $key ) . '=' . urlencode( $key_value );return implode( '&', $query_array ); } global $API; $opts = array('http' => array('method' => 'POST',"header" => "Content-type: application/x-www-form-urlencoded\r\nAuthorization:".base64_encode($API["api_key"].":".$API["secret_key"])."\r\n", "content" => post_content($content)));return stream_context_create($opts); } function submit(){ global $API; if(empty($captcha) || $captcha == '' || !isset($captcha)) return array( "error" => "Please solve the captcha."); if (empty($_POST['account']) || !ctype_alnum($_POST['account'])) return array( "error" => "Invalid account id."); $checkAccount = checkAccount($_POST['account']); if (isset($checkAccount["error"])) return array("error" => $checkAccount["error"]); if (isset($checkAccount["success"])){ $account_unique_id = (isset($_SESSION['kal_id'])) ? $_SESSION['kal_id'] : $checkAccount["success"]; $result = json_decode(file_get_contents($API["API_Domain"] . '/api/generate/vote-rewards-token', false, postParams(array('callback' => $API["callback"],'account_unique_id' => $account_unique_id ))) , true); { echo '<br><center><h3>Please wait...</h3></center>'; } if (!empty($result)){ if (isset($result["response"])){ if (isset($result["response"]["error"])) return array("error" => $result["response"]["error"]); elseif (isset($result["response"]["success"])) return array("redirect" => '<script type="text/javascript">setTimeout(function () { window.location.href = "'.$result["response"]["success"].'";}, 500)</script>'); } } } } if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['account'])){ $response = submit(); if (isset($response['redirect']) && $response['redirect']){ echo $response['redirect']; die; } }elseif (isset($_GET['return'])){ $result = json_decode(file_get_contents($API["API_Domain"] . '/api/verify/vote-rewards-token', false, postParams(array('returned_code' => $_GET['return']))) , true); if (!empty($result)){ if (isset($result["response"])){ if (isset($result["response"]["error"])) $response['error'] = $result["response"]["error"]; elseif (isset($result["response"]["success"])){ insertRewards($result["response"]["account_unique_id"]); $response['success'] = '<b>Thank you, Your vote has been recorded and the server rank will be updated soon.<b><br />You will receive your rewards in storage of your account.<p>Your next vote in : <b>' . $result["response"]["NextVote"] . '</b></p>'; } } } } ?>
<head> <title>Vote Rewards - <?php echo $config['serverName']; ?></title> <link rel="shortcut icon" href=images/favicon.png"> <link rel="stylesheet" href="css/vote.css"> <link rel="stylesheet" href="css/fontawesome.css"> <link rel="stylesheet" href="css/fontawesomeall.css"> <script src='https://www.google.com/recaptcha/api.js'></script> </head> <body> <form class="vote-form" method="post"> <noscript><div class="isa_error">Javascript is not enabled in your browser! Please enable it or change your browser.</div></noscript> <?php if(isset($response['error']) && $response['error']){ ?><div class="isa_error"> <?php echo $response['error'] ;?> </div> <?php } ?> <?php if(isset($response['success']) && $response['success']){ ?><div class="isa_success"> <?php echo $response['success'] ;?> </div> <?php }else{ ?> <label> <span>Account ID :</span> <input type="text" name="account" maxlength="20" <?php echo (isset($_SESSION['kal_username'])) ? 'readonly value="'.$_SESSION['kal_username'].'"' : ""; ?>" /> </label> <div class="g-recaptcha" style="margin:0 auto;" data-sitekey="xxx" data-theme="dark"></div> <label class="label_btn"> <input type="submit" class="button" value="Vote" /> </label> <?php } ?> </form> <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> </body> </html> Edited October 13, 2019 by requinix we don't do markdown. please use the Code <> button for code Hi, I currently have this code: Code: [Select] <?php function respond_xml($status, $message) { $out = new XMLWriter(); $out->openURI("php://output"); $out->setIndent(true); $out->startDocument("1.0", "ISO-8859-1"); $out->startElement("statuscheck"); $out->writeElement("status", $status); $out->writeElement("message", $message); $out->endElement(); $out->endDocument(); $out->flush(); } function main() { header("Content-type: text/xml"); if (!isset($_GET["file"])) respond_xml("ERROR", "File parameter missing"); else if (file_exists($_GET["file"])) return respond_xml("OK", "File exists"); else return respond_xml("NOT OK", "File does not exist"); } main(); ?> This code works and gives a correct XML response when you type in for example "http://localhost:8080/php/script.php?file=test" it's says: Code: [Select] <statuscheck> <status>NOT OK</status> <message>File does not exist</message> </statuscheck> Now, I need it to be able to check it every 5 seconds so i've use this code Code: [Select] header("Refresh: 5; URL=http://localhost:8080/php/script.php?file=test"); Here's my problem: The first 5 or 10 tries it should say "file not found". After the 10th try it should automatically say "file found". BUT it should also time out after like 50 tries and it hasn't found the file. But i don't know how to do this.. Could i use curl to check api response time and if so how? A HTTP request is made to the server, Slim creates a Request and Response object, content in the Request is sent to another server using cURL via Guzzle, Guzzle returns its own Response, and content from Guzzle's response must be returned by the original Slim response. Would you recommend white-listing or black-listing response headers, and which specific headers? Similarly, would you recommend white-listing or black-listing the request headers sent via cURL, and which specific headers? Thanks <?php use Psr\Http\Message\ResponseInterface as Response; use GuzzleHttp\Psr7\Response as CurlResponse; class ApiResponder { public function delete(Response $httpResponse, CurlResponse $curlResponse) { return $this->proxy($httpResponse, $curlResponse); } //other public methods... private function proxy(Response $httpResponse, CurlResponse $curlResponse) { foreach($this->getResponseHeaders($curlResponse) as $name=>$value) { $httpResponse=$httpResponse->withHeader($name, $value); } return $httpResponse->withBody($curlResponse->getBody())->withStatus($curlResponse->getStatusCode()); } private function getResponseHeaders(Response $httpResponse):array { //Blacklist headers which should be returned to original client. TBD whether I should whitelist headers instead. $blacklist=['Date'=>null, 'Server'=>null, 'X-Powered-By'=>null, 'Access-Control-Allow-Origin'=>null, 'Access-Control-Allow-Methods'=>null, 'Access-Control-Allow-Headers'=>null, 'Set-Cookie'=>null]; return array_diff_key($curlResponse->getHeaders(), $blacklist); } /** * This method doesn't really exist in this class, but is just included to show which headers I am forwarding in the cURL request. */ private function getRequestHeaders($clientRequest):array { $whitelist=['connection'=>null,'accept'=>null,'accept-encoding'=>null,'accept-language'=>null,'content-type'=>null,'content-length'=>null]; return array_intersect_key($clientRequest->getHeaders(), $whitelist); } }
Hello, I found some little php code to check google index of any site. Code: [Select] <?php function checkSite($www) { $ch = curl_init('http://www.google.pl/search?hl=pl&q=site%3A'.trim($www).'&btnG=Szukaj&source=hp'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $sHtml = curl_exec($ch); preg_match('#\<div id=resultStats\>.*([0-9,]+) wynik#Ui', $sHtml, $aMatches); curl_close($ch); return (int)str_replace(',', '', $aMatches[1]); } echo checkSite('domain.com'); ?> But to check any site I must edit this code and add new site manually. I'm big beginner in PHP. I want to have a area on browser side to add many sites, and receive result, like in this code which I add. above. Can anybody help me with this? PS. Sorry for my poor English. Not sure if this is possible, but.. As most of you likely know, if a person searches Google, they can see how many webpages are indexed by using: site:techcrunch.com Is there any way that I could do this via a php script for 10 different sites and then have the results emailed to me on a daily basis? I'm not asking for a coded solution.. just an idea on how this might be achieved, if it could? Thanks. This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=344076.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=307094.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=356960.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=333650.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=315333.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=321605.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=328756.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=307157.0 This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=357315.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=356052.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=351914.0 |