_setItemList($options['data']['itemList']); unset($options['data']['itemList']); } $this->setOptions($options); if (isset($options['type'])) { $this->_setPaymentType($options['type']); } return $this; } public function setOptions($options) { $options = Qs_Options::setOptions($this, $options); $this->_options = array_merge($this->_options, $options); return $this; } public function getOptions() { return $this->_options; } public function getOption($option) { if (array_key_exists($option, $this->_options)) { return $this->_options[$option]; } return false; } protected function _writeLog($data) { foreach ($this->_forbiddenFields as $field) { if (isset($data[$field])) { unset($data[$field]); } } $log = new \App\Service\Log\PaymentLog([ 'name' => $this->_logFileName, ]); $log->log([$data]); return $this; } protected function _postPayment($data) { $orderConfig = $this->_getPaymentConfig('order'); if ($orderConfig['enable']) { $orderClass = new $orderConfig['class'](); $orderClass->{$orderConfig['updateMethod']}($data); } return $this; } protected function _getPaymentConfig($field = null) { if (!$this->_paymentConfig) { $this->_paymentConfig = Qs_Config::get($this->_paymentConfigAlias, Qs_Config::APP_TYPE)->toArray(); } return $field ? $this->_paymentConfig[$field] : $this->_paymentConfig; } protected function _setItemList($itemList) { $this->_itemList = $itemList; return $this; } protected function _getItemList() { return $this->_itemList; } protected function _setPaymentType($paymentType) { $this->_paymentType = $paymentType; return $this; } public function getPaymentType() { return $this->_paymentType; } /** * @return App_Service_Payment_ResponseAbstract * @throws Qs_Exception */ public function getResponse() { throw new Qs_Exception('Method ' . __METHOD__ . ' is not implemented'); } /** * PayPal IPN processing * @return App_Service_Payment_Abstract */ protected function _verifyIpn() { $postParams = Qs_Request::getPost(); $this->_writeLog($postParams); $postParams['cmd'] = '_notify-validate'; $query = http_build_query($postParams); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->_getPaymentConfig('actionUrl')); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $query); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Host: ' . $this->_getPaymentConfig('host')]); $response = curl_exec($ch); curl_close($ch); if (strcmp($response, "VERIFIED") == 0) { $receiverEmail = $this->_getPaymentConfig('receiverEmail'); if ($postParams['payment_status'] == 'Completed' && $postParams['receiver_email'] == $receiverEmail) { $orderConfig = $this->_getPaymentConfig('order'); if ($orderConfig['enable']) { $orderClass = new $orderConfig['class'](); $total = Zend_Locale_Math::round($postParams['mc_gross'], 2); $verifyMethod = $orderConfig['verifyMethod']; $options = $postParams + ['transactionId' => $postParams['custom'], 'total' => $total]; if ($orderClass->{$verifyMethod}($options)) { $this->_postPayment($options); } else { $response = 'INVALID'; } } } else { $response = 'INVALID'; } } $this->_writeLog(['response' => $response] + $postParams); return $this; } }