Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Paypal_ipn extends CI_Controller {
- public function index() {
- // read the post from PayPal system and add 'cmd'
- $req = 'cmd=_notify-validate';
- $header = null;
- foreach ($_POST as $key => $value) {
- $value = urlencode(stripslashes($value));
- $req .= "&$key=$value";
- }
- // post 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";
- $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
- // assign posted variables to local variables
- //$item_name = $_POST['item_name'];
- //$item_number = $_POST['item_number'];
- if(isset($_POST['payment_status'])) {
- $payment_status = $_POST['payment_status'];
- }
- if(isset($_POST['mc_gross'])) {
- $payment_amount = $_POST['mc_gross'];
- }
- if(isset($_POST['mc_currency'])) {
- $payment_currency = $_POST['mc_currency'];
- }
- if(isset($_POST['txn_id'])) {
- $txn_id = $_POST['txn_id'];
- }
- if(isset($_POST['invoice'])) {
- $invoice = $_POST['invoice'];
- }
- if(isset($_POST['payment_date'])) {
- $payment_date = $_POST['payment_date']; // This is in PST timezone
- }
- if(isset($_POST['payment_type'])) {
- $payment_type = $_POST['payment_type'];
- }
- if(isset($_POST['pending_reason'])) {
- $pending_reason = $_POST['pending_reason'];
- }
- if(isset($_POST['receiver_email'])) {
- $receiver_email = $_POST['receiver_email'];
- }
- if(isset($_POST['payer_email'])) {
- $payer_email = $_POST['payer_email'];
- }
- if(isset($_POST['first_name'])) {
- $first_name = $_POST['first_name'];
- }
- if(isset($_POST['last_name'])) {
- $last_name = $_POST['last_name'];
- }
- //$trackingId = $_POST['trackingId'];
- //$payment_fee = $_POST['mc_fee'];
- //$contact_phone = $_POST['contact_phone'];
- if (!$fp) {
- // HTTP ERROR
- } else {
- fputs ($fp, $header . $req);
- while (!feof($fp)) {
- $res = fgets ($fp, 1024);
- if (strcmp ($res, "VERIFIED") == 0) {
- log_message('error', "*********************************");
- $log = var_export($_POST, true);
- $log = str_replace(array("\r","\n"), '', $log);
- log_message('error', $log);
- log_message('error', "*********************************");
- //log_message('error', "<pre>$_POST</pre>");
- log_message('error', "invoice = $invoice");
- //log_message('error', "tracking_id = $trackingId");
- log_message('error', "payment_status = $payment_status");
- log_message('error', "payment_amount = $payment_amount");
- //log_message('error', "payment_fee = $payment_fee");
- log_message('error', "payment_type = $payment_type");
- log_message('error', "payment_currency = $payment_currency");
- log_message('error', "payment_date = $payment_date");
- log_message('error', "pending_reason = $pending_reason");
- log_message('error', "first_name = $first_name");
- log_message('error', "last_name = $last_name");
- //log_message('error', "contact_phone = $contact_phone");
- log_message('error', "txn_id = $txn_id");
- log_message('error', "receiver_email = $receiver_email");
- log_message('error', "payer_email = $payer_email");
- // check the payment_status is Completed
- // check that txn_id has not been previously processed
- // check that receiver_email is your Primary PayPal email
- // check that payment_amount/payment_currency are correct
- // process payment
- }
- else if (strcmp ($res, "INVALID") == 0) {
- log_message('error', "Problem with IPN. res = $res");
- }
- }
- fclose ($fp);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement