Sunteți pe pagina 1din 3

<?

php

/* ========================================== */
/* Start PayPal Recurring Button Code */
/* ========================================== */
/*
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but20.gif" b
order="0" name="submit" alt="Make payments with PayPal - it's fast, free and sec
ure!">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="john.doe@johndoe.com">
<input type="hidden" name="item_name" value="My Special Service">
<input type="hidden" name="item_number" value="SS-001">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a3" value="19.99">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="M">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
<input type="hidden" name="custom" value="19.99">
</form>
*/
/* ========================================== */
/* End PayPal Recurring button code */
/* ========================================== */

// define array to store PayPal request


// as key-value pair
$postvars = array();
// read post from PayPal into local array
while(list ($key, $value) = each ($_POST)) {
$postvars[] = $key;
}
// add a 'cmd' parameter to the parameter list that is POSTed
// back, as required by PayPal
$req = 'cmd=_notify-validate';
// append each parameter posted by the PayPal
// as name value pair to the "req" variable
for ($var = 0; $var < count ($postvars); $var++) {
$postvar_key = $postvars[$var];
$postvar_value = $$postvars[$var];
$req .= "&" . $postvar_key . "=" . urlencode ($postvar_value);
}
// post the request back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen ($req) . "\r\n\r\n";
// open file pointer to the paypal server
$fp = fsockopen ("www.paypal.com", 80, $errno, $errstr, 30);
// assign posted variables to local variables
// subscr_id
// parent_txn_id
// first_name
// last_name
// payer_business_name
// address_street
// address_city
// address_state
// address_zip
// address_country
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$userid = $_POST['custom'];
if (!$fp) {
// HTTP error
// log an error
} else {
// POST the data using the file pointer created above
fputs ($fp, $header . $req);
while (!feof($fp)) {
// read the response from the PayPal server
$res = fgets ($fp, 1024);
// check if the request has been VERIFIED by PayPal
// if it is, then you can proceed further
// if it is INVALID, then abort the process
if (strcmp ($res, "VERIFIED") == 0) {
// check the transaction type for the subscription sent by PayPal
// and take action accordingly
if(isset($_POST['txn_type'])){
if(strtolower($_POST['txn_type']) == "subscr_payment"){
// a subscriber just paid
// increase the subscription period by X days
}
else if(strtolower($_POST['txn_type']) == "subscr_cancel"){
// subscriber cancelled
}
else if(strtolower($_POST['txn_type']) == "subscr_eot"){
// subscriber reached end of term
}
}
else {
// incorrect transaction type, log an error
}
}
else if(strcmp ($res, "INVALID") == 0) {
// an INVALID transaction, log an error
}
}
}
?>

S-ar putea să vă placă și