note 31147 modified in function.curl-setopt by goba
| From: | goba@php.net | Date: | Fri, 17 Oct 2003 17:45:45 +0000 |
| Subject: | note 31147 modified in function.curl-setopt by goba | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-58771@lists.php.net to get a copy of this message | ||
A lot of people have asked me how to make automatic E-Gold payments so here's a small class:
class APayments
{
var $PROCES_DETAILS;
function Breakout($errno, $key="")
{
switch($errno)
{
case 1:
$this->PROCES_DETAILS["Error"] = "Error with var $key";
break;
case 2:
$this->PROCES_DETAILS["Error"] = "No vars";
break;
case 3:
$this->PROCES_DETAILS["Error"] = "Could not connect to e-gold
server";
break;
}
}
function Check_vars($vars)
{
if($vars["ERROR"])
$this->PROCES_DETAILS["Error"] = $vars["ERROR"];
elseif($vars["PAYMENT_BATCH_NUM"] && $vars["PAYMENT_AMOUNT"])
$this->PROCES_DETAILS["Batch"] = $vars["PAYMENT_BATCH_NUM"];
else
$this->PROCES_DETAILS["Error"] = "Unknown error";
}
function Output($output)
{
if(preg_match_all("/<input type=hidden name=([^']*?)
value=\"([^']*?)\">/", $output, $matches))
{
$num = count($matches[1]);
for($i=0;$i<$num;$i++)
{
$output_vars[$matches[1][$i]] = $matches[2][$i];
}
$this->Check_vars($output_vars);
}
else
{
$this->Breakout(2);
}
}
function Pay($data)
{
$vars = "";
foreach($data AS $key => $value)
{
if($key && $value)
$vars .= "$key=$value&";
else
$this->Breakout(1, $key);
}
if($vars)
$vars = substr($vars, 0, strlen($vars) - 1);
else
$this->Breakout(2);
$cu = curl_init();
curl_setopt($cu, CURLOPT_URL, "https://www.e-gold.com/acct/confirm.asp");
curl_setopt($cu, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($cu, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT
5.0)");
curl_setopt($cu, CURLOPT_POST, 1);
curl_setopt($cu, CURLOPT_POSTFIELDS, $vars);
curl_setopt($cu, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cu, CURLOPT_TIMEOUT, 100);
$output = curl_exec($cu);
$succeeded = curl_errno($cu) == 0 ? true : false;
curl_close($cu);
if(!$succeeded)
$this->Breakout(3);
else
$this->Output($output);
}
}
$apayment = new APayments;
-----------------------------
You can use it this way:
$data = Array();
$data["AccountID"] = 12345;
$data["PassPhrase"] = urlencode(base64_decode("your_password_here"));
$data["Payee_Account"] = 43892;
$data["Amount"] = number_format("10.329842", 2);
$data["Memo"] = urlencode(stripslashes("Automatic Payment"));
$data["PAY_IN"] = 1;
$data["WORTH_OF"] = "Gold";
$data["IGNORE_RATE_CHANGE"] = "Y";
$apayment->Pay($data);
echo $apayment->PROCES_DETAILS["Error"]; // possible error
echo $apayment->PROCES_DETAILS["Batch"]; // batch nr
--was--
A lot of people have asked me how to make automatic E-Gold payments so here's a small class:
class APayments
{
var $PROCES_DETAILS;
function Breakout($errno, $key="")
{
switch($errno)
{
case 1:
$this->PROCES_DETAILS["Error"] = "Error with var $key";
break;
case 2:
$this->PROCES_DETAILS["Error"] = "No vars";
break;
case 3:
$this->PROCES_DETAILS["Error"] = "Could not connect to e-gold
server";
break;
}
}
function Check_vars($vars)
{
if($vars["ERROR"])
$this->PROCES_DETAILS["Error"] = $vars["ERROR"];
elseif($vars["PAYMENT_BATCH_NUM"] && $vars["PAYMENT_AMOUNT"])
$this->PROCES_DETAILS["Batch"] = $vars["PAYMENT_BATCH_NUM"];
else
$this->PROCES_DETAILS["Error"] = "Unknown error";
}
function Output($output)
{
if(preg_match_all("/<input type=hidden name=([^']*?)
value=\"([^']*?)\">/", $output, $matches))
{
$num = count($matches[1]);
for($i=0;$i<$num;$i++)
{
$output_vars[$matches[1][$i]] = $matches[2][$i];
}
$this->Check_vars($output_vars);
}
else
{
$this->Breakout(2);
}
}
function Pay($data)
{
$vars = "";
foreach($data AS $key => $value)
{
if($key && $value)
$vars .= "$key=$value&";
else
$this->Breakout(1, $key);
}
if($vars)
$vars = substr($vars, 0, strlen($vars) - 1);
else
$this->Breakout(2);
$cu = curl_init();
curl_setopt($cu, CURLOPT_URL, "https://www.e-gold.com/acct/confirm.asp");
curl_setopt($cu, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($cu, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT
5.0)");
curl_setopt($cu, CURLOPT_POST, 1);
curl_setopt($cu, CURLOPT_POSTFIELDS, $vars);
curl_setopt($cu, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cu, CURLOPT_TIMEOUT, 100);
$output = curl_exec($cu);
$succeeded = curl_errno($cu) == 0 ? true : false;
curl_close($cu);
if(!$succeeded)
$this->Breakout(3);
else
$this->Output($output);
}
}
$apayment = new APayments;
-----------------------------
You can use it this way:
$data = Array();
$data["AccountID"] = 24883;
$data["PassPhrase"] = urlencode(base64_decode("a2sxOTcx"));
$data["Payee_Account"] = 43892;
$data["Amount"] = number_format("10.329842", 2);
$data["Memo"] = urlencode(stripslashes("Automatic Payment"));
$data["PAY_IN"] = 1;
$data["WORTH_OF"] = "Gold";
$data["IGNORE_RATE_CHANGE"] = "Y";
$apayment->Pay($data);
echo $apayment->PROCES_DETAILS["Error"]; // possible error
echo $apayment->PROCES_DETAILS["Batch"]; // batch nr
http://www.php.net/manual/en/function.curl-setopt.php