File indexing completed on 2025-02-09 07:14:35

0001 <?php
0002 /**
0003  *  ocs-webserver
0004  *
0005  *  Copyright 2016 by pling GmbH.
0006  *
0007  *    This file is part of ocs-webserver.
0008  *
0009  *    This program is free software: you can redistribute it and/or modify
0010  *    it under the terms of the GNU Affero General Public License as
0011  *    published by the Free Software Foundation, either version 3 of the
0012  *    License, or (at your option) any later version.
0013  *
0014  *    This program is distributed in the hope that it will be useful,
0015  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017  *    GNU Affero General Public License for more details.
0018  *
0019  *    You should have received a copy of the GNU Affero General Public License
0020  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021  **/
0022 
0023 class Default_Model_Dwolla_Callback extends Local_Payment_Dwolla_Callback
0024 {
0025 
0026     /** @var \Default_Model_Pling */
0027     protected $_tablePling;
0028 
0029     /** @var  Zend_Db_Table_Row_Abstract */
0030     protected $_storedDataTransaction;
0031 
0032     function __construct($config = null, $logger = null)
0033     {
0034         if (null == $logger) {
0035             $logger = Zend_Registry::get('logger');
0036         }
0037 
0038         if (null == $config) {
0039             $config = Zend_Registry::get('config');
0040         }
0041 
0042         parent::__construct($config->third_party->dwolla, $logger);
0043 
0044         $this->_tablePling = new Default_Model_Pling();
0045     }
0046 
0047     protected function validateTransaction()
0048     {
0049         $this->_storedDataTransaction = $this->_tablePling->fetchPlingFromResponse($this->_transactionMessage);
0050         if (null === $this->_storedDataTransaction) {
0051             $this->_logger->err(__METHOD__ . ' - ' . 'No transaction found for IPN message.' . PHP_EOL);
0052             return false;
0053         } else {
0054             $this->_logger->debug(__METHOD__ . " - " . print_r($this->_storedDataTransaction->toArray(), true) . PHP_EOL);
0055         }
0056 
0057         return $this->_checkAmount();
0058     }
0059 
0060     protected function _checkAmount()
0061     {
0062         $this->_logger->debug(__METHOD__ . ' - ' . "{$this->_storedDataTransaction->amount} == {$this->_transactionMessage->getTransactionAmount()}");
0063         return $this->_storedDataTransaction->amount == $this->_transactionMessage->getTransactionAmount();
0064     }
0065 
0066     protected function _statusCompleted()
0067     {
0068         $this->_logger->info(__METHOD__ . '::' . "activate plings." . PHP_EOL);
0069         $this->_tablePling->activatePlingsFromResponse($this->_transactionMessage);
0070     }
0071 
0072     protected function _statusCancelled()
0073     {
0074         $this->_statusError();
0075     }
0076 
0077     protected function _statusError()
0078     {
0079         $this->_logger->info(__METHOD__ . '::' . "deactivate plings." . PHP_EOL);
0080         $this->_tablePling->deactivatePlingsFromResponse($this->_transactionMessage);
0081     }
0082 
0083 }