/** * EBANX return response - gets called after returning from the EBANX checkout * @return void */ function ebanx_return_response() { $ebanxWC = new WC_Gateway_Ebanx(); $response = \Ebanx\Ebanx::doQuery(array('hash' => $_GET['hash'])); $orderId = (int) $response->payment->order_number; $order = new WC_Order($orderId); if (isset($response->status) && $response->status == 'SUCCESS' && $response->payment->status == 'CO') { if ($response->payment->status == 'CO') { $order->add_order_note(__('EBANX payment completed, Hash: ' . $response->payment->hash, 'woocommerce')); $order->payment_complete(); } } wp_redirect($ebanxWC->get_return_url($order)); exit; }
public function getCallbackOwnerTransaction() { $this->callEbanxLib(); $request = \XLite\Core\Request::getInstance(); $hashes = explode(',', $request->hash_codes); $result = \Ebanx\Ebanx::doQuery(array('hash' => $hashes[0])); return $result->payment->merchant_payment_code ? \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\Transaction')->find($result->payment->merchant_payment_code) : null; }
/** * Notification URI for the EBANX robot * @return void */ public function notifyAction() { $hashes = $this->getRequest()->getParam('hash_codes'); if (isset($hashes) && $hashes != null) { $hashes = explode(',', $hashes); foreach ($hashes as $hash) { $orderPayment = Mage::getModel('sales/order_payment')->getCollection()->addFieldToFilter('ebanx_hash', $hash)->getFirstItem(); $response = \Ebanx\Ebanx::doQuery(array('hash' => $hash)); if ($response->status == 'SUCCESS') { try { // Get the new status from Magento $orderStatus = $this->_getOrderStatus($response->payment->status); // Update order status $order = Mage::getModel('sales/order')->load($orderPayment->getParentId(), 'entity_id'); // Checks if the order exists if (!$order->getRealOrderId()) { throw new Exception('Order cannot be found.'); } // If payment status is CA - Canceled - AND order can be cancelled if ($response->payment->status == 'CA' && $order->canCancel()) { if (!$order->canCancel()) { throw new Exception('Order cannot be canceled, assuming already processed.'); } // Cancel order $order->cancel(); // Set orderStatus to Generic canceled status - nothing more to do $orderStatus = 'canceled'; // Comment on order $order->addStatusHistoryComment('Automatically CANCELED by EBANX Notification.', false); } // If payment status is CO - Paid - AND order can be invoiced if ($response->payment->status == 'CO') { // If can NOT Invoice or order is not new if (!$order->canInvoice()) { throw new Exception('Order cannot be invoiced, assuming already processed.'); } // Invoice $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice(); $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE); $invoice->register(); $invoice->getOrder()->setCustomerNoteNotify(true); $invoice->getOrder()->setIsInProcess(true); // Commit invoice to order $transactionSave = Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder()); $transactionSave->save(); // Comment on order $order->addStatusHistoryComment('Automatically INVOICED by EBANX Notification.', false); $order->getSendConfirmation(); $order->setEmailSent(true); $order->sendNewOrderEmail(); } // Set status $order->addStatusToHistory($orderStatus, 'Status changed by EBANX Notification.', false)->save(); echo 'OK: payment ' . $hash . ' was updated<br>'; } catch (Exception $e) { echo 'NOK: payment ' . $hash . ' could not update order, Exception: ' . $e->getMessage() . '<br>'; } } else { echo 'NOK: payment ' . $hash . ' could not be updated.<br>'; } } } else { echo 'NOK: empty request.'; } }