Hi.. I find someone to help me to create Safepaysolutions.com Payment Module..
and for Soeren... have any idea about this scripts?
The scripts following attach bellow..
<?php
$EMAIL_WHERE_TO_SEND_POST_DATA1 = "1st-email-to-notify@yourdomain.com";
$EMAIL_WHERE_TO_SEND_POST_DATA2 = "2nd-email-to-notify@yourdomain.com";
// PLEASE EDIT THE EMAIL_WHERE_TO_SEND_POST_DATA FIELDS ABOVE!
$fp = fopen("_notify_post.log", "a");
fwrite($fp, "\n\nEXECUTED: " . date("m/d/y h:i:s") . "\n");
$s = "";
foreach($_REQUEST as $k=>$v){
$s .= "$k=$v&";
fwrite($fp, "$k=$v\n");
if($k == "notifyEml") $EMAIL_WHERE_TO_SEND_POST_DATA = $v;
}
fwrite($fp, "\nQUERY: $s\n\n");
fclose($fp);
@mail($EMAIL_WHERE_TO_SEND_POST_DATA1, "POST DATA FROM SPS NOTIFY SCRIPT", $s, "System");
@mail($EMAIL_WHERE_TO_SEND_POST_DATA2, "POST DATA FROM SPS NOTIFY SCRIPT", $s, "System");
if(isset($EMAIL_WHERE_TO_SEND_POST_DATA) && strlen($EMAIL_WHERE_TO_SEND_POST_DATA) > 0) @mail($EMAIL_WHERE_TO_SEND_POST_DATA, "POST DATA FROM SPS NOTIFY SCRIPT", $s, "System");
$passPhraseLocal = "test";
/**
* If you want to log errors just set this report type to:
* "log-file" - if you want to log into file (if this option setted then define $lofFile value below)
* "output" - just prints log to the default output
* Leave it blank if you don't want to log
*/
$reportType = "log-file";
/**
* If you setted $reportType = "log-file" then define log filename here
*/
$logFile = "sps_notify.log";
$confirmUsing = "curl"; // values: "curl" or "socket"
///////////////////////////////////////////////////////////////////////
function report($str){
global $reportType, $rfp;
switch($reportType){
case "log-file":
if($rfp) fwrite($rfp, $str);
break;
case "output":
print $str;
break;
default:
break;
}
}
function confirmTransaction(){
global $confirmUsing, $confirmScript, $confirmationID, $transactionID, $totalAmount;
$confirmScriptFull = $confirmScript["host"] . "/" . $confirmScript["path"];
if(isset($confirmationID) && is_numeric($confirmationID) && $confirmationID > 0){
$data = "confirmID=$confirmationID&trid=$transactionID&amount=$totalAmount";
if($confirmUsing == "curl"){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $confirmScriptFull);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$answer = curl_exec($ch);
$curlErr = curl_error($ch);
if(strlen($curlErr) > 0) report("CURL ERROR on <$confirmScriptFull>: " . $curlErr . "\n");
curl_close($ch);
report("Confirmation script answer: " . $answer . "\n");
if(strlen($answer) > 0 && strpos($answer, "SUCCESS") !== false) $answer = 1;
else $answer = 0;
}
elseif($confirmUsing == "socket"){
if($confirmScript["ssl"]){
$port = "443";
$ssl = "ssl://";
}
else $port = "80";
$fp = @fsockopen($ssl . $confirmScript["host"], $port, $errnum, $errstr, 30);
if(!$fp){
report("SOCKET ERROR! $errnum: $errstr\n");
$answer = 0;
}
else{
fputs($fp, "POST {$confirmScript[path]} HTTP/1.1\r\n"); // PATH
fputs($fp, "Host: {$confirmScript[host]}\r\n"); // HOST
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($data)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data . "\r\n\r\n");
while(!feof($fp)) $answer .= @fgets($fp, 1024);
fclose($fp);
report("Confirmation script answer: " . $answer . "\n");
if(strlen($answer) > 0 && strpos($answer, "SUCCESS") !== false) $answer = 1;
else $answer = 0;
}
}
}
else $answer = 1;
return $answer;
}
// TEST MODE FLAG: 'on' for TEST mode, 'off' or empty for REAL TRANSACTION mode
$itestmode = $_REQUEST["itestmode"];
// type: '_ipn_payment' for purchases and '_ipn_subscription' for subscriptions
$_ipn_act = $_REQUEST["_ipn_act"];
// result code (1 - success, 0 - failure)
$result = $_REQUEST["result"];
// your SPS username
$receiver = $_REQUEST["ireceiver"];
// buyer's SPS username
$payer = $_REQUEST["ipayer"];
// service / product cost
$amount = $_REQUEST["iamount"];
// the MD5 hash of your secret passphrase (Note: MD5 Hash code will be all UPPERCASE!)
$passPhrase = $_REQUEST["passPhrase"];
// product/service name
$itemName = $_REQUEST["itemName"];
// product/service id
$itemNum = $_REQUEST["itemNum"];
// product/service description
$itemDescr = $_REQUEST["idescr"];
// custom fields
$custom1 = $_REQUEST["custom1"];
$custom2 = $_REQUEST["custom2"];
$custom3 = $_REQUEST["custom3"];
$custom4 = $_REQUEST["custom4"];
$custom5 = $_REQUEST["custom5"];
if($_ipn_act == '_ipn_payment' || !isset($_ipn_act) || strlen($_ipn_act) == 0){
// product/service quantity
$itemQuantity = $_REQUEST["iquantity"];
// if REAL TRANSACTION MODE,
// getting some specific only for this mode variables
if($itestmode != 'on'){
// confirmation ID
$confirmationID = $_REQUEST["confirmID"];
// transaction ID
$transactionID = $_REQUEST["tid"];
}
// shipping / physical product delivery:
// 1 - no physically delivered product
// 2 - optional physical delivery
// 3 - shipping required
$deliveryRequirement = $_REQUEST["idelivery"];
// shipping information (only if delivery required)
if($deliveryRequirement == '2' || $deliveryRequirement == '3'){
$shippingAddress = $_REQUEST["ishaddress"];
$shippingCity = $_REQUEST["ishcity"];
$shippingState = $_REQUEST["ishstate"];
$shippingZip = $_REQUEST["ishzip"];
$shippingCountry = $_REQUEST["ishcountry"];
}
}
elseif($_ipn_act == '_ipn_subscription'){
$cycleLength = $_REQUEST["cycleLength"];
$cycles = $_REQUEST["cycles"];
$trialPeriod = $_REQUEST["trialPeriod"];
$trialAmount = $_REQUEST["trialAmount"];
$trialCycles = $_REQUEST["trialCycles"];
if($itestmode != 'on'){
$transactionID = $_REQUEST["tid"];
}
}
$confirmScript = array(
"host" => "https://www.safepaysolutions.com",
"path" => "index.php",
"ssl" => 1 // 1 for https, 0 for http
);
if($reportType == "log-file") $rfp = fopen($logFile, "a");
$error = false;
report("\n\nEXECUTION TIME: " . date("m/d/y h:i:s") . "\n");
// if the result code is 1 then payment succesfull, but don't forget
// to check the secret passphrase (if it is defined in your SPS backoffice)
if($result == 1 && ($_ipn_act == '_ipn_payment' || !isset($_ipn_act) || strlen($_ipn_act) == 0)){
// checking secret passphrase
if(isset($passPhraseLocal) && (strlen($passPhraseLocal) > 0) && (strtoupper(md5($passPhraseLocal)) != $passPhrase)){
report("Secret passphrase error\n");
$error = true;
}
// checking amount format
if(!is_numeric($amount) || $amount < 0){
report("Amount error ($amount)\n");
$error = true;
}
// checking quantity format
if(!is_numeric($itemQuantity) || $itemQuantity < 0){
report("Item quantity error ($itemQuantity)\n");
$error = true;
}
if($itestmode != 'on' && (!isset($transactionID) || strlen($transactionID) == 0 || !preg_match("/^([0-9]){8}-([0-9]){1,}$/", $transactionID))){
report("Transaction ID error ($transactionID)\n");
$error = true;
}
// checking finished, POST data looks good
if($error === false){
// calculation total amount
$totalAmount = $amount*$itemQuantity;
if($itestmode != 'on'){
$confirmed = confirmTransaction();
if($confirmed == 1){
// everything is ok, payment is good
report("Everything looks ok, money on your SPS account (purchase)\n");
// ...
// ...
// ...
}
else{
// transaction not confirmed, money is not on your SPS account
report("Transaction not confirmed, money is not on your SPS account\n");
// ...
// ...
// ...
}
}
else{
// everything is ok, TEST TRANSACTION, actual charged amount is $0.00!!!
report("Everything is ok. TEST PURCHASE!\n");
// ...
// ...
// ...
}
}
}
elseif($result == 1 && $_ipn_act == '_ipn_subscription'){
// checking secret passphrase
if(isset($passPhraseLocal) && (strlen($passPhraseLocal) > 0) && (strtoupper(md5($passPhraseLocal)) != $passPhrase)){
report("Secret passphrase error\n");
$error = true;
}
// checking amount format
if(!is_numeric($amount) || $amount < 0){
report("Amount error ($amount)\n");
$error = true;
}
// checking finished, POST data looks good
if($error === false){
if($itestmode != 'on'){
// everything is ok, subscription is good
report("Everything looks ok (subscription)\n");
// ...
// ...
// ...
}
else{
// everything is ok, TEST TRANSACTION, actual charged amount is $0.00!!!
report("Everything is ok. TEST SUBSCRIPTION!\n");
// ...
// ...
// ...
}
}
}
else{
report("Result Code $result: Payment Error\n");
}
if($reportType == "log-file" && $rfp) fclose($rfp);
?>
Thank you,
Deep Nuke
have you managed to get it to work, if you have please let me know.
Thank you
John