Created
March 7, 2012 07:54
-
-
Save matfish2/1991773 to your computer and use it in GitHub Desktop.
PHP: Paypal IPN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> | |
<input name="amount" type="hidden" value="COMBIEN_CA_COUTE" /> | |
<input name="currency_code" type="hidden" value="EUR" /> | |
<input name="shipping" type="hidden" value="0.00" /> | |
<input name="tax" type="hidden" value="0.00" /> | |
<input name="return" type="hidden" value="URL_DE_SUCCES" /> | |
<input name="cancel_return" type="hidden" value="URL_ANNULATION" /> | |
<input name="notify_url" type="hidden" value="URL_NOTIFICATION_PAIEMENT" /> | |
<input name="cmd" type="hidden" value="_xclick" /> | |
<input name="business" type="hidden" value="IDENTIFIANT_VENDEUR" /> | |
<input name="item_name" type="hidden" value="CE QUE JE VENDS" /> | |
<input name="no_note" type="hidden" value="1" /> | |
<input name="lc" type="hidden" value="FR" /> | |
<input name="bn" type="hidden" value="PP-BuyNowBF" /> | |
<input name="custom" type="hidden" value="var1=1&var2=lol" /> | |
<input type="submit" value="S'abonner" class="btn primary"> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//permet de traiter le retour ipn de paypal | |
$email_account = "[email protected]"; | |
$req = 'cmd=_notify-validate'; | |
foreach ($_POST as $key => $value) { | |
$value = urlencode(stripslashes($value)); | |
$req .= "&$key=$value"; | |
} | |
$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"; | |
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); | |
$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']; | |
parse_str($_POST['custom'],$custom); | |
if (!$fp) { | |
} else { | |
fputs ($fp, $header . $req); | |
while (!feof($fp)) { | |
$res = fgets ($fp, 1024); | |
if (strcmp ($res, "VERIFIED") == 0) { | |
// vérifier que payment_status a la valeur Completed | |
if ( $payment_status == "Completed") { | |
if ( $email_account == $receiver_email) { | |
/** | |
* C'EST LA QUE TOUT SE PASSE | |
* PS : tjrs penser à vérifier la somme !! | |
*/ | |
/** | |
* FIN CODE | |
*/ | |
} | |
} | |
else { | |
// Statut de paiement: Echec | |
} | |
exit(); | |
} | |
else if (strcmp ($res, "INVALID") == 0) { | |
// Transaction invalide | |
} | |
} | |
fclose ($fp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment