Permalink
Browse files

Merge pull request #4 from josegonzalez/master

Improved Paypal-IPN-Plugin
  • Loading branch information...
2 parents 21b5d52 + 9a03059 commit 7d304b960c1edb70bc091a56a659d18726c6954b @webtechnick committed Nov 21, 2011
@@ -1,38 +1,62 @@
<?php
/************
- * Use these settings to set defaults for the Paypal Helper class.
- * The PaypalHelper class will help you create paynow, subscribe, donate, or addtocart buttons for you.
- *
- * All these options can be set on the fly as well within the helper
- */
-
+ * Use these settings to set defaults for the Paypal Helper class.
+ * The PaypalHelper class will help you create paynow, subscribe, donate, or addtocart buttons for you.
+ *
+ * All these options can be set on the fly as well within the helper
+ */
class PaypalIpnConfig {
- /************
- * Each settings key coresponds to the Paypal API. Review www.paypal.com for more.
- */
- var $settings = array(
- 'business' => 'live_email@paypal.com', //'live_email@paypal.com', //Your Paypal email account
- 'server' => 'https://www.paypal.com', //Main paypal server.
- 'notify_url' => 'http://yoursite.com/paypal_ipn/process', //'http://www.yoursite.com/paypal_ipn/process', //Notify_url... set this to the process path of your paypal_ipn::instant_payment_notification::process action
- 'currency_code' => 'USD', //Currency
- 'lc' => 'US', //Locality
- 'item_name' => 'Paypal_IPN', //Default item name.
- 'amount' => '15.00' //Default item amount.
- );
-
- /***********
- * Test settings to test with using a sandbox paypal account.
- */
- var $testSettings = array(
- 'business' => 'sandbox_email@paypal.com', //'sandbox_email@paypal.com',
- 'server' => 'https://www.sandbox.paypal.com',
- 'notify_url' => 'http://www.yoursite.com/paypal_ipn/process', //'http://www.yoursite.com/paypal_ipn/process',
- 'currency_code' => 'USD',
- 'lc' => 'US',
- 'item_name' => 'Paypal_IPN',
- 'amount' => '15.00'
- );
+/************
+ * Each settings key coresponds to the Paypal API. Review www.paypal.com for more.
+ */
+ var $default = array(
+ 'business' => 'live_email@paypal.com', // 'live_email@paypal.com', //Your Paypal email account
+ 'server' => 'https://www.paypal.com', // Main paypal server.
+ 'notify_url' => 'http://yoursite.com/paypal_ipn/process',
+ // 'http://yoursite.com/paypal_ipn/process',
+ // Notify_url... set this to the process path of your
+ // paypal_ipn::instant_payment_notification::process action
+ 'currency_code' => 'USD', // Currency
+ 'lc' => 'US', // Locality
+ 'item_name' => 'Paypal_IPN', // Default item name.
+ 'amount' => '15.00', // Default item amount.
+ 'encrypt' => false, // Set to true to enable encryption
+ );
+
+/***********
+ * Test settings to test with using a sandbox paypal account.
+ */
+ var $test = array(
+ 'business' => 'sandbox_email@paypal.com', // 'live_email@paypal.com', //Your Paypal email account
+ 'server' => 'https://www.sandbox.paypal.com', // Main paypal server.
+ 'notify_url' => 'http://test.yoursite.com/paypal_ipn/process',
+ // 'http://test.yoursite.com/paypal_ipn/process',
+ // Notify_url... set this to the process path of your
+ // paypal_ipn::instant_payment_notification::process action
+ 'currency_code' => 'USD', // Currency
+ 'lc' => 'US', // Locality
+ 'item_name' => 'Paypal_IPN', // Default item name.
+ 'amount' => '15.00', // Default item amount.
+ 'encrypt' => false, // Set to true to enable encryption
+ );
+
+ var $encryption_default = array(
+ 'cert_id' => '', // Certificate ID (gotten after certificate uploaded to paypal)
+ 'key_file' => '', // Absolute path to Private Key File
+ 'cert_file' => '', // Absolute path to Public Certificate file
+ 'paypal_cert_file' => '', // Absolute path to Paypal certificate file
+ 'openssl' => '/usr/bin/openssl', // OpenSSL location
+ 'bn' => 'cakephp_paypal-ipn-plugin', // Build Notation
+ );
+
+ var $encryption_test = array(
+ 'cert_id' => '', // Certificate ID (gotten after certificate uploaded to paypal)
+ 'key_file' => '', // Absolute path to Private Key File
+ 'cert_file' => '', // Absolute path to Public Certificate file
+ 'paypal_cert_file' => '', // Absolute path to Paypal certificate file
+ 'openssl' => '/usr/bin/openssl', // OpenSSL location
+ 'bn' => 'cakephp_paypal-ipn-plugin', // Build Notation
+ );
-}
-?>
+}
@@ -1,15 +1,15 @@
<?php
class ipnSchema extends CakeSchema {
- var $name = 'ipn';
-
- function before($event = array()) {
+ var $name = 'ipn';
+
+ function before($event = array()) {
return true;
}
function after($event = array()) {
- }
-
- var $instant_payment_notifications = array(
+ }
+
+ var $instant_payment_notifications = array(
'id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'key' => 'primary'),
'notify_version' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 64),
'verify_sign' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 127),
@@ -100,7 +100,7 @@ function after($event = array()) {
'modified' => array('type' => 'datetime', 'null' => true, 'default' => NULL),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
-
+
var $paypal_items = array(
'id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'key' => 'primary'),
'instant_payment_notification_id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36),
@@ -116,5 +116,4 @@ function after($event = array()) {
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
-}
-?>
+}
@@ -3,15 +3,15 @@
* Migration file. If you do not have paypal_ipn installed on your system. please use the ipn schema file.
*/
class itemsSchema extends CakeSchema {
- var $name = 'items';
-
- function before($event = array()) {
+ var $name = 'items';
+
+ function before($event = array()) {
return true;
}
function after($event = array()) {
- }
-
+ }
+
var $paypal_items = array(
'id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'key' => 'primary'),
'instant_payment_notification_id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36),
@@ -27,5 +27,4 @@ function after($event = array()) {
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
-}
-?>
+}
@@ -4,84 +4,91 @@ 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('/');
- }
-
- /**
- * __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() {
+
+/**
+ * Paypal IPN processing action..
+ * 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);
+
+ $existingIPNId = $this->InstantPaymentNotification->searchIPNId($notification);
+ if ($existingIPNId !== false) {
+ $notification['InstantPaymentNotification']['id'] = $existingIPNId;
+ }
+
+ $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() {
$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 +103,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 +117,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) {
}
}
-}
-?>
+}
Oops, something went wrong.

0 comments on commit 7d304b9

Please sign in to comment.