示例#1
0
 public function action_index()
 {
     // Log the output
     Kohana::$log->add(Log::DEBUG, IPN::array_to_string($this->request->post()));
     $this->_IPN = new IPN();
     $this->_IPN->process($this->request->post());
     // If the request did not come from PayPal show a 404 page.
     if (!$this->_IPN->is_verified()) {
         throw HTTP_Exception::factory('404', 'File not found!');
     }
     // TODO: We want to log all IPN actions and ensure we do not process the same action TWICE!
     // Find the correct subscription.
     $this->_subscription = ORM::factory('Payment_Subscription')->where('recurring_payment_id', '=', $this->_IPN->get_data('recurring_payment_id'))->find();
     Kohana::$log->add(Log::DEBUG, $this->_IPN->get_transaction_type());
     switch ($this->_IPN->get_transaction_type()) {
         case IPN::RECURRING_PAYMENT_PROFILE_CREATED:
             Kohana::$log->add(Log::DEBUG, 'PROFILE CREATED');
             $this->_profile_created();
             break;
         case IPN::RECURRING_PAYMENT:
             Kohana::$log->add(Log::DEBUG, 'PAYMENT RECEIVED');
             $this->_payment();
             break;
         case IPN::RECURRING_PAYMENT_PROFILE_CANCEL:
             Kohana::$log->add(Log::DEBUG, 'PROFILE CANCEL');
             $this->_profile_cancel();
             break;
     }
     $this->response->status(200);
     $this->response->body('OK');
 }