<?php
// ---------------------//
// return data from CB: //
// ---------------------//
    // IPN version 1.0 //
$ccustname            = $_REQUEST['ccustname'];
$ccustemail           = $_REQUEST['ccustemail'];
$ccustcc              = $_REQUEST['ccustcc'];
$ccuststate           = $_REQUEST['ccuststate'];
$ctransreceipt        = $_REQUEST['ctransreceipt']; 
$cproditem            = $_REQUEST['cproditem'];
$ctransaction         = $_REQUEST['ctransaction'];
$ctransaffiliate      = $_REQUEST['ctransaffiliate'];
$ctranspublisher      = $_REQUEST['ctranspublisher'];
$cprodtype            = $_REQUEST['cprodtype'];
$cprodtitle           = $_REQUEST['cprodtitle'];
$ctranspaymentmethod  = $_REQUEST['ctranspaymentmethod'];
$ctransamount         = $_REQUEST['ctransamount'];
$caffitid             = $_REQUEST['caffitid'];
$cvendthru            = $_REQUEST['cvendthru'];
$cverify              = $_REQUEST['cverify'];
// IPN version 2.0 //
$ccustfullname        = $_REQUEST['ccustfullname'];
$ccustfirstname       = $_REQUEST['ccustfirstname'];
$ccustlastname        = $_REQUEST['ccustlastname'];
$ccustzip             = $_REQUEST['ccustzip'];
$ccustaddr1           = $_REQUEST['ccustaddr2'];
$ccustaddr2           = $_REQUEST['ccustaddr2'];
$ccustcity            = $_REQUEST['ccustcity'];
$ccustcounty          = $_REQUEST['ccustcounty'];
$ccustshippingzip     = $_REQUEST['ccustshippingzip'];
$ccustshippingcountry = $_REQUEST['ccustshippingcountry'];
$caccountamount       = $_REQUEST['caccountamount'];
$corderamount         = $_REQUEST['corderamount'];
$ccurrency            = $_REQUEST['ccurrency'];
$ctransrole           = $_REQUEST['ctransrole'];
$cupsellreceipt       = $_REQUEST['cupsellreceipt'];
$crebillamnt          = $_REQUEST['crebillamnt'];
$cprocessedpayments   = $_REQUEST['cprocessedpayments'];
$cfuturepayments      = $_REQUEST['cfuturepayments'];
$cnextpaymentdate     = $_REQUEST['cnextpaymentdate'];
$crebillstatus        = $_REQUEST['crebillstatus'];
$ctid                 = $_REQUEST['ctid'];
$ctranstime           = $_REQUEST['ctranstime'];

if($ctransamount=="" && $caccountamount!="") { $ctransamount = $caccountamount; }
if($ccustname=="" && $ccustfullname!="") { $ccustname = $ccustfullname; }
$ccustname = stripslashes($ccustname);
if($ctid == "" && $caffitid!="") { $ctid = $caffitid; }
$amount = ($ctransamount/100);
$amount2 = ($caccountamount/100);
$amount3 = ($corderamount/100);

$trackmsg = "
------------- TRACKING/MISC --------------
Tracking ID : $ctid  (ctid)
Epoch Time  : $ctranstime (epoch time transaction occurred. Not inc. in cverify)
CVerify     : $cverify\n\n
$vendstring
";

$msg="ClickBank IPN version $ipn_version: 
Customer Information:\n---------------------
Name        : $ccustname
Email       : $ccustemail
Receipt     : $ctransreceipt
Item        : $cproditem
ProductName : $cprodtitle
Amount      : $amount
Affiliate   : $ctransaffiliate
Publisher   : $ctranspublisher

------------- BILLING DETAILS ------------
Amount Rcvd       : $amount2
Amount Retail     : $amount3
Amount Rebill     : $crebillamnt
Rebill Status     : $crebillstatus
Currency          : $ccurrency
Recipient Role    : $ctransrole
Upsell Parent Inv : $cupsellreceipt
ProductType       : $cprodtype
Transaction       : $ctransaction
Payment Mthd      : $ctranspaymentmethod
Recurring Num#    : $cprocessedpayments
Recurring future  : $cfuturepayments (num of payments remaining)
Next Payment date : $cnextpaymentdate

------------- SHIPPING/ADDR --------------
Addr #1           : $ccustaddr1
Addr #2           : $ccustaddr2
ZIP               : $ccustzip
City              : $ccustcity
Country           : $ccustcc
State             : $ccuststate
Shipping Zip      : $ccustshippingzip
Shipping County   : $ccustcounty
Shipping Country  : $ccustshippingcountry

$trackmsg 
--------------------------------------
SubscriptionMate System Generated Mesg
---------------------------------------
";

// ----------------------//
// ClickBank POP Routine //
// ----------------------//
function cbValid($key) {
  $key=$key;
  $ccustname = $_REQUEST['ccustname'];
  $ccustemail = $_REQUEST['ccustemail'];
  $ccustcc = $_REQUEST['ccustcc'];
  $ccuststate = $_REQUEST['ccuststate'];
  $ctransreceipt = $_REQUEST['ctransreceipt'];
  $cproditem = $_REQUEST['cproditem'];
  $ctransaction = $_REQUEST['ctransaction'];
  $ctransaffiliate = $_REQUEST['ctransaffiliate'];
  $ctranspublisher = $_REQUEST['ctranspublisher'];
  $cprodtype = $_REQUEST['cprodtype'];
  $cprodtitle = $_REQUEST['cprodtitle'];
  $ctranspaymentmethod = $_REQUEST['ctranspaymentmethod'];
  $ctransamount = $_REQUEST['ctransamount'];
  $caffitid = $_REQUEST['caffitid'];
  $cvendthru = $_REQUEST['cvendthru'];
  $cbpop = $_REQUEST['cverify'];

$xxpop = sha1("$ccustname|$ccustemail|$ccustcc|$ccuststate|$ctransreceipt|$cproditem|$ctransaction|"."$ctransaffiliate|$ctranspublisher|$cprodtype|$cprodtitle|$ctranspaymentmethod|$ctransamount|$caffitid|$cvendthru|$key");

$xxpop=strtoupper(substr($xxpop,0,8));

// DEBUG //
/*
$err_pop = "
  key=$key
  ccustname = $ccustname
  ccustemail = $ccustemail
  ccustcc = $ccustcc
  ccuststate = $ccuststate
  ctransreceipt = $ctransreceipt
  cproditem = $cproditem
  ctransaction = $ctransaction
  ctransaffiliate = $ctransaffiliate
  ctranspublisher = $ctranspublisher
  cprodtype = $cprodtype
  cprodtitle = $cprodtitle
  ctranspaymentmethod = $ctranspaymentmethod
  ctransamount = $ctransamount
  caffitid = $caffitid
  cvendthru = $cvendthru
  cbpop = $cverify
  -----------------
  XXPOP: $xxpop
  CBPOP: $cbpop";
  */
// ----------- end DEBUG -------------//


  if ($cbpop==$xxpop) {
    return (1);
  } else {
    //return($err_pop);
    return(0);
  }
}
?>