Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Server Development
Habbo Retros
Habbo Releases
[PayPal IPN] Automatic Shopping System
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="MayoMayn" data-source="post: 396896" data-attributes="member: 71840"><p>Since I've seen so many retarded retros around here, not using any kind of IPN, so that their users have to wait several hours to get what they've paid for, I've decided to release the class and coding I use for my CMS.</p><p></p><p>Demo: <a href="https://www.youtube.com/watch?v=WpqWzwuzfIc" target="_blank">https://www.youtube.com/watch?v=WpqWzwuzfIc</a></p><p>(I assume that you're using <strong>RevCMS</strong>, if not change values in the coding so it matches your CMS).</p><p></p><p>First off, go create a folder called <strong>paypal </strong>and a file called <strong>class.paypal.php </strong>inside that folder.</p><p><em><u>There's a construct function so that if people use some sort of config table or anything related to that, they can easily change their settings inside this class.</u></em></p><p>Your <strong>class.paypal.php</strong> should contain this:</p><p>[PHP]</p><p>class PayPalIPN</p><p>{</p><p> /**</p><p> * @var bool $use_sandbox Indicates if the sandbox endpoint is used.</p><p> */</p><p> private $use_sandbox = true;</p><p> /**</p><p> * @var bool $use_local_certs Indicates if the local certificates are used.</p><p> */</p><p> private $use_local_certs = true;</p><p> /**</p><p> * @var string $DIR Indicates the file directory of this class.</p><p> */</p><p> private $DIR = dirname(__FILE__) . DIRECTORY_SEPARATOR . "app/management/";</p><p> /** Production Postback URL */</p><p> const VERIFY_URI = 'https://ipnpb.paypal.com/cgi-bin/webscr';</p><p> /** Sandbox Postback URL */</p><p> const SANDBOX_VERIFY_URI = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr';</p><p> /** Response from PayPal indicating validation was successful */</p><p> const VALID = 'VERIFIED';</p><p> /** Response from PayPal indicating validation failed */</p><p> const INVALID = 'INVALID';</p><p> </p><p> /*public function __construct($config) {</p><p> $this->use_sandbox = ($config->paypal('production') ? false : true);</p><p></p><p> $this->use_local_certs = ($config->paypal('local_certs') ? true : false);</p><p> }*/</p><p></p><p> public function putLog($title='LOG',$data)</p><p> {</p><p></p><p> $cur_log = file_get_contents($this->DIR . "logs/paypal.log");</p><p> file_put_contents($this->DIR . "logs/paypal.log", $cur_log . "[PAYPAL {$title} - " . gmdate("D, d M Y H:i:s") . "]\r\n" . "{$data}\r\n\r\n");</p><p></p><p> }</p><p> /**</p><p> * Determine endpoint to post the verification data to.</p><p> * @return string</p><p> */</p><p> public function getPaypalUri()</p><p> {</p><p> if($this->use_sandbox) {</p><p> return self::SANDBOX_VERIFY_URI;</p><p> } else {</p><p> return self::VERIFY_URI;</p><p> }</p><p></p><p> }</p><p> /**</p><p> * Verification Function</p><p> * Sends the incoming post data back to PayPal using the cURL library.</p><p> *</p><p> * @return bool</p><p> * @throws Exception</p><p> */</p><p> public function verifyIPN()</p><p> {</p><p> </p><p> if(!count($_POST)) {</p><p> return false;</p><p> exit();</p><p> }</p><p> $raw_post_data = file_get_contents('php://input');</p><p> $raw_post_array = explode('&', $raw_post_data);</p><p> $data = [];</p><p> foreach($raw_post_array as $keyval) {</p><p> $keyval = explode('=', $keyval);</p><p> if(count($keyval) == 2) {</p><p> // Since we do not want the plus in the datetime string to be encoded to a space, we manually encode it.</p><p> if($keyval[0] === 'payment_date') {</p><p> if(substr_count($keyval[1], '+') === 1) {</p><p> $keyval[1] = str_replace('+', '%2B', $keyval[1]);</p><p> }</p><p> }</p><p> $data[$keyval[0]] = urldecode($keyval[1]);</p><p> }</p><p> }</p><p> // Build the body of the verification post request, adding the _notify-validate command.</p><p> $req = 'cmd=_notify-validate';</p><p> foreach($data as $key => $value) {</p><p> if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() == 1) {</p><p> $value = urlencode(stripslashes($value));</p><p> } else {</p><p> $value = urlencode($value);</p><p> }</p><p> $req .= "&{$key}={$value}";</p><p> }</p><p> // Post the data back to PayPal, using curl. Throw exceptions if errors occur.</p><p> $ch = curl_init($this->getPaypalUri());</p><p> curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);</p><p> curl_setopt($ch, CURLOPT_POST, 1);</p><p> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);</p><p> curl_setopt($ch, CURLOPT_POSTFIELDS, $req);</p><p> curl_setopt($ch, CURLOPT_SSLVERSION, 6);</p><p> curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);</p><p> curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);</p><p> // This is often required if the server is missing a global cert bundle, or is using an outdated one.</p><p> if($this->use_local_certs) {</p><p> curl_setopt($ch, CURLOPT_CAINFO, $this->DIR . "paypal/cacert.pem");</p><p> }</p><p> curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);</p><p> curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);</p><p> curl_setopt($ch, CURLOPT_HTTPHEADER, ['Connection: Close']);</p><p> $res = curl_exec($ch);</p><p> if(!($res)) {</p><p> $errno = curl_errno($ch);</p><p> $errstr = curl_error($ch);</p><p> curl_close($ch);</p><p> $this->putLog("ERROR", "cURL error: [{$errno}] {$errstr}");</p><p> }</p><p> $info = curl_getinfo($ch);</p><p> $http_code = $info['http_code'];</p><p> if($http_code != 200) {</p><p> $this->putLog("ERROR", "PayPal responded with http code {$http_code}");</p><p> }</p><p> curl_close($ch);</p><p> // Check if PayPal verifies the IPN data, and if so, return true.</p><p> if($res == self::VALID) {</p><p> return true;</p><p> } else {</p><p> return false;</p><p> }</p><p></p><p> }</p><p></p><p>}</p><p>[/PHP]</p><p></p><p>Then after this go and run this SQL query to add the required table:</p><p>[CODE]</p><p>DROP TABLE IF EXISTS `cms_transactions`;</p><p>CREATE TABLE `cms_transactions` (</p><p> `id` int(11) NOT NULL AUTO_INCREMENT,</p><p> `user_id` int(11) NOT NULL,</p><p> `refunded` enum('0','1') DEFAULT '0',</p><p> `gateway` enum('stripe','paypal','braintree') DEFAULT NULL,</p><p> `transaction_id` varchar(25) NOT NULL,</p><p> `amount` char(7) NOT NULL,</p><p> `package` int(1) NOT NULL,</p><p> `email` varchar(255) DEFAULT NULL,</p><p> `nonce` varchar(255) NOT NULL,</p><p> `purchase_date` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,</p><p> PRIMARY KEY (`id`)</p><p>) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;</p><p>[/CODE]</p><p></p><p>Then on your shop page, go add this at the very top of your .php file:</p><p>[PHP]</p><p>/**</p><p> * Set cache headers to prevent the user from doing a duplicate of form submission</p><p> */</p><p>header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");</p><p>header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");</p><p>header("Cache-Control: no-store, no-cache, must-revalidate");</p><p>header("Cache-Control: post-check=0, pre-check=0", false);</p><p>header("Pragma: no-cache");</p><p></p><p>//header("HTTP/1.1 200 OK");</p><p></p><p>require dirname(__FILE__) . DIRECTORY_SEPARATOR . "app/management/paypal/class.paypal.php";</p><p></p><p>use PayPalIPN;</p><p></p><p>$ipn = new PayPalIPN();</p><p></p><p>$orderPlaced = true;</p><p></p><p>// Set the response array</p><p>$response = ['status' => 'false', 'title' => 'Payment Error', 'message' => ''];</p><p></p><p>$verified = $ipn->verifyIPN();</p><p>if($verified) {</p><p> $username = $users->getUsername($uid);</p><p></p><p> // Payment has been verified, so get details</p><p> $payer_email = $_POST['payer_email'];</p><p> $verify_sign = $_POST['verify_sign'];</p><p> $txn_id = $_POST['txn_id'];</p><p> $payment_date = $_POST['payment_date'];</p><p> $package = $_POST['item_number'];</p><p> $amount = $_POST['payment_gross'];</p><p> $item_name = $_POST['item_name'];</p><p></p><p> // Make sure the transaction id has not already been used</p><p> $stmt = $db->query("SELECT `id` FROM `cms_transactions` WHERE `transaction_id` = :tid LIMIT 1");</p><p> $stmt->bindParam(':tid', $txn_id, $db->PARAM_STR);</p><p> $stmt->execute();</p><p></p><p> if($stmt->rowCount() < 1) {</p><p> // If the transaction id has not been used, match the package id against the one in db.</p><p> $stmt = $db->query("SELECT `diamonds` FROM `cms_diamond_packages` WHERE `id` = :id AND `price` = :a LIMIT 1");</p><p> $stmt->bindParam(':id', $package, $db->PARAM_INT);</p><p> $stmt->bindParam(':a', $amount, $db->PARAM_STR);</p><p> $stmt->execute();</p><p> </p><p> if($stmt->rowCount() > 0) {</p><p> $diamonds = $stmt->fetchColumn();</p><p> </p><p> // Payment has been successfully placed, insert it into the transactions table.</p><p> $stmt = $db->query("INSERT INTO `cms_transactions` (`user_id`,`gateway`,`transaction_id`,`amount`,`package`,`email`,`nonce`,`purchase_date`) VALUES (:uid,:g,:tid,:a,:p,:e,:n,:d)");</p><p> $data = [</p><p> ':uid' => $_SESSION['user']['id'],</p><p> ':g' => 'paypal',</p><p> ':tid' => $txn_id,</p><p> ':a' => $amount,</p><p> ':p' => $package,</p><p> ':e' => $payer_email,</p><p> ':n' => $verify_sign,</p><p> ':d' => NULL</p><p> ];</p><p> $stmt->execute($data);</p><p> </p><p> // Give user paid currencies or VIP</p><p> $users->updateUser($uid, 'diamonds', ($users->getUserInfo($uid, 'diamonds') + $diamonds));</p><p> if(!$users->hasBadge($uid, 'SDB01')) // If user doesn't have badge give it to them</p><p> $users->giveUserBadge($uid, 'SDB01');</p><p> </p><p> // Set response to success</p><p> $response['status'] = "true";</p><p> $response['title'] = "Payment Success";</p><p> $response['message'] = 'You have successfully bought '.$diamonds.' <img src="'.$url.'/static/img/diamonds.png" />.<br /> You can buy all sorts of things with diamonds. Visit our other shops to buy credits, duckets, rares, boxes, VIP etc.';</p><p> </p><p> // Put log as success</p><p> $ipn->putLog("SUCCESS", json_encode($_POST, true));</p><p> $ipn->putLog("SUCCESS", "User {$username} has successfully bought package {$package} containing {$diamonds} with a price of {$amount} using payer email {$payer_email} on {$payment_date} with ID: {$txn_id}");</p><p> } else {</p><p> // Put log as the user trying to exploit the system by changing price for a package</p><p> $response['message'] = "Package ID doesn't match its pricetag: {$verified}";</p><p> $ipn->putLog("ERROR", "User {$username} tried to spoof {$package} with price {$amount} using transaction id {$txn_id} with payer email {$payer_email} on {$payment_date}.");</p><p> }</p><p> } else {</p><p> // User tried to duplicate this package, set the response and put the error log</p><p> $response['message'] = "You have already bought a package using this Transaction ID once <b>{$txn_id}</b>.";</p><p> $ipn->putLog("ERROR", "User {$username} tried to duplicate package {$package} using transaction id {$txn_id} with payer email {$payer_email} on {$payment_date}.");</p><p> }</p><p>} else {</p><p> $orderPlaced = false;</p><p>}</p><p>[/PHP]</p><p></p><p>So, when someone clicks on a buy button, they should be redirected to PayPal with the right values, that is where this comes in handy:</p><p>[PHP]</p><p><?php echo '<form action="'.$ipn->getPaypalUri().'" method="post" accept-charset="utf8"></p><p><input type="hidden" name="cmd" value="_xclick"></p><p><input type="hidden" name="lc" value="US"></p><p><input type="hidden" name="currency" value="currency they're paying in"></p><p><input type="hidden" name="item_name" value="title of what they're buying"></p><p><input type="hidden" name="business" value="Your PayPal Business Email"></p><p><input type="hidden" name="amount" value="price of what they're buying"></p><p><input type="hidden" name="item_number" value="package id of what they're buying"></p><p><input type="hidden" name="return" value="enter url here that returns to your shop page"></p><p><input type="hidden" name="cancel_url" value="enter url here that returns to your shop page"></p><p><input type="hidden" name="rm" value="2"></p><p><input type="hidden" name="quantity" value="1"></p><p><button style="margin:3px 3px 3px;float:left;padding:.375rem 0.9rem;" type="submit" class="btn btn-green" name="submit"></p><p> <big>_diamonds_ <img src="'.$url.'/static/img/diamonds.png" /></big></p><p> <br /></p><p> <small>_price_ '.$currency.'</small></p><p></button></p><p></form>'; ?></p><p>[/PHP]</p><p></p><p>To check if a process has been made, you can print to the user the response details as shown below:</p><p>[PHP]</p><p><?php if($orderPlaced): ?></p><p><script type="text/javascript"></p><p>window.alert("Title: <?php echo $response['title']; ?>, Response: <?php echo $response['message']; ?>");</p><p></script></p><p><?php endif; ?></p><p>[/PHP]</p><p></p><p>Getting the <strong>cacert.pem </strong>copy the data from here: <a href="https://github.com/paypal/ipn-code-samples/blob/master/php/cert/cacert.pem" target="_blank">https://github.com/paypal/ipn-code-samples/blob/master/php/cert/cacert.pem</a></p><p>Aint gonna be too specific about this, so if you got any questions write a comment.</p><p></p><p>* There will be added a feature, so that every times a user visits client, it checks for current existing transactions made by that user, to be sure that the user haven't refunded the payment, and if they have, it will automatically ban them.</p></blockquote><p></p>
[QUOTE="MayoMayn, post: 396896, member: 71840"] Since I've seen so many retarded retros around here, not using any kind of IPN, so that their users have to wait several hours to get what they've paid for, I've decided to release the class and coding I use for my CMS. Demo: [URL]https://www.youtube.com/watch?v=WpqWzwuzfIc[/URL] (I assume that you're using [B]RevCMS[/B], if not change values in the coding so it matches your CMS). First off, go create a folder called [B]paypal [/B]and a file called [B]class.paypal.php [/B]inside that folder. [I][U]There's a construct function so that if people use some sort of config table or anything related to that, they can easily change their settings inside this class.[/U][/I] Your [B]class.paypal.php[/B] should contain this: [PHP] class PayPalIPN { /** * @var bool $use_sandbox Indicates if the sandbox endpoint is used. */ private $use_sandbox = true; /** * @var bool $use_local_certs Indicates if the local certificates are used. */ private $use_local_certs = true; /** * @var string $DIR Indicates the file directory of this class. */ private $DIR = dirname(__FILE__) . DIRECTORY_SEPARATOR . "app/management/"; /** Production Postback URL */ const VERIFY_URI = 'https://ipnpb.paypal.com/cgi-bin/webscr'; /** Sandbox Postback URL */ const SANDBOX_VERIFY_URI = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr'; /** Response from PayPal indicating validation was successful */ const VALID = 'VERIFIED'; /** Response from PayPal indicating validation failed */ const INVALID = 'INVALID'; /*public function __construct($config) { $this->use_sandbox = ($config->paypal('production') ? false : true); $this->use_local_certs = ($config->paypal('local_certs') ? true : false); }*/ public function putLog($title='LOG',$data) { $cur_log = file_get_contents($this->DIR . "logs/paypal.log"); file_put_contents($this->DIR . "logs/paypal.log", $cur_log . "[PAYPAL {$title} - " . gmdate("D, d M Y H:i:s") . "]\r\n" . "{$data}\r\n\r\n"); } /** * Determine endpoint to post the verification data to. * @return string */ public function getPaypalUri() { if($this->use_sandbox) { return self::SANDBOX_VERIFY_URI; } else { return self::VERIFY_URI; } } /** * Verification Function * Sends the incoming post data back to PayPal using the cURL library. * * @return bool * @throws Exception */ public function verifyIPN() { if(!count($_POST)) { return false; exit(); } $raw_post_data = file_get_contents('php://input'); $raw_post_array = explode('&', $raw_post_data); $data = []; foreach($raw_post_array as $keyval) { $keyval = explode('=', $keyval); if(count($keyval) == 2) { // Since we do not want the plus in the datetime string to be encoded to a space, we manually encode it. if($keyval[0] === 'payment_date') { if(substr_count($keyval[1], '+') === 1) { $keyval[1] = str_replace('+', '%2B', $keyval[1]); } } $data[$keyval[0]] = urldecode($keyval[1]); } } // Build the body of the verification post request, adding the _notify-validate command. $req = 'cmd=_notify-validate'; foreach($data as $key => $value) { if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() == 1) { $value = urlencode(stripslashes($value)); } else { $value = urlencode($value); } $req .= "&{$key}={$value}"; } // Post the data back to PayPal, using curl. Throw exceptions if errors occur. $ch = curl_init($this->getPaypalUri()); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $req); curl_setopt($ch, CURLOPT_SSLVERSION, 6); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // This is often required if the server is missing a global cert bundle, or is using an outdated one. if($this->use_local_certs) { curl_setopt($ch, CURLOPT_CAINFO, $this->DIR . "paypal/cacert.pem"); } curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Connection: Close']); $res = curl_exec($ch); if(!($res)) { $errno = curl_errno($ch); $errstr = curl_error($ch); curl_close($ch); $this->putLog("ERROR", "cURL error: [{$errno}] {$errstr}"); } $info = curl_getinfo($ch); $http_code = $info['http_code']; if($http_code != 200) { $this->putLog("ERROR", "PayPal responded with http code {$http_code}"); } curl_close($ch); // Check if PayPal verifies the IPN data, and if so, return true. if($res == self::VALID) { return true; } else { return false; } } } [/PHP] Then after this go and run this SQL query to add the required table: [CODE] DROP TABLE IF EXISTS `cms_transactions`; CREATE TABLE `cms_transactions` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `refunded` enum('0','1') DEFAULT '0', `gateway` enum('stripe','paypal','braintree') DEFAULT NULL, `transaction_id` varchar(25) NOT NULL, `amount` char(7) NOT NULL, `package` int(1) NOT NULL, `email` varchar(255) DEFAULT NULL, `nonce` varchar(255) NOT NULL, `purchase_date` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8; [/CODE] Then on your shop page, go add this at the very top of your .php file: [PHP] /** * Set cache headers to prevent the user from doing a duplicate of form submission */ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); //header("HTTP/1.1 200 OK"); require dirname(__FILE__) . DIRECTORY_SEPARATOR . "app/management/paypal/class.paypal.php"; use PayPalIPN; $ipn = new PayPalIPN(); $orderPlaced = true; // Set the response array $response = ['status' => 'false', 'title' => 'Payment Error', 'message' => '']; $verified = $ipn->verifyIPN(); if($verified) { $username = $users->getUsername($uid); // Payment has been verified, so get details $payer_email = $_POST['payer_email']; $verify_sign = $_POST['verify_sign']; $txn_id = $_POST['txn_id']; $payment_date = $_POST['payment_date']; $package = $_POST['item_number']; $amount = $_POST['payment_gross']; $item_name = $_POST['item_name']; // Make sure the transaction id has not already been used $stmt = $db->query("SELECT `id` FROM `cms_transactions` WHERE `transaction_id` = :tid LIMIT 1"); $stmt->bindParam(':tid', $txn_id, $db->PARAM_STR); $stmt->execute(); if($stmt->rowCount() < 1) { // If the transaction id has not been used, match the package id against the one in db. $stmt = $db->query("SELECT `diamonds` FROM `cms_diamond_packages` WHERE `id` = :id AND `price` = :a LIMIT 1"); $stmt->bindParam(':id', $package, $db->PARAM_INT); $stmt->bindParam(':a', $amount, $db->PARAM_STR); $stmt->execute(); if($stmt->rowCount() > 0) { $diamonds = $stmt->fetchColumn(); // Payment has been successfully placed, insert it into the transactions table. $stmt = $db->query("INSERT INTO `cms_transactions` (`user_id`,`gateway`,`transaction_id`,`amount`,`package`,`email`,`nonce`,`purchase_date`) VALUES (:uid,:g,:tid,:a,:p,:e,:n,:d)"); $data = [ ':uid' => $_SESSION['user']['id'], ':g' => 'paypal', ':tid' => $txn_id, ':a' => $amount, ':p' => $package, ':e' => $payer_email, ':n' => $verify_sign, ':d' => NULL ]; $stmt->execute($data); // Give user paid currencies or VIP $users->updateUser($uid, 'diamonds', ($users->getUserInfo($uid, 'diamonds') + $diamonds)); if(!$users->hasBadge($uid, 'SDB01')) // If user doesn't have badge give it to them $users->giveUserBadge($uid, 'SDB01'); // Set response to success $response['status'] = "true"; $response['title'] = "Payment Success"; $response['message'] = 'You have successfully bought '.$diamonds.' <img src="'.$url.'/static/img/diamonds.png" />.<br /> You can buy all sorts of things with diamonds. Visit our other shops to buy credits, duckets, rares, boxes, VIP etc.'; // Put log as success $ipn->putLog("SUCCESS", json_encode($_POST, true)); $ipn->putLog("SUCCESS", "User {$username} has successfully bought package {$package} containing {$diamonds} with a price of {$amount} using payer email {$payer_email} on {$payment_date} with ID: {$txn_id}"); } else { // Put log as the user trying to exploit the system by changing price for a package $response['message'] = "Package ID doesn't match its pricetag: {$verified}"; $ipn->putLog("ERROR", "User {$username} tried to spoof {$package} with price {$amount} using transaction id {$txn_id} with payer email {$payer_email} on {$payment_date}."); } } else { // User tried to duplicate this package, set the response and put the error log $response['message'] = "You have already bought a package using this Transaction ID once <b>{$txn_id}</b>."; $ipn->putLog("ERROR", "User {$username} tried to duplicate package {$package} using transaction id {$txn_id} with payer email {$payer_email} on {$payment_date}."); } } else { $orderPlaced = false; } [/PHP] So, when someone clicks on a buy button, they should be redirected to PayPal with the right values, that is where this comes in handy: [PHP] <?php echo '<form action="'.$ipn->getPaypalUri().'" method="post" accept-charset="utf8"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="lc" value="US"> <input type="hidden" name="currency" value="currency they're paying in"> <input type="hidden" name="item_name" value="title of what they're buying"> <input type="hidden" name="business" value="Your PayPal Business Email"> <input type="hidden" name="amount" value="price of what they're buying"> <input type="hidden" name="item_number" value="package id of what they're buying"> <input type="hidden" name="return" value="enter url here that returns to your shop page"> <input type="hidden" name="cancel_url" value="enter url here that returns to your shop page"> <input type="hidden" name="rm" value="2"> <input type="hidden" name="quantity" value="1"> <button style="margin:3px 3px 3px;float:left;padding:.375rem 0.9rem;" type="submit" class="btn btn-green" name="submit"> <big>_diamonds_ <img src="'.$url.'/static/img/diamonds.png" /></big> <br /> <small>_price_ '.$currency.'</small> </button> </form>'; ?> [/PHP] To check if a process has been made, you can print to the user the response details as shown below: [PHP] <?php if($orderPlaced): ?> <script type="text/javascript"> window.alert("Title: <?php echo $response['title']; ?>, Response: <?php echo $response['message']; ?>"); </script> <?php endif; ?> [/PHP] Getting the [B]cacert.pem [/B]copy the data from here: [URL]https://github.com/paypal/ipn-code-samples/blob/master/php/cert/cacert.pem[/URL] Aint gonna be too specific about this, so if you got any questions write a comment. * There will be added a feature, so that every times a user visits client, it checks for current existing transactions made by that user, to be sure that the user haven't refunded the payment, and if they have, it will automatically ban them. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Releases
[PayPal IPN] Automatic Shopping System
Top