Permalink
Browse files

Formatting

  • Loading branch information...
1 parent 320dafc commit 6218bbecc1e492e2aad8fdf74c7019d150b6032e @josegonzalez josegonzalez committed Oct 2, 2011
@@ -4,84 +4,84 @@ class InstantPaymentNotificationsController extends PaypalIpnAppController {
var $name = 'InstantPaymentNotifications';
var $helpers = array('Html', 'Form');
var $components = array('Email');
-
- /**
- * beforeFilter makes sure the process is allowed by auth
- * since paypal will need direct access to it.
- */
+
+/**
+ * beforeFilter makes sure the process is allowed by auth
+ * since paypal will need direct access to it.
+ */
function beforeFilter(){
- parent::beforeFilter();
- if(isset($this->Auth)){
- $this->Auth->allow('process');
- }
- if(isset($this->Security) && $this->action == 'process'){
- $this->Security->validatePost = false;
- }
+ parent::beforeFilter();
+ if (isset($this->Auth)) {
+ $this->Auth->allow('process');
+ }
+ if (isset($this->Security) && $this->action == 'process') {
+ $this->Security->validatePost = false;
+ }
+ }
+
+/**
+ * Paypal IPN processing action..
+ * This action is the intake for a paypal_ipn callback performed by paypal itself.
+ * This action will take the paypal callback, verify it (so trickery) and save the transaction into your database for later review
+ *
+ * @access public
+ * @author Nick Baker
+ */
+ function process() {
+ if ($this->InstantPaymentNotification->isValid($_POST)) {
+ $notification = $this->InstantPaymentNotification->buildAssociationsFromIPN($_POST);
+ $this->InstantPaymentNotification->saveAll($notification);
+ $this->__processTransaction($this->InstantPaymentNotification->id);
+ }
+ $this->redirect('/');
}
-
- /**
- * Paypal IPN processing action..
- * This action is the intake for a paypal_ipn callback performed by paypal itself.
- * This action will take the paypal callback, verify it (so trickery) and save the transaction into your database for later review
- *
- * @access public
- * @author Nick Baker
- */
- function process(){
- if($this->InstantPaymentNotification->isValid($_POST)){
- $notification = $this->InstantPaymentNotification->buildAssociationsFromIPN($_POST);
- $this->InstantPaymentNotification->saveAll($notification);
- $this->__processTransaction($this->InstantPaymentNotification->id);
- }
- $this->redirect('/');
- }
-
- /**
- * __processTransaction is a private callback function used to log a verified transaction
- * @access private
- * @param String $txnId is the string paypal ID and the id used in your database.
- */
- private function __processTransaction($txnId){
- $this->log("Processing Trasaction: $txnId",'paypal');
- //Put the afterPaypalNotification($txnId) into your app_controller.php
- $this->afterPaypalNotification($txnId);
- }
-
- /**
- * Admin Only Functions... all baked
- */
-
- /**
- * Admin Index
- */
- function admin_index() {
+
+/**
+ * __processTransaction is a private callback function used to log a verified transaction
+ * @access private
+ * @param String $txnId is the string paypal ID and the id used in your database.
+ */
+ private function __processTransaction($txnId){
+ $this->log("Processing Trasaction: {$txnId}", 'paypal');
+ //Put the afterPaypalNotification($txnId) into your app_controller.php
+ $this->afterPaypalNotification($txnId);
+ }
+
+/**
+ * Admin Only Functions... all baked
+ */
+
+/**
+ * Admin Index
+ */
+ function admin_index() {
$this->InstantPaymentNotification->recursive = 0;
$this->set('instantPaymentNotifications', $this->paginate());
}
- /**
- * Admin View
- * @param String ID of the transaction to view
- */
+/**
+ * Admin View
+ * @param String ID of the transaction to view
+ */
function admin_view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid InstantPaymentNotification.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('instantPaymentNotification', $this->InstantPaymentNotification->read(null, $id));
}
-
- /**
- * Admin Add
- */
+
+/**
+ * Admin Add
+ */
function admin_add(){
- $this->redirect(array('admin' => true, 'action' => 'edit'));
+ $this->redirect(array('admin' => true, 'action' => 'edit'));
}
- /**
- * Admin Edit
- * @param String ID of the transaction to edit
- */
+/**
+ * Admin Edit
+ * @param String ID of the transaction to edit
+ */
function admin_edit($id = null) {
if (!empty($this->data)) {
if ($this->InstantPaymentNotification->save($this->data)) {
@@ -96,10 +96,10 @@ function admin_edit($id = null) {
}
}
- /**
- * Admin Delete
- * @param String ID of the transaction to delete
- */
+/**
+ * Admin Delete
+ * @param String ID of the transaction to delete
+ */
function admin_delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for InstantPaymentNotification', true));
@@ -110,6 +110,5 @@ function admin_delete($id = null) {
$this->redirect(array('action'=>'index'));
}
}
-
-}
-?>
+
+}
@@ -18,7 +18,7 @@ function admin_view($id = null) {
}
function admin_add(){
- $this->redirect(array('admin' => true, 'action' => 'edit'));
+ $this->redirect(array('admin' => true, 'action' => 'edit'));
}
function admin_edit($id = null) {
@@ -48,5 +48,4 @@ function admin_delete($id = null) {
}
}
-}
-?>
+}
@@ -2,58 +2,57 @@
App::import('Core', array('HttpSocket'));
class PaypalIpnSource extends DataSource {
-
- /**
- * Http is the HttpSocket Object.
- * @access public
- * @var object
- */
- var $Http = null;
-
- /**
- * constructer. Load the HttpSocket into the Http var.
- */
- function __construct(){
- $this->Http =& new HttpSocket();
- }
-
- /**
- * Strip slashes
- * @param string value
- * @return string
- */
- static function clearSlash($value){
- return get_magic_quotes_runtime() ? stripslashes($value) : $value;
- }
-
- /**
- * verifies POST data given by the paypal instant payment notification
- * @param array $data Most likely directly $_POST given by the controller.
- * @return boolean true | false depending on if data received is actually valid from paypal and not from some script monkey
- */
- function isValid($data){
- $data['cmd'] = '_notify-validate';
-
- $data = array_map(array('PaypalIpnSource', 'clearSlash'), $data);
-
- if(isset($data['test_ipn'])) {
- $server = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
- } else {
- $server = 'https://www.paypal.com/cgi-bin/webscr';
- }
-
- $response = $this->Http->post($server, $data);
-
- if($response == "VERIFIED"){
- return true;
- }
-
- if(!$response){
- $this->log('HTTP Error in PaypalIpnSource::isValid while posting back to PayPal', 'paypal');
- }
-
- return false;
- }
-}
-
-?>
+
+/**
+ * Http is the HttpSocket Object.
+ * @access public
+ * @var object
+ */
+ var $Http = null;
+
+/**
+ * constructer. Load the HttpSocket into the Http var.
+ */
+ function __construct() {
+ $this->Http =& new HttpSocket();
+ }
+
+/**
+ * Strip slashes
+ * @param string value
+ * @return string
+ */
+ static function clearSlash($value){
+ return get_magic_quotes_runtime() ? stripslashes($value) : $value;
+ }
+
+/**
+ * verifies POST data given by the paypal instant payment notification
+ * @param array $data Most likely directly $_POST given by the controller.
+ * @return boolean true | false depending on if data received is actually valid from paypal and not from some script monkey
+ */
+ function isValid($data){
+ $data['cmd'] = '_notify-validate';
+
+ $data = array_map(array('PaypalIpnSource', 'clearSlash'), $data);
+
+ if (isset($data['test_ipn'])) {
+ $server = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
+ } else {
+ $server = 'https://www.paypal.com/cgi-bin/webscr';
+ }
+
+ $response = $this->Http->post($server, $data);
+
+ if ($response == "VERIFIED") {
+ return true;
+ }
+
+ if (!$response) {
+ $this->log('HTTP Error in PaypalIpnSource::isValid while posting back to PayPal', 'paypal');
+ }
+
+ return false;
+ }
+
+}
Oops, something went wrong.

0 comments on commit 6218bbe

Please sign in to comment.