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

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 class Default_Model_DbTable_MemberPayout extends Local_Model_Table
0023 {
0024     protected $_keyColumnsForRow = array('id');
0025     protected $_key = 'id';
0026     protected $_name = "member_payout";
0027     
0028     public static $PAYOUT_STATUS_NEW = 0;
0029     public static $PAYOUT_STATUS_REQUESTED = 1;
0030     public static $PAYOUT_STATUS_PROCESSED = 10;
0031     public static $PAYOUT_STATUS_PENDING = 50;
0032     public static $PAYOUT_STATUS_ERROR = 99;
0033     public static $PAYOUT_STATUS_COMPLETED = 100;
0034     public static $PAYOUT_STATUS_REFUND = 900;
0035     public static $PAYOUT_STATUS_RESERVED = 901;
0036     public static $PAYOUT_STATUS_DENIED = 940;
0037     public static $PAYOUT_STATUS_FAILED = 950;
0038     
0039     
0040     
0041     
0042     /**
0043      * @param int $status
0044      * @return all payouts with status = $status
0045      **/
0046     public function fetchAllPayouts($yearmonth = null, $status=0)
0047     {
0048     
0049       $sql = "
0050                 SELECT
0051                     *
0052                 FROM
0053                     ".$this->_name."
0054                 WHERE
0055                     status = ".$status;
0056        if($yearmonth) {
0057            $sql .= " AND ";
0058        }
0059     
0060       $result = $this->_db->fetchAll($sql);
0061     
0062       return $result;
0063     
0064     }
0065     
0066     /**
0067      * Mark payout as payed.
0068      *
0069      * @param Local_Payment_ResponseInterface $payment_response
0070      *
0071      */
0072     public function setPayoutStatusCompletedFromResponse($payment_response)
0073     {
0074         $updateValues = array(
0075             'status' => self::$PAYOUT_STATUS_COMPLETED,
0076             'payment_transaction_id' => $payment_response->getTransactionId(),
0077             'payment_raw_Message' => serialize($payment_response->getRawMessage()),
0078             'payment_status' => $payment_response->getTransactionStatus(),
0079             'timestamp_masspay_last_ipn' => new Zend_Db_Expr ('Now()')
0080         );
0081 
0082         $this->update($updateValues, "payment_reference_key='" . $payment_response->getPaymentId() . "'");
0083     }
0084     
0085     /**
0086      * Mark payout as payed.
0087      *
0088      * @param Local_Payment_ResponseInterface $payment_response
0089      *
0090      */
0091     public function setPayoutStatusPendingFromResponse($payment_response)
0092     {
0093         $updateValues = array(
0094             'status' => self::$PAYOUT_STATUS_PENDING,
0095             'payment_transaction_id' => $payment_response->getTransactionId(),
0096             'payment_raw_Message' => serialize($payment_response->getRawMessage()),
0097             'payment_status' => $payment_response->getTransactionStatus(),
0098             'timestamp_masspay_last_ipn' => new Zend_Db_Expr ('Now()')
0099         );
0100 
0101         $this->update($updateValues, "payment_reference_key='" . $payment_response->getPaymentId() . "'");
0102     }
0103     
0104     /**
0105      * Mark payout as payed.
0106      *
0107      * @param Local_Payment_ResponseInterface $payment_response
0108      *
0109      */
0110     public function setPayoutStatusRefundFromResponse($payment_response)
0111     {
0112         $updateValues = array(
0113             'status' => self::$PAYOUT_STATUS_REFUND,
0114             'payment_transaction_id' => $payment_response->getTransactionId(),
0115             'payment_raw_Message' => serialize($payment_response->getRawMessage()),
0116             'payment_status' => $payment_response->getTransactionStatus(),
0117             'timestamp_masspay_last_ipn' => new Zend_Db_Expr ('Now()')
0118         );
0119 
0120         $this->update($updateValues, "payment_reference_key='" . $payment_response->getPaymentId() . "'");
0121     }
0122     
0123     /**
0124      * Mark payout as denied.
0125      *
0126      * @param Local_Payment_ResponseInterface $payment_response
0127      *
0128      */
0129     public function setPayoutStatusDeniedFromResponse($payment_response)
0130     {
0131         $updateValues = array(
0132             'status' => self::$PAYOUT_STATUS_DENIED,
0133             'payment_transaction_id' => $payment_response->getTransactionId(),
0134             'payment_raw_Message' => serialize($payment_response->getRawMessage()),
0135             'payment_status' => $payment_response->getTransactionStatus(),
0136             'timestamp_masspay_last_ipn' => new Zend_Db_Expr ('Now()')
0137         );
0138 
0139         $this->update($updateValues, "payment_reference_key='" . $payment_response->getPaymentId() . "'");
0140     }
0141     
0142     /**
0143      * Mark payout as failed.
0144      *
0145      * @param Local_Payment_ResponseInterface $payment_response
0146      *
0147      */
0148     public function setPayoutStatusFailedFromResponse($payment_response)
0149     {
0150       $updateValues = array(
0151           'status' => self::$PAYOUT_STATUS_FAILED,
0152           'payment_transaction_id' => $payment_response->getTransactionId(),
0153           'payment_raw_Message' => serialize($payment_response->getRawMessage()),
0154           'payment_status' => $payment_response->getTransactionStatus(),
0155           'timestamp_masspay_last_ipn' => new Zend_Db_Expr ('Now()')
0156       );
0157     
0158       $this->update($updateValues, "payment_reference_key='" . $payment_response->getPaymentId() . "'");
0159     }
0160     
0161     /**
0162      * Mark payout as reserved.
0163      *
0164      * @param Local_Payment_ResponseInterface $payment_response
0165      *
0166      */
0167     public function setPayoutStatusReservedFromResponse($payment_response)
0168     {
0169       $updateValues = array(
0170           'status' => self::$PAYOUT_STATUS_RESERVED,
0171           'payment_transaction_id' => $payment_response->getTransactionId(),
0172           'payment_raw_Message' => serialize($payment_response->getRawMessage()),
0173           'payment_status' => $payment_response->getTransactionStatus(),
0174           'timestamp_masspay_last_ipn' => new Zend_Db_Expr ('Now()')
0175       );
0176     
0177       $this->update($updateValues, "payment_reference_key='" . $payment_response->getPaymentId() . "'");
0178     }
0179     
0180     /**
0181      * Mark plings as payed.
0182      * So they can be used to pling.
0183      *
0184      * @param Local_Payment_ResponseInterface $payment_response
0185      *
0186      */
0187     public function activatePayoutFromResponse($payment_response)
0188     {
0189         $updateValues = array(
0190             'status' => self::$PAYOUT_STATUS_COMPLETED,
0191             'payment_transaction_id' => $payment_response->getTransactionId(),
0192             'payment_raw_Message' => serialize($payment_response->getRawMessage()),
0193             'payment_status' => $payment_response->getTransactionStatus(),
0194             'timestamp_masspay_last_ipn' => new Zend_Db_Expr ('Now()')
0195         );
0196 
0197         $this->update($updateValues, "payment_reference_key='" . $payment_response->getPaymentId() . "'");
0198     }
0199 
0200     /**
0201      * @param Local_Payment_ResponseInterface $payment_response
0202      */
0203     public function deactivatePayoutFromResponse($payment_response)
0204     {
0205         $updateValues = array(
0206             'status' => 0,
0207             'payment_status' => $payment_response->getTransactionStatus(),
0208             'payment_raw_error' => serialize($payment_response->getRawMessage())
0209         );
0210 
0211         $this->update($updateValues,
0212             "payment_transaction_id='" . $payment_response->getTransactionId() . "' and (status_id=1 or status_id=2)");
0213 
0214     }
0215 
0216     /**
0217      * @param Local_Payment_ResponseInterface $payment_response
0218      * @return null|\Zend_Db_Table_Row_Abstract
0219      */
0220     public function fetchPayoutFromResponse($payment_response)
0221     {
0222         if ($payment_response->getPaymentId() != null) {
0223             $where = array('payment_reference_key = ?' => $payment_response->getPaymentId());
0224         } elseif ($payment_response->getTransactionId() != null) {
0225             $where = array('payment_transaction_id = ?' => $payment_response->getTransactionId());
0226         } else {
0227             return null;
0228         }
0229 
0230         return $this->fetchRow($where);
0231 
0232     }
0233 
0234     /**
0235      * @param Local_Payment_ResponseInterface $payment_response
0236      */
0237     public function updatePayoutTransactionStatusFromResponse($payment_response)
0238     {
0239         $updateValues = array(
0240             'payment_status' => $payment_response->getTransactionStatus(),
0241             'payment_raw_error' => serialize($payment_response->getRawMessage())
0242         );
0243 
0244         $this->update($updateValues,
0245             "payment_transaction_id='" . $payment_response->getTransactionId() . "' and status>1");
0246 
0247     }
0248     
0249     
0250 }