All pastes #982027 Raw Edit

OpenSimWiReduxEcom

public text v1 · immutable
·published 2008-04-12 06:31 UTC
rendered paste body
Index: trunk/currency.php
===================================================================
--- trunk/currency.php	(revision 0)
+++ trunk/currency.php	(revision 0)
@@ -0,0 +1,196 @@
+<? 
+
+// This file enables buying currency in the client.
+
+// For this to work, the all clients using currency need to add
+// -helperURI <WebpathToThisDirectory> to the commandline parameters when starting the client!
+// ex: '-helperURI http://foo.bar/'  if this file is in the root folder of the website foo.bar
+
+// Don't forget to change the currency conversion value in the wi_economy_money table!
+
+
+include("settings/config.php");
+include("settings/mysql.php");
+
+$confirmValue = "1234567883789";
+
+function move_money($sourceId, $destId, $amount, $aggregatePermInventory, $aggregatePermNextOwner, $flags, $transactionType, $description)
+{
+	// Add Cash to one account
+	$DbLink = new DB;
+	$SQL = "INSERT INTO ".C_TRANSACTION_TBL." (sourceId,destId,amount,flags,aggregatePermInventory,aggregatePermNextOwner,transactionType,description) values ('".$sourceId."','".$destId."',".$amount.",".$aggregatePermInventory.",".$aggregatePermNextOwner.",".$flags.",".$transactionType.",'".$description."')";
+	
+	list($UUIDUSER) = $DbLink->query($SQL);
+	
+	// Remove Cash from the other account
+	$amount2 = (integer)$amount * -1;
+	
+	$SQL = "INSERT INTO ".C_TRANSACTION_TBL." (sourceId,destId,amount,flags,aggregatePermInventory,aggregatePermNextOwner,transactionType,description) values ('".$destId."','".$sourceId."',".$amount2.",".$aggregatePermInventory.",".$aggregatePermNextOwner.",".$flags.",".$transactionType.",'".$description."')";
+
+	list($UUIDUSER) = $DbLink->query($SQL);
+
+	return True;
+}
+
+function processTransaction($avatarId,$amount)
+{
+	// Do Credit Card Processing here!  Return False if it fails!
+	// Remember, $amount is stored without decimal places, however it's assumed
+	// that the transaction amount is in Cents and has two decimal places
+	// 5 dollars will be 500
+	// 15 dollars will be 1500
+	return True;
+}
+
+function quote_func($method_name, $params, $app_data)
+{
+
+	$confirmValue = "1234567883789";
+
+	$req = $params[0];
+	$agentid = str_replace("\'","",$req['agentId']);
+	$sessionid = str_replace("\'","",$req['secureSessionId']);
+	$amount = $req['currencyBuy'];
+
+	// Validate Requesting user has a session
+	$DbLink = new DB;
+	$DbLink->query("SELECT UUID FROM ".C_SESSION_TBL." WHERE UUID='$agentid' and secureSessionID='$sessionid'");
+	list($UUIDUSER) = $DbLink->next_record();
+
+	if($UUIDUSER){
+
+		// Get the currency conversion ratio in USD Cents per Money Unit
+		$DbLink->query("SELECT CentsPerMoneyUnit FROM ".C_CURRENCY_TBL." limit 1");
+		list($CentsPerMoneyUnit) = $DbLink->next_record();
+
+		if ($CentsPerMoneyUnit)
+		{} else 
+		{
+			$CentsPerMoneyUnit = 0;
+		}	
+		
+		// Multiply the cents per L times the requested amount
+		$estimatedcost = 0;
+		$estimatedcost = $CentsPerMoneyUnit * $amount;
+		
+		// Dealing in cents here. The XML requires an integer
+		// so we have to ceil out any decimal places and cast as an integer
+		$estimatedcost = (integer)ceil($estimatedcost);		
+		
+		$currency = array('estimatedCost'=>$estimatedcost,'currencyBuy'=>$amount);
+
+		
+		header("Content-type: text/xml");
+		$response_xml = xmlrpc_encode(array(
+				'success'=>True,'currency'=>$currency,
+				'confirm'=>$confirmvalue
+			));
+
+		
+
+		print $response_xml;
+	} else {
+				
+		header("Content-type: text/xml");
+		$response_xml = xmlrpc_encode(array(
+					'success'=>False,
+					'errorMessage'=>"Unable to Authenticate\n\nClick URL for more info.",
+					'errorURI'=> "".SYSURL.""
+					));
+		print $response_xml;
+
+	}
+
+	return "";
+}
+
+function buy_func($method_name, $params, $app_data)
+{
+	$req = $params[0];
+	$agentid = str_replace("\'","",$req['agentId']);
+	$sessionid = str_replace("\'","",$req['secureSessionId']);
+	$amount = $req['currencyBuy'];
+
+	// Validate Requesting user has a session
+	$DbLink = new DB;
+	$DbLink->query("SELECT UUID FROM ".C_SESSION_TBL." WHERE UUID='$agentid' and secureSessionID='$sessionid'");
+	list($UUIDUSER) = $DbLink->next_record();
+
+	if($UUIDUSER){
+
+		// Get the currency conversion ratio in USD Cents per Money Unit
+		$DbLink->query("SELECT CentsPerMoneyUnit FROM ".C_CURRENCY_TBL." limit 1");
+		list($CentsPerMoneyUnit) = $DbLink->next_record();
+
+		if ($CentsPerMoneyUnit)
+		{} else 
+		{
+			$CentsPerMoneyUnit = 0;
+		}	
+		
+		// Multiply the cents per L times the requested amount
+		$estimatedcost = 0;
+		$estimatedcost = $CentsPerMoneyUnit * $amount;
+		
+		// Dealing in cents here. The XML requires an integer
+		// so we have to ceil out any decimal places and cast as an integer
+		$estimatedcost = (integer)ceil($estimatedcost);		
+
+		$transactionResult = processTransaction($agentid,$estimatedcost);
+		
+		if ($transactionResult)
+		{
+
+			header("Content-type: text/xml");
+			$response_xml = xmlrpc_encode(array(
+					'success'=>True
+					));
+			print $response_xml;
+			move_money('', $agentid, $amount, 0, 0, 0, 0, "Currency purchase");
+			
+		} else {
+
+			
+			header("Content-type: text/xml");
+			$response_xml = xmlrpc_encode(array(
+					'success'=>False,
+					'errorMessage'=>"We were unable to process the transaction.  The gateway denied your charge",
+					'errorURI'=>"".SYSURL.""
+					));
+			print $response_xml;
+
+		}
+		
+	} else 
+	{
+
+		header("Content-type: text/xml");
+		$response_xml = xmlrpc_encode(array(
+					'success'=>False,
+					'errorMessage'=>"Unable to Authenticate\n\nClick URL for more info.",
+					'errorURI'=> "".SYSURL.""
+					));
+		print $response_xml;
+
+
+	}
+	
+	return "";
+}
+
+
+$xmlrpc_server = xmlrpc_server_create();
+
+xmlrpc_server_register_method($xmlrpc_server, "getCurrencyQuote", "quote_func");
+xmlrpc_server_register_method($xmlrpc_server, "buyCurrency", "buy_func");
+
+
+$request_xml = $HTTP_RAW_POST_DATA;
+
+$response = xmlrpc_server_call_method($xmlrpc_server, $request_xml, '');
+//print $response;
+
+xmlrpc_server_destroy($xmlrpc_server);
+
+
+?>
\ No newline at end of file
Index: trunk/settings/config.php
===================================================================
--- trunk/settings/config.php	(revision 5)
+++ trunk/settings/config.php	(working copy)
@@ -37,5 +37,8 @@
 define("C_SITE_TBL","wi_sitemanager");
 define("C_NAMES_TBL","wi_lastnames");
 define("C_COUNTRY_TBL","wi_country");
+define("C_SESSION_TBL","agents");
+define("C_CURRENCY_TBL","wi_economy_money");
+define("C_TRANSACTION_TBL","wi_economy_transactions");
 
 ?>
\ No newline at end of file
Index: trunk/sql_update/wi_economy_money.sql
===================================================================
--- trunk/sql_update/wi_economy_money.sql	(revision 0)
+++ trunk/sql_update/wi_economy_money.sql	(revision 0)
@@ -0,0 +1,7 @@
+CREATE TABLE wi_economy_money (
+   id INT AUTO_INCREMENT NOT NULL,
+   CentsPerMoneyUnit INT NOT NULL DEFAULT '0',
+  PRIMARY KEY (id)
+) ENGINE = InnoDB ROW_FORMAT = DEFAULT;
+
+INSERT INTO wi_economy_money (id,CentsPerMoneyUnit) values (1,0.5);
\ No newline at end of file
Index: trunk/sql_update/wi_economy_transactions.sql
===================================================================
--- trunk/sql_update/wi_economy_transactions.sql	(revision 0)
+++ trunk/sql_update/wi_economy_transactions.sql	(revision 0)
@@ -0,0 +1,16 @@
+CREATE TABLE `wi_economy_transactions`
+   (
+   `id` int (11) NOT NULL AUTO_INCREMENT,
+   `sourceId` varchar (36) NOT NULL,
+   `destId` varchar (36) NOT NULL,
+   `amount` int (11) NOT NULL DEFAULT '0' ,
+   `flags` int (11) NOT NULL DEFAULT '0' ,
+   `aggregatePermInventory` int (11) NOT NULL DEFAULT '0' ,
+   `aggregatePermNextOwner` int (11) NOT NULL DEFAULT '0' ,
+   `description` varchar (256) DEFAULT NULL ,
+   `transactionType` int (11) NOT NULL DEFAULT '0' ,
+   PRIMARY KEY (`id`)
+   )
+   ENGINE=INNODB
+   AUTO_INCREMENT=1
+   DEFAULT CHARSET=utf8;
\ No newline at end of file