/**
  * @test
  */
 public function processIPNWithSpecialCharacters()
 {
     $ipnData = "description=Jake's store";
     ini_set('get_magic_quotes_gpc', true);
     $ipn = new PPIPNMessage($ipnData);
     $rawData = $ipn->getRawData();
     $this->assertEquals($rawData['description'], "Jake's store");
     ini_set('get_magic_quotes_gpc', false);
     $ipn = new PPIPNMessage($ipnData);
     $rawData = $ipn->getRawData();
     $this->assertEquals($rawData['description'], "Jake's store");
     $this->assertEquals($rawData['description'], "Jake's store");
 }
<?php

/**
 * This is a sample implementation of an IPN listener
 * that uses the SDK's PPIPNMessage class to process IPNs
 * 
 * This sample simply validates the incoming IPN message
 * and logs IPN variables. In a real application, you will
 * validate the IPN and initiate some action based on the 
 * incoming IPN variables.
 */
require_once '../PPBootStrap.php';
// first param takes ipn data to be validated. if null, raw POST data is read from input stream
$ipnMessage = new PPIPNMessage(null, Configuration::getConfig());
foreach ($ipnMessage->getRawData() as $key => $value) {
    error_log("IPN: {$key} => {$value}");
}
if ($ipnMessage->validate()) {
    error_log("Success: Got valid IPN data");
} else {
    error_log("Error: Got invalid IPN data");
}
 public function actionIpn()
 {
     require_once 'paypal/PPBootStrap.php';
     $log = new Log();
     $log->description = "";
     $ipnMessage = new PPIPNMessage(null, Configuration::getConfig());
     foreach ($ipnMessage->getRawData() as $key => $value) {
         $log->description .= "IPN: {$key} => {$value}\n";
     }
     if ($ipnMessage->validate()) {
         $log->description .= "Success: Got valid IPN data\n";
         //if($ipnMessage->getRawData()['business']=='*****@*****.**') {
         if ($ipnMessage->getRawData()['business'] == '*****@*****.**') {
             $reservation = Reservation::model()->findByPk(substr($ipnMessage->getRawData()['item_number'], 3, -1));
             if (isset($reservation)) {
                 if ($ipnMessage->getRawData()['mc_gross'] == $reservation->total) {
                     if ($ipnMessage->getRawData()['payment_status'] == 'Completed') {
                         $reservation->status = 'PAID';
                         $reservation->payment_date = date('Y-m-d H:i:s', strtotime($ipnMessage->getRawData()['payment_date']));
                         $reservation->note = $ipnMessage->getRawData()['memo'];
                     } else {
                         $reservation->status = 'ERROR';
                     }
                     if ($reservation->save()) {
                         $log->description .= "reservation saved\n";
                         $subject = 'Reservación';
                         $name = $reservation->user->name . " " . $reservation->user->lastname;
                         $body = "{$name} ha hecho una reservación y ha pagado exitosamente.\n" . "Fecha llegada: " . $reservation->arrival_date . "\n" . "Fecha salida: " . $reservation->departure_date . "\n" . "Max # personas: " . $reservation->number_people . "\n" . "Nota: " . $reservation->note . "\n" . "Total: \$" . $reservation->total;
                         $headers = "From: {$name} <*****@*****.**>\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/plain; charset=UTF-8";
                         mail(Yii::app()->params['adminEmail'], $subject, $body, $headers);
                         $log->description .= "email sent\n";
                         $subject = 'Reservación EdenBlue';
                         $name = $reservation->user->name . " " . $reservation->user->lastname;
                         $body = "Has hecho una reservación y ha pagado exitosamente. Ahora puedes dirigirte a nuestras instalaciones.\n" . "Fecha llegada: " . $reservation->arrival_date . "\n" . "Fecha salida: " . $reservation->departure_date . "\n" . "Max # personas: " . $reservation->number_people . "\n" . "Total: \$" . $reservation->total;
                         $headers = "From: EdenBlue <*****@*****.**>\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/plain; charset=UTF-8";
                         mail($ipnMessage->getRawData()['payer_email'], $subject, $body, $headers);
                         $log->description .= "email sent to payer\n";
                     } else {
                         $log->description .= "reservation no saved\n";
                     }
                 } else {
                     $log->description .= "bad total amount\n";
                 }
             } else {
                 $log->description .= "reservation not found\n";
             }
         } else {
             $log->description .= "bad receiver_id\n";
         }
     } else {
         $log->description .= "Error: Got invalid IPN data";
     }
     $log->creation_date = date('Y-m-d H:i:s');
     if ($log->save()) {
         echo "saved";
     } else {
         echo "no saved";
     }
 }
 public function ipn($id = null)
 {
     //$products = $this->products;
     //$product = $products[$id];
     $ipn_message = new PPIPNMessage(null, $this->pp_settings);
     $raw_data = $ipn_message->getRawData();
     if (!$ipn_message->validate()) {
         return false;
     }
     foreach ($raw_data as $key => $value) {
         //error_log("IPN: $key => $value");
     }
     //error_log("-----------------------------end ipn------------------------------");
     $txn_id = isset($raw_data['parent_txn_id']) ? $raw_data['parent_txn_id'] : $raw_data['txn_id'];
     $txn_id = isset($raw_data['recurring_payment_id']) ? $raw_data['recurring_payment_id'] : $txn_id;
     $_POST['sctxnid'] = $txn_id;
     switch ($raw_data['txn_type']) {
         //anything related to recurring, we follow
         //the profiles status
         case 'recurring_payment_profile_created':
         case 'subscr_signup':
         case 'recurring_payment':
         case 'recurring_payment_skipped':
         case 'subscr_modify':
         case 'subscr_payment':
         case 'recurring_payment_profile_cancel':
         case 'recurring_payment_expired':
         case 'recurring_payment_failed':
         case 'recurring_payment_suspended_due_to_max_failed_payment':
         case 'recurring_payment_suspended':
         case 'subscr_cancel':
         case 'subscr_eot':
         case 'subscr_failed':
             switch ($raw_data['profile_status']) {
                 case 'Active':
                     $this->wlm->ShoppingCartReactivate();
                     break;
                 case 'Suspended':
                 case 'Cancelled':
                     $this->wlm->ShoppingCartDeactivate();
                     break;
                 default:
                     //ignore
                     break;
             }
             //were done
             return;
             break;
     }
     // this is a one time payment
     switch ($raw_data['payment_status']) {
         case 'Completed':
             if (isset($raw_data['echeck_time_processed'])) {
                 $this->wlm->ShoppingCartReactivate(1);
             } else {
                 $this->wlm->ShoppingCartRegistration(null, false);
                 $this->wlm->CartIntegrationTerminate();
             }
             break;
         case 'Canceled-Reversal':
             $this->wlm->ShoppingCartReactivate();
             break;
         case 'Processed':
             $this->wlm->ShoppingCartReactivate('Confirm');
             break;
         case 'Expired':
         case 'Failed':
         case 'Refunded':
         case 'Reversed':
             $this->wlm->ShoppingCartDeactivate();
             break;
     }
 }
 /**
  *  Check if ipn request is valid or not
  *
  *  @return boolean true/false
  */
 function check_ipn_response()
 {
     if ('yes' == $this->testmode) {
         $config = array('mode' => 'sandbox');
     } else {
         $config = array('mode' => 'live');
     }
     $ipnMessage = new PPIPNMessage(null, $config);
     if ($ipnMessage->validate()) {
         $this->add_log('IPN Response: ' . print_r($ipnMessage->getRawData(), true));
         do_action("dokan-valid-paypal-adaptive-request");
     } else {
         $this->add_log('Received invalid response from PayPal Adaptive Payment');
         if (is_wp_error($ipnMessage)) {
             $this->add_log('Error response: ' . $ipnMessage->get_error_message());
         }
     }
 }