Hello
I’m trying to set up a pingback service for an online virtual currency (via paymentwall). I’ve attached the example code given by paymentwall with my codes in there to update the users credit balance. I am however having a few problems:
- whenever i run the code it always adds the new currency to ‘2’ (not the existing balance). I have absolutely no idea where 2 comes from!!! its supposed to add cumulatively so will retrieve all past credits earned when it gets the existing balance.
- the code is supposed to return a signature but I have absolutely no idea what to do (I think its in the last bit of the code?). I have uploaded the default help guide to help with this: http://m.gam3s.co.uk/wp-content/uploads/2012/07/paymentwall-api.pdf
If anyone has the time to mess around with this it would be greatly appreciated!
Matt
[CODE]
<?php define('SECRET', 'APPLICATION_KEY'); define('CHARGEBACK', 2); $ipsWhitelist = array( '174.36.92.186', '174.36.96.66', '174.36.92.187', '174.36.92.192', '174.37.14.28' ); $userId = isset($_GET['uid']) ? $_GET['uid'] : null; $credits = isset($_GET['currency']) ? $_GET['currency'] : null; $type = isset($_GET['type']) ? $_GET['type'] : null; $signature = isset($_GET['sig']) ? $_GET['sig'] : null; $refId = isset($_GET['ref']) ? $_GET['ref'] : null; $result = false; if (!empty($userId) && !empty($credits) && isset($type) && !empty($refId) && !empty($signature)) { $signatureParams = array( 'uid' => $userId, 'currency' => $credits, 'type' => $type, 'ref' => $refId ); $signatureCalculated = generateSignature($signatureParams, SECRET); // check if IP is in whitelist and if signature matches if (in_array($_SERVER['REMOTE_ADDR'], $ipsWhitelist) && ($signature == $signatureCalculated)) { $result = true; if ($type == 'CHARGEBACK') { // Deduct credits from user, NOTE: $credits will be (-x) $con = mysql_connect("localhost","USER","PASSWORD"); mysql_select_db("DATABASE", $con); $sql2 = "SELECT `Credits` FROM `wp_users` WHERE `ID`=$userId"; $existing2= mysql_query($sql2,$con); $newbalance2= $existing2 + $credits; $sql3 = "UPDATE `wp_users` SET `Credits`=$newbalance2 WHERE `ID`=$userId"; mysql_query($sql3,$con); mysql_close($con); } else { // Give credits to user $con = mysql_connect("localhost","USER","PASSWORD"); mysql_select_db("DATABASE", $con); $sql = "SELECT `Credits` FROM `wp_users` WHERE `ID`=$userId"; $existing= mysql_query($sql,$con); $newbalance= $existing + $credits; $sql1 = "UPDATE `wp_users` SET `Credits`=$newbalance WHERE `ID`=$userId"; mysql_query($sql1,$con); mysql_close($con); } } } if ($result) { echo 'OK'; } function generateSignature($params, $secret) { $str = ''; foreach ($params as $k=>$v) { $str .= "$k=$v"; } $str .= $secret; return md5($str); } ?>[/CODE]