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'); }
public function action_complete() { // Get the transaction details. $fetch = $this->_gateway->fetchTransaction($this->_payment_vars())->send(); $data = $fetch->getData(); // Add the buyer email to parameters. $parameters = $this->_payment_vars() + array('email' => $data['EMAIL']); /** @var Payment_PayPal_CreateRecurringPaymentsRequest $request */ $request = $this->_gateway->createRecurringPaymentsProfile($parameters); // Overwrite Item Category. $data = $request->getData(); $data['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = $this->_config['itemCategory']; /** @var Omnipay\PayPal\Message\ExpressAuthorizeResponse $response */ $response = $request->sendData($data); if ($response->isSuccessful()) { $response_data = $response->getData(); // Get the transaction details. // $fetch = $this->_gateway->fetchTransaction($this->_payment_vars())->send(); // $data = $fetch->getData(); ORM::factory('Payment_Subscription')->values(array('user_id' => $this->user->id, 'package_id' => $this->_package->id, 'status' => Model_Payment_Subscription::PENDING, 'recurring_payment_id' => $response_data['PROFILEID']))->create(); Hint::success(Kohana::message('payment', 'payment.success')); $this->redirect(Route::get('payment')->uri()); } else { // Log the error. Kohana::$log->add(Log::ERROR, IPN::array_to_string($response->getData())); throw HTTP_Exception::factory('403', 'Something went wrong, no cash should have been drawn, if the error proceeds contact support!'); } }
/** * Return the user from paypal, and process the payment. * * @throws HTTP_Exception */ public function action_complete() { /** @var Omnipay\PayPal\Message\ExpressAuthorizeResponse $response */ $response = $this->_gateway->completePurchase($this->_payment_vars())->send(); if ($response->isSuccessful()) { // Get the transaction details. $fetch = $this->_gateway->fetchTransaction($this->_payment_vars())->send(); $data = $fetch->getData(); $transaction = ORM::factory('Payment_Transaction')->where('TOKEN', '=', $data['TOKEN'])->find(); // Update the transaction with the buyers information. $transaction->values(array('status' => 'completed', 'email' => $data['EMAIL'], 'first_name' => $data['FIRSTNAME'], 'last_name' => $data['LASTNAME'], 'country' => $data['COUNTRYCODE']))->save(); // Give the player the rewards. foreach ($this->_package->rewards as $key => $value) { $reward = Payment_Reward::factory($key, $value); $reward->reward($this->user); } $this->user->save(); Hint::success(Kohana::message('payment', 'payment.success')); $this->redirect(Route::get('payment')->uri()); } else { // Log the error. Kohana::$log->add(Log::ERROR, IPN::array_to_string($response->getData())); throw HTTP_Exception::factory('403', 'Something went wrong, no cash should have been drawn, if the error proceeds contact support!'); } }