Ejemplo n.º 1
0
 public function ipnPostSubmit()
 {
     // Give PAP access to the data so it can handle any needed commissions
     try {
         $papModel = Mage::getModel('pap/pap');
         $postData = $this->getIpnFormData();
         $customdata = explode('~~~a469ccb0-767c-4fed-96de-99427e1783aa~~~', $postData['custom']);
         $saleData = isset($customdata[0]) ? $customdata[0] : null;
         $cookieValue = isset($customdata[1]) ? $customdata[1] : null;
         // Convert the JSON data into a usable array
         $saleData = json_decode($saleData);
         $saleData = $this->ForceArray($saleData);
         $sReq = '';
         foreach ($this->getIpnFormData() as $k => $v) {
             $sReq .= '&' . $k . '=' . urlencode(stripslashes($v));
         }
         //append ipn commdn
         $sReq .= "&cmd=_notify-validate";
         $sReq = substr($sReq, 1);
         $http = new Varien_Http_Adapter_Curl();
         $http->write(Zend_Http_Client::POST, $this->getPaypalUrl(), '1.1', array(), $sReq);
         $response = $http->read();
         $response = preg_split('/^\\r?$/m', $response, 2);
         $response = trim($response[1]);
         if ($response == 'VERIFIED') {
             $papModel->registerSaleDetails($saleData, isset($cookieValue) ? $cookieValue : null);
         }
     } catch (Exception $e) {
         Mage::log('Caught exception while trying to log PayPal sale: ' . $e->getMessage() . "\n");
     }
     // let the base class go on to do whatever processing it was going to do
     parent::ipnPostSubmit();
 }
Ejemplo n.º 2
0
 /**
  * Listen for subscription IPN data
  * @return
  */
 public function ipnPostSubmit()
 {
     $IPN = $this->getIpnFormData();
     if (isset($IPN['subscr_id'])) {
         if ($Subscription = Mage::getModel('sarp/subscription')->load($IPN['subscr_id'], 'real_id')) {
             $Order = $Subscription->getLastOrder();
             if (!$Order instanceof Mage_Sales_Model_Order) {
                 $Subscription->log("Can't load last order for subscription #{$Subscription->getId()}");
             }
             switch ($IPN['txn_type']) {
                 case 'subscr_cancel':
                     // Cancel subscription
                     $Subscription->setStatus(AW_Sarp_Model_Subscription::STATUS_CANCELED)->save();
                     // Set last oder status as canceled
                     if ($Order) {
                         $Order->registerCancellation('Subscrition #{$Subscription->getId()} canceled at PayPal by IPN', true);
                     }
                     break;
                 case 'subscr_eot':
                     // End Of time
                     $Subscription->setStatus(AW_Sarp_Model_Subscription::STATUS_EXPIRED)->save();
                     // Set last oder status as canceled
                     if ($Order) {
                         $Order->registerCancellation('Subscrition #{$Subscription->getId()} expired at PayPal by IPN', true);
                     }
                     break;
                 case 'subscr_failed':
                     // Failed
                     $Subscription->setStatus(AW_Sarp_Model_Subscription::STATUS_SUSPENDED)->save();
                     // Set last oder status as canceled
                     if ($Order) {
                         $Order->registerCancellation('Subscrition #{$Subscription->getId()} failed at PayPal by IPN', true);
                     }
                     break;
                 default:
                     // Success
                     if ($Order) {
                         $Order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true, Mage::helper('sarp')->__('Subscription payment successfully processed at PayPal'), true)->save();
                     }
             }
         }
     }
     return parent::ipnPostSubmit();
 }