/** * end action method handles payment confirm and saves order */ public function endAction() { $config = Shopware()->Plugins()->Frontend()->PigmbhRatePAYPayment()->Config(); $secret = $this->getPaymentShortName() == 'RatePAYInvoice'? $config->security_code: $config->security_code_rate; $transactionId = Shopware()->Session()->pi_ratepay_transactionID; $hash = $secret . $transactionId; $this->saveOrder($transactionId, $hash); $sql = "SELECT `ordernumber` FROM `s_order` WHERE `transactionID` = ?"; $this->ordernumber = Shopware()->Db()->fetchOne($sql, array($transactionId)); $sql = "SELECT `id` FROM `s_order` WHERE `transactionID` = ?"; $this->orderId = Shopware()->Db()->fetchOne($sql, array($transactionId)); Shopware()->Session()->pi_ratepay_ordernumber = $this->ordernumber; if ($this->getPaymentShortName() == 'RatePAYRate') $this->saveRateDetails(); historyEntry($this->ordernumber, '<b class=\"green\">Bestellung ist eingegangen</b>', '', '', ''); $this->saveRatepayDetails(); $this->saveStats(true); $this->saveOrderDetails(); $this->saveShippingCosts(); $sql = "UPDATE `s_order` SET `cleared` = ? WHERE `ordernumber` = ?"; Shopware()->Db()->query($sql, array((int)getAcceptedStatusId(), $this->ordernumber)); $this->redirect(array('controller' => 'checkout', 'action' => 'finish', 'sUniqueID' => $hash, 'forceSecure' => true)); }
/** * Gets all orders that where payed with RatePAY and delivers a JSON String. * Checks all orders that have the "pending" state and changes the state if neccesary. * * @see templates/backend/plugins/PigmbhRatePAYPayment/index.php * @return void */ public function getOrdersAction() { $this->View()->setTemplate(); $start = (int)isset($this->Request()->start)? $this->Request()->start: 0; $limit = (int)isset($this->Request()->limit)? $this->Request()->limit: 10; $paidString = $this->Request()->nurbezahlt == 'true'? "AND a.cleared = ".(int)getAcceptedStatusId()."": ""; $search = isset($this->Request()->search)? $this->Request()->search: ''; $search = Shopware()->Db()->quote($search); $searchFor = isset($this->Request()->suchenach)? $this->Request()->suchenach: 1; $searchString = ""; if ($search == '') $searchFor = 3; switch ($searchFor) { case 1: $searchString = "a.ordernumber LIKE '%" . $search . "%' OR a.transactionID LIKE '%" . $search . "%' OR d.description LIKE '%" . $search . "%' OR b.lastname LIKE '%" . $search . "%' "; break; case 2: $searchString = "a.ordernumber LIKE '%" . $search . "%'"; break; case 3: $searchString = "a.transactionID LIKE '%" . $search . "%'"; break; case 4: $searchString = "d.description LIKE '%" . $search . "%'"; break; case 5: $searchString = "b.lastname LIKE '%" . $search . "%'"; break; } $sql = "SELECT DISTINCT a.id AS id, a.ordertime AS bestellzeit, a.ordernumber AS bestellnr, a.transactionID AS transaktion, a.invoice_amount AS betrag, CONCAT(b.firstname,' ', b.lastname) AS kunde, c.description AS zahlstatus, d.description AS bestellstatus, e.description AS zahlart, f.name AS sprache FROM `s_order` AS a LEFT JOIN `s_user_billingaddress` b ON a.userID = b.UserID LEFT JOIN `s_core_states` c ON a.cleared = c.id LEFT JOIN `s_core_states` d ON a.status = d.id LEFT JOIN `s_core_paymentmeans` e ON a.paymentID = e.id LEFT JOIN `s_core_multilanguage` f ON a.language = f.isocode WHERE " . $searchString . " " . $paidString . " AND(a.paymentID = ? OR a.paymentID = ? OR a.paymentID = ?) AND a.cleared !='Abgebrochen' ORDER BY a.ordertime DESC LIMIT " . $start . "," . $limit . ""; $orders = Shopware()->Db()->fetchAll($sql,array( (int)getInvoicePaymentId(), (int)getRatePaymentId(), (int)getDebitPaymentId() )); $total = Shopware()->Db()->fetchAll(substr($sql, 0, strpos($sql, 'LIMIT')),array( (int)getInvoicePaymentId(), (int)getRatePaymentId(), (int)getDebitPaymentId() )); foreach ($orders as $key => $order) { $dispatchId = $this->_getDispatchId($order['bestellnr']); $dispatchId == 0? $order['versand'] = 'Keine Versandkosten': $order['versand'] = $this->_getDispatchName($dispatchId); $order['userid'] = $this->_getUserId($order['bestellnr']); $order['kunde'] = htmlentities($order['kunde']); $order['RatePAYid'] = ($key + 1) + $start; $order['betrag'] = number_format($order['betrag'], 2, ',', '.'); $order['bestellstatus_kurz'] = $this->_removeSpans($order['bestellstatus']); $order['bestellstatus']= str_replace('\"', "", $order['bestellstatus']); $order['zahlstatus']= str_replace('\"', "", $order['zahlstatus']); $order['zahlstatus_kurz'] = $this->_removeSpans($order['zahlstatus']);; $order['options_delete'] = ' '; $img = $this->_getImgPath($order['zahlart']); $order['zahlart'] = '<a title="Bestellung Nr. ' . $order['bestellnr'] . ' bearbeiten" class="mylogoonclick" onclick="orderwindow(' . $order['id'] . ',' . $order['bestellnr'] . ',\'' . $order['kunde'] . '\')">' . '<img class="RatePAY_order_img" src="' . $img . '" width="65px";/></a>'; $order['options_RatePAY'] = '<a class ="pencil myonclick" title="Bestellung Nr. ' . $order['bestellnr'] . ' bearbeiten" onclick="orderwindow(' . $order['id'] . ',' . $order['bestellnr'] . ',\'' . $order['kunde'] . '\')"> </a>'; $orders[$key] = $order; } echo json_encode(array("total" => count($total), "items" => $orders)); }
/** * get Invoices that were made with this plugin and update payment ID */ protected function getOldInvoices() { try { $sql = "SELECT order_number, payment_name from pi_ratepay_orders"; $ratepayOrders = Shopware()->Db()->fetchAll($sql); foreach($ratepayOrders as $ratepayOrder){ $sql = "SELECT `id` FROM `s_core_paymentmeans` WHERE `name` LIKE ?"; $newPaymentId = Shopware()->Db()->fetchOne($sql, array($ratepayOrder['payment_name'])); $sql = "UPDATE `s_order` SET `paymentID` = ?, `cleared` = ? WHERE `ordernumber` = ?"; Shopware()->Db()->query($sql, array((int)$newPaymentId,(int)getAcceptedStatusId(), $ratepayOrder["order_number"])); $sql = "UPDATE `pi_ratepay_orders` SET `payment_id`= ? WHERE `order_number` = ?"; Shopware()->Db()->query($sql, array((int)$newPaymentId, $ratepayOrder["order_number"])); } } catch (Exception $e) { $this->uninstall(); throw new Exception('<b>Fehler beim laden alter RatePAY Rechnungen(getOldInvoices)</b><br />' . $e); } }
/** * Confirm payment request * * @param Object $pi_RatePAY_request Current request * @param Object $config Plugin configobject * @param Array $userData Userdata */ function confirmPayment($config, $userData) { if(!Shopware()->Session()->pi_ratepay_Confirm){ Shopware()->Session()->pi_ratepay_Confirm = true; $liveMode = checkSandboxMode($userData["additional"]["payment"]["name"]); include_once dirname(__FILE__) . '/../Views/Frontend/Ratenrechner/php/pi_ratepay_xml_service.php'; $operation = 'PAYMENT_CONFIRM'; $ratepay = new pi_ratepay_xml_service(); $ratepay->live = $liveMode; $request = $ratepay->getXMLObject(); $sql = "SELECT `ordernumber` FROM `s_order` WHERE `transactionID` = ?"; $myordernumber = Shopware()->Db()->fetchOne($sql, array(Shopware()->Session()->pi_ratepay_transactionID)); $customer = $userData['billingaddress']['firstname'] . ' ' . $userData['billingaddress']['lastname']; setRatepayHead($request, $operation, false, $myordernumber); $response = $ratepay->paymentOperation($request); if ($response) { writeLog( Shopware()->Session()->pi_ratepay_ordernumber, Shopware()->Session()->pi_ratepay_transactionID, "PAYMENT_CONFIRM", "", $request, $response, $customer, $userData["additional"]["payment"]["name"] ); $sql = "UPDATE `s_order` SET `cleared` = ? WHERE `ordernumber` = ?"; if ((string) $response->head->processing->status->attributes()->code == "OK" && (string) $response->head->processing->result->attributes()->code == "400") { Shopware()->Db()->query($sql, array((int)getAcceptedStatusId(), $myordernumber)); } else { Shopware()->Db()->query($sql, array((int)getDeclinedStatusId(), $myordernumber)); } } else { writeLog("", Shopware()->Session()->pi_ratepay_transactionID, "PAYMENT_CONFIRM", "", $request, "", $customer,$userData["additional"]["payment"]["name"]); return true; } } }