File indexing completed on 2025-05-04 05:29:07
0001 <?php 0002 0003 /** 0004 * ocs-webserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-webserver. 0009 * 0010 * This program is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as 0012 * published by the Free Software Foundation, either version 3 of the 0013 * License, or (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 **/ 0023 class SupportController extends Local_Controller_Action_DomainSwitch 0024 { 0025 0026 /** 0027 * Zend_Controller_Request_Abstract object wrapping the request environment 0028 * 0029 * @var Zend_Controller_Request_Http 0030 */ 0031 protected $_request = null; 0032 /** @var int */ 0033 /** @var Zend_Auth */ 0034 protected $_auth; 0035 0036 public function init() 0037 { 0038 parent::init(); 0039 $this->_auth = Zend_Auth::getInstance(); 0040 } 0041 0042 public function indexAction() 0043 { 0044 $this->view->authMember = $this->_authMember; 0045 $this->view->headTitle('Become a supporter - ' . $this->getHeadTitle(), 'SET'); 0046 } 0047 0048 public function showAction() 0049 { 0050 $this->view->authMember = $this->_authMember; 0051 $this->_helper->viewRenderer('index'); 0052 $this->view->headTitle('Become a supporter - ' . $this->getHeadTitle(), 'SET'); 0053 $this->indexAction(); 0054 } 0055 0056 0057 public function supportAction() 0058 { 0059 $this->view->headTitle('Become a supporter - ' . $this->getHeadTitle(), 'SET'); 0060 $this->view->authMember = $this->_authMember; 0061 0062 $request = Zend_Controller_Front::getInstance()->getRequest(); 0063 0064 $httpHost = $this->getRequest()->getHttpHost(); 0065 $this->view->urlPay = 'https://' . $httpHost . '/support-old/pay'; 0066 $this->view->amount = (float)$this->getParam('amount', 1); 0067 $this->view->comment = html_entity_decode(strip_tags($this->getParam('comment'), null), ENT_QUOTES, 'utf-8'); 0068 $this->view->provider = 0069 mb_strtolower(html_entity_decode(strip_tags($this->getParam('provider'), null), ENT_QUOTES, 'utf-8'), 0070 'utf-8'); 0071 0072 } 0073 0074 public function payAction() 0075 { 0076 $this->_helper->layout()->disableLayout(); 0077 $this->view->headTitle('Become a supporter - ' . $this->getHeadTitle(), 'SET'); 0078 0079 //get parameter 0080 $amount_predefined = (float)$this->getParam('amount_predefined', 1); 0081 $amount_handish = (float)$this->getParam('amount_handish', 1); 0082 0083 $amount = 0; 0084 if(null != ($this->getParam('amount_predefined') && $amount_predefined > 0)) { 0085 $amount = $amount_predefined; 0086 } else { 0087 $amount = $amount_handish; 0088 } 0089 0090 $comment = Default_Model_HtmlPurify::purify($this->getParam('comment')); 0091 $paymentProvider = 0092 mb_strtolower(html_entity_decode(strip_tags($this->getParam('provider'), null), ENT_QUOTES, 'utf-8'), 0093 'utf-8'); 0094 $httpHost = $this->getRequest()->getHttpHost(); 0095 $config = Zend_Registry::get('config'); 0096 0097 $form_url = $config->third_party->paypal->form->endpoint . '/cgi-bin/webscr'; 0098 $ipn_endpoint = 'http://'.$httpHost.'/gateway/paypal'; 0099 $return_url_success = 'http://'.$httpHost.'/support-old/paymentok'; 0100 $return_url_cancel = 'http://'.$httpHost.'/support-old/paymentcancel'; 0101 $merchantid = $config->third_party->paypal->merchantid; 0102 0103 $this->view->form_endpoint = $form_url; 0104 $this->view->form_ipn_endpoint = $ipn_endpoint; 0105 $this->view->form_return_url_ok = $return_url_success; 0106 $this->view->form_return_url_cancel = $return_url_cancel; 0107 $this->view->form_merchant = $merchantid; 0108 $this->view->member_id = $this->_authMember->member_id; 0109 $this->view->transaction_id = $this->_authMember->member_id . '_' . time(); 0110 $this->view->amount = $amount; 0111 $this->view->amount_predefined = $amount_predefined; 0112 0113 //Add pling 0114 $modelSupport = new Default_Model_DbTable_Support(); 0115 $supportId = $modelSupport->createNewSupport($this->view->transaction_id, $this->_authMember->member_id, $amount); 0116 0117 0118 /** 0119 $paymentGateway = $this->createPaymentGateway($paymentProvider); 0120 //Receiver Data 0121 $opendesktopdata = array(); 0122 $opendesktopdata['mail'] = $config->resources->mail->defaultFrom->email; 0123 //$opendesktopdata['firstname'] = ""; 0124 $opendesktopdata['lastname'] = $config->resources->mail->defaultFrom->name; 0125 $opendesktopdata['paypal_mail'] = $config->third_party->paypal->facilitator_fee_receiver; 0126 $opendesktopdata['project_id'] = 0; 0127 $opendesktopdata['title'] = $config->resources->mail->defaultFrom->name; 0128 0129 $paymentGateway->getUserDataStore()->generateFromArray($opendesktopdata); 0130 0131 $requestMessage = 'Thank you for supporting: ' . $paymentGateway->getUserDataStore()->getProductTitle(); 0132 0133 $response = null; 0134 try { 0135 $response = $paymentGateway->requestPayment($amount, $requestMessage); 0136 $this->view->checkoutEndpoint = $paymentGateway->getCheckoutEndpoint(); 0137 $this->view->paymentKey = $response->getPaymentId(); 0138 $this->_helper->viewRenderer->setRender('pay_' . $paymentProvider); 0139 } catch (Exception $e) { 0140 throw new Zend_Controller_Action_Exception('payment error', 500, $e); 0141 } 0142 0143 if (false === $response->isSuccessful()) { 0144 throw new Zend_Controller_Action_Exception('payment failure', 500); 0145 } 0146 0147 $memberId = $this->_authMember->member_id; 0148 0149 //Add pling 0150 $modelDonation = new Default_Model_DbTable_Donation(); 0151 $donationId = $modelDonation->createNewDonationFromResponse($response, $memberId, $amount); 0152 0153 if (false == empty($comment)) { 0154 $modelComments = new Default_Model_ProjectComments(); 0155 $dataComment = array( 0156 'comment_type' => Default_Model_DbTable_Comments::COMMENT_TYPE_DONATION, 0157 'comment_target_id' => 0, 0158 'comment_member_id' => $memberId, 0159 'comment_pling_id' => $donationId, 0160 'comment_text' => $comment 0161 ); 0162 $modelComments->save($dataComment); 0163 } 0164 **/ 0165 } 0166 0167 /** 0168 * @param string $paymentProvider 0169 * 0170 * @throws Zend_Controller_Exception 0171 * @return Local_Payment_GatewayInterface 0172 */ 0173 protected function createPaymentGateway($paymentProvider) 0174 { 0175 $httpHost = $this->getRequest()->getHttpHost(); 0176 /** @var Zend_Config $config */ 0177 $config = Zend_Registry::get('config'); 0178 $helperBuildProductUrl = new Default_View_Helper_BuildProductUrl(); 0179 switch ($paymentProvider) { 0180 case 'paypal': 0181 $paymentGateway = new Default_Model_PayPal_Gateway($config->third_party->paypal); 0182 $paymentGateway->setIpnNotificationUrl('http://' . $httpHost . '/gateway/paypal'); 0183 // $paymentGateway->setIpnNotificationUrl('http://' . $httpHost . '/gateway/paypal?XDEBUG_SESSION_START=1'); 0184 $paymentGateway->setCancelUrl('http://' . $httpHost . '/donate/paymentcancel'); 0185 $paymentGateway->setReturnUrl('http://' . $httpHost . '/donate/paymentok'); 0186 break; 0187 0188 case 'dwolla': 0189 $paymentGateway = new Default_Model_Dwolla_Gateway($config->third_party->dwolla); 0190 $paymentGateway->setIpnNotificationUrl('http://' . $httpHost . '/gateway/dwolla'); 0191 $paymentGateway->setReturnUrl('http://' . $httpHost . '/donate/dwolla'); 0192 break; 0193 0194 case 'amazon': 0195 $paymentGateway = new Default_Model_Amazon_Gateway($config->third_party->amazon); 0196 $paymentGateway->setIpnNotificationUrl('http://' . $httpHost . '/gateway/amazon'); 0197 $paymentGateway->setCancelUrl('http://' . $httpHost . '/donate/paymentcancel'); 0198 $paymentGateway->setReturnUrl('http://' . $httpHost . '/donate/paymentok'); 0199 break; 0200 0201 default: 0202 throw new Zend_Controller_Exception('No known payment provider found in parameters.'); 0203 break; 0204 } 0205 0206 return $paymentGateway; 0207 } 0208 0209 public function dwollaAction() 0210 { 0211 $modelPling = new Default_Model_DbTable_Plings(); 0212 $plingData = $modelPling->fetchRow(array('payment_reference_key = ?' => $this->getParam('checkoutId'))); 0213 $plingData->payment_transaction_id = (int)$this->getParam('transaction'); 0214 $plingData->save(); 0215 0216 if ($this->_getParam('status') == 'Completed') { 0217 $this->_helper->viewRenderer('paymentok'); 0218 $this->paymentokAction(); 0219 } else { 0220 $this->_helper->viewRenderer('paymentcancel'); 0221 $this->paymentcancelAction(); 0222 } 0223 } 0224 0225 public function paymentokAction() 0226 { 0227 //$this->_helper->layout()->disableLayout(); 0228 $this->view->paymentStatus = 'success'; 0229 $this->view->paymentMessage = 'Payment successful.'; 0230 $this->view->headTitle('Thank you for your support - ' . $this->getHeadTitle(), 'SET'); 0231 } 0232 0233 public function paymentcancelAction() 0234 { 0235 //$this->_helper->layout()->disableLayout(); 0236 $this->view->paymentStatus = 'danger'; 0237 $this->view->paymentMessage = 'Payment cancelled.'; 0238 $this->view->headTitle('Become a supporter - ' . $this->getHeadTitle(), 'SET'); 0239 } 0240 0241 0242 /** 0243 * @param $errors 0244 * 0245 * @return array 0246 */ 0247 protected function getErrorMessages($errors) 0248 { 0249 $messages = array(); 0250 foreach ($errors as $element => $row) { 0251 if (!empty($row) && $element != 'submit') { 0252 foreach ($row as $validator => $message) { 0253 $messages[$element][] = $message; 0254 } 0255 } 0256 } 0257 0258 return $messages; 0259 } 0260 0261 protected function _initResponseHeader() 0262 { 0263 $duration = 1800; // in seconds 0264 $expires = gmdate("D, d M Y H:i:s", time() + $duration) . " GMT"; 0265 0266 $this->getResponse()->setHeader('X-FRAME-OPTIONS', 'ALLOWALL', 0267 true)// ->setHeader('Last-Modified', $modifiedTime, true) 0268 ->setHeader('Expires', $expires, true)->setHeader('Pragma', 'no-cache', true) 0269 ->setHeader('Cache-Control', 'private, no-cache, must-revalidate', true) 0270 ; 0271 } 0272 0273 0274 }