/**
  *
  * @param array $request - get from gateway
  * @throws waPaymentException
  * @return mixed
  */
 protected function callbackHandler($request)
 {
     $transaction_data = $this->formalizeData($request);
     $code = $transaction_data['type'] == self::OPERATION_CHECK ? self::XML_PAYMENT_REFUSED : self::XML_TEMPORAL_PROBLEMS;
     if (!$this->order_id || !$this->app_id || !$this->merchant_id) {
         throw new waPaymentException('invalid invoice number', $code);
     }
     if (!$this->ShopID) {
         throw new waPaymentException('empty merchant data', $code);
     }
     if (waRequest::get('result') || $request['action'] == 'PaymentFail') {
         $type = $request['action'] == 'PaymentFail' ? waAppPayment::URL_FAIL : waAppPayment::URL_SUCCESS;
         return array('redirect' => $this->getAdapter()->getBackUrl($type, $transaction_data));
     }
     $this->verifySign($request);
     switch ($transaction_data['type']) {
         case self::OPERATION_CHECK:
             $app_payment_method = self::CALLBACK_CONFIRMATION;
             $transaction_data['state'] = self::STATE_AUTH;
             break;
         case self::OPERATION_AUTH_CAPTURE:
             // exclude transactions duplicates
             $tm = new waTransactionModel();
             $fields = array('native_id' => $transaction_data['native_id'], 'plugin' => $this->id, 'type' => waPayment::OPERATION_AUTH_CAPTURE);
             if ($tm->getByFields($fields)) {
                 throw new waPaymentException('already accepted', self::XML_SUCCESS);
             }
             $app_payment_method = self::CALLBACK_PAYMENT;
             $transaction_data['state'] = self::STATE_CAPTURED;
             break;
         default:
             throw new waPaymentException('unsupported payment operation', self::XML_TEMPORAL_PROBLEMS);
     }
     $transaction_data = $this->saveTransaction($transaction_data, $request);
     $result = $this->execAppCallback($app_payment_method, $transaction_data);
     return $this->getXMLResponse($request, $result['result'] ? self::XML_SUCCESS : self::XML_PAYMENT_REFUSED, $result['error']);
 }
예제 #2
0
 /**
  * Get transactions list
  * @param array $conditions - $key=>$value pairs
  * @return array $transactions - transactions list
  */
 public static final function getTransactionsByFields($conditions)
 {
     $transaction_model = new waTransactionModel();
     $transaction_data_model = new waTransactionDataModel();
     $transactions = $transaction_model->getByFields($conditions);
     $transactions_data = $transaction_data_model->getByField('transaction_id', array_keys($transactions), true);
     foreach ($transactions_data as $key => $row) {
         $transactions[$row['transaction_id']]['raw_data'][$row['field_id']] = $row['value'];
     }
     return $transactions;
 }
예제 #3
0
 private function getUniqTransaction($transaction_data)
 {
     $transaction_model = new waTransactionModel();
     return $transaction_model->getByFields(array('plugin' => $this->id, 'app_id' => $this->app_id, 'merchant_id' => $this->merchant_id, 'native_id' => $transaction_data['native_id']));
 }
 protected function callbackHandler($request)
 {
     $encrypt = $this->encryptFields($request['crypt'], $this->crypt_password);
     $request += $encrypt;
     $this->request = $request;
     $transaction_data = $this->formalizeData($this->request);
     if (!$this->order_id || !$this->app_id || !$this->merchant_id) {
         throw new waPaymentException('invalid invoice number');
     }
     $result = array('p' => $this);
     if ($transaction_data['type'] == waPayment::OPERATION_AUTH_CAPTURE) {
         $app_payment_method = self::CALLBACK_CONFIRMATION;
         $back_url = $this->getAdapter()->getBackUrl(waAppPayment::URL_SUCCESS, $transaction_data);
     } else {
         $app_payment_method = self::CALLBACK_CANCEL;
         $back_url = $this->getAdapter()->getBackUrl(waAppPayment::URL_FAIL, $transaction_data);
     }
     if ($transaction_data['type']) {
         $tm = new waTransactionModel();
         $fields = array('native_id' => $transaction_data['native_id'], 'plugin' => $this->id, 'type' => $app_payment_method);
         if (!$tm->getByFields($fields)) {
             $transaction_data = $this->saveTransaction($transaction_data, $this->request);
             if ($app_payment_method) {
                 $result += $this->execAppCallback($app_payment_method, $transaction_data);
                 self::addTransactionData($transaction_data['id'], $result);
             }
         }
     }
     $result['back_url'] = $back_url;
     $result['template'] = wa()->getConfig()->getRootPath() . '/wa-plugins/payment/' . $this->id . '/templates/callback.html';
     return $result;
 }
 /**
  * @param array $request
  * @return array|string|void
  * @throws waPaymentException
  */
 public function callbackHandler($request)
 {
     $transaction_data = $this->formalizeData($request);
     if (!$this->order_id || !$this->app_id || !$this->merchant_id) {
         throw new waPaymentException('invalid invoice number');
     }
     if ($transaction_data['type'] == waPayment::OPERATION_AUTH_CAPTURE) {
         $app_payment_method = self::CALLBACK_CONFIRMATION;
     }
     $tm = new waTransactionModel();
     $fields = array('native_id' => $transaction_data['native_id'], 'plugin' => $this->id, 'type' => $app_payment_method);
     $result = '';
     if (!$tm->getByFields($fields)) {
         $transaction_data = $this->saveTransaction($transaction_data, $request);
         $result = $this->execAppCallback($app_payment_method, $transaction_data);
         self::addTransactionData($transaction_data['id'], $result);
     }
     return $result;
 }
 /**
  * @param array $request
  * @throws waPaymentException
  * @return array|string|void
  */
 protected function callbackHandler($request)
 {
     $transaction_data = $this->formalizeData($request);
     if (!$this->order_id || !$this->app_id || !$this->merchant_id) {
         throw new waPaymentException('invalid invoice number');
     }
     $response_password = !empty($request['callbackPW']) ? $request['callbackPW'] : '';
     $result = array('p' => $this);
     if ($response_password != $this->response_password) {
         $result['rp_not_equal'] = true;
         $result['template'] = wa()->getConfig()->getRootPath() . '/wa-plugins/payment/' . $this->id . '/templates/callback.html';
         $result['back_url'] = $this->getAdapter()->getBackUrl(waAppPayment::URL_FAIL, $transaction_data);
         waLog::log("Payment Response password in plugin settings doesn't equal the same setting in the Merchant Interface\n" . "Client IP:" . waRequest::getIp(), 'worldpayPament.log');
         return $result;
     }
     if ($transaction_data['type'] == waPayment::OPERATION_AUTH_CAPTURE) {
         $app_payment_method = self::CALLBACK_CONFIRMATION;
         $back_url = $this->getAdapter()->getBackUrl(waAppPayment::URL_SUCCESS, $transaction_data);
     } else {
         $app_payment_method = self::CALLBACK_CANCEL;
         $back_url = $this->getAdapter()->getBackUrl(waAppPayment::URL_FAIL, $transaction_data);
     }
     $tm = new waTransactionModel();
     $fields = array('native_id' => $transaction_data['native_id'], 'plugin' => $this->id, 'type' => $app_payment_method);
     if (!$tm->getByFields($fields)) {
         $transaction_data = $this->saveTransaction($transaction_data, $request);
         $result += $this->execAppCallback($app_payment_method, $transaction_data);
     }
     $result['back_url'] = $back_url;
     $result['template'] = wa()->getConfig()->getRootPath() . '/wa-plugins/payment/' . $this->id . '/templates/callback.html';
     return $result;
 }
 private function restPayment($payment_form_data, $order_data, $auto_submit = false)
 {
     $order_data = waOrder::factory($order_data);
     $transaction_model = new waTransactionModel();
     $this->order_id = $order_data->id;
     $transaction_data = $transaction_model->getByField(array('app_id' => $this->app_id, 'plugin' => $this->id, 'order_id' => $this->order_id), 'id');
     ksort($transaction_data);
     $transaction_data = end($transaction_data);
     $messages = array();
     if (empty($transaction_data)) {
         if (!empty($payment_form_data['customer_phone'])) {
             $payment_form_data['customer_phone'] = preg_replace('@\\D+@', '', $payment_form_data['customer_phone']);
             if (preg_match('@\\d{11}@', $payment_form_data['customer_phone'])) {
                 try {
                     $transaction_data = $this->restAuth($payment_form_data, $order_data);
                 } catch (waPaymentException $ex) {
                     $messages[] = $ex->getMessage();
                 }
             } else {
                 $messages[] = 'Неверный номер телефона, используйте только цифры без пробелов и разделителей';
             }
         }
     } elseif ($transaction_data['state'] == self::STATE_AUTH && empty($payment_form_data['customer_phone'])) {
         $time = min(time() - strtotime($transaction_data['create_datetime']), time() - strtotime($transaction_data['update_datetime'])) / 3600;
         if ($time > min($this->lifetime, 2)) {
             try {
                 $transaction_data = $this->restAuth(array(), $order_data);
             } catch (waPaymentException $ex) {
                 if ($ex->getCode() == 210) {
                     unset($transaction_data['native_id']);
                 } else {
                     $messages[] = $ex->getMessage();
                 }
             }
         }
     }
     if (!empty($transaction_data['native_id'])) {
         if ($transaction_data['state'] == self::STATE_CAPTURED) {
             //TODO reload page
             //wa()->getResponse()->redirect('');
             $message = 'Заказ уже оплачен';
         } elseif ($transaction_data['state'] == self::STATE_AUTH) {
             $url = $this->getEndpointUrl('form', array('native_id' => $transaction_data['native_id']));
             if ($auto_submit) {
                 wa()->getResponse()->redirect($url);
                 return null;
             } else {
                 $view = wa()->getView();
                 $view->assign('form_url', $url);
                 $view->assign('messages', $messages);
                 return $view->fetch($this->path . '/templates/paymentRest.html');
             }
         } elseif (in_array($transaction_data['state'], array(self::STATE_DECLINED, self::STATE_CANCELED))) {
             $transaction_data_model = new waTransactionDataModel();
             $raw_status = $transaction_data_model->getByField(array('transaction_id' => $transaction_data['id'], 'field_id' => 'status'));
             switch (ifempty($raw_status['value'])) {
                 case 'expired':
                     /** Время жизни счета истекло. Счет не оплачен. **/
                     $message = sprintf('Время жизни счета истекло. Счет %s не оплачен.', $order_data->id_str);
                     break;
                 case 'unpaid':
                     /** Ошибка при проведении оплаты. Счет не оплачен. **/
                     $message = sprintf('Ошибка при проведении оплаты. Счет %s не оплачен.', $order_data->id_str);
                     break;
                 case 'rejected':
                     /**Счет отклонен.**/
                     $message = sprintf('Счет %s отклонен', $order_data->id_str);
                     break;
                 default:
                     $message = sprintf('Неизвестное состояние для счета %s', $order_data->id_str);
                     break;
             }
         } else {
             $message = 'Возможно, заказ уже оплачен';
         }
         return $message;
     } else {
         if (!empty($payment_form_data['customer_phone'])) {
             $mobile_phone = $payment_form_data['customer_phone'];
         } else {
             $mobile_phone = preg_replace('/[\\D]+/', '', $order_data->getContactField($this->customer_phone, 'default'));
         }
         $view = wa()->getView();
         $view->assign('mobile_phone', $mobile_phone);
         $view->assign('messages', $messages);
         return $view->fetch($this->path . '/templates/paymentRest.html');
     }
 }