_sendRequest(); } protected function _sendRequest() { $writeLog = $this->_getPaymentConfig('writeLog'); $this->_initSaleTransaction(); if ($writeLog) { $logData = [ 'transactionType' => $this->_transactionObj->getTransactionType(), 'transactionMode' => $this->_transactionObj->getTransactionMode(), ]; $logData += $this->getOption('data'); $this->_writeLog($logData); } if ($this->_transactionObj->process()) { $result = $this->_transactionObj->getResult(); } else { $result = ['r_error' => 'Connection error', 'r_approved' => '']; } if ($writeLog) { $this->_writeLog($result); } $this->_response = new App_Service_Payment_LinkPoint_Response($result); return $this; } protected function _getTransactionObj($reset = false) { if ($reset) { $this->_transactionObj = null; } if (null === $this->_transactionObj) { $config = [ 'store_name' => $this->_getPaymentConfig('STORE_NAME'), 'key_file' => $this->_getPaymentConfig('KEY_FILE'), ]; $this->_transactionObj = new \LinkPoint\LinkPoint($config); $this->_transactionObj->setTransactionMode($this->_getPaymentConfig('MODE')); } return $this->_transactionObj; } protected function _initSaleTransaction() { $data = $this->getOption('data'); $transactionObj = $this->_getTransactionObj(true); $transactionObj->setOrderId($data['orderId']); $transactionObj->setInvoiceId($data['invoiceId']); $transactionObj->setTax($data['tax']); $transactionObj->setShipping($data['shipping']); $transactionObj->setTotal($data['total']); $billingAddress = new \LinkPoint\Address(\LinkPoint\Address::BILLING, $data['billingInfo']); $transactionObj->setBillingAddress($billingAddress); $shippingAddress = new \LinkPoint\Address(\LinkPoint\Address::SHIPPING, $data['shippingInfo']); $transactionObj->setShippingAddress($shippingAddress); $card = new \LinkPoint\Payment_CreditCard( $data['cardnumber'], $data['cardexpmonth'], $data['cardexpyear'], $data['cvmvalue'], $data['cvmindicator'] ); $transactionObj->setPaymentObject($card); $transactionObj->addItems($data['items']); return $this; } protected function _initVoidTransaction() { $transactionObj = $this->_getTransactionObj(true); $transactionObj->setTransactionType(\LinkPoint\LinkPoint::TYPE_VOID); $transactionObj->setOrderId($this->_options['data']['orderId']); $transactionObj->setTransactionDate($this->getResponse()->getData('r_date')); return $this; } public function getResponse() { return $this->_response; } public function updateOrder($orderId) { $orderConfig = $this->_getPaymentConfig('order'); $writeLog = $this->_getPaymentConfig('writeLog'); $result = true; if ($orderConfig['enable']) { $orderClass = new $orderConfig['class'](); $checkout = new App_ECommerce_Checkout_Obj(); $transactionId = $checkout->getTransactionId(); if (!empty($transactionId)) { $checkout->saveTransactionId($transactionId); $data = ['invoice' => $orderId, 'transactionId' => $transactionId]; $data += $this->getResponse()->getData(); $result = $orderClass->{$orderConfig['updateMethod']}($data); } else { $this->_initVoidTransaction(); if ($writeLog) { $logData = [ 'transactionType' => $this->_transactionObj->getTransactionType(), 'transactionMode' => $this->_transactionObj->getTransactionMode(), ]; $logData += $this->getOption('data'); $this->_writeLog($logData); } if ($this->_transactionObj->process()) { $result = $this->_transactionObj->getResult(); } else { $result = ['r_error' => 'Connection error', 'r_approved' => '']; } if ($writeLog) { $this->_writeLog($result); } $this->_response = new App_Service_Payment_LinkPoint_Response($result); if ($this->_response->isSuccess()) { $this->_response = new App_Service_Payment_AuthorizeNet_Response([ 'r_approved' => '', 'r_error' => 'Wrong transaction id', ]); } $result = false; } } if ($writeLog) { $this->_writeLog(['type' => 'updateOrder', 'orderId' => $orderId, 'result' => $result]); } return $result; } }