/** * Retrieves the OrderPayment object, created at validateOrder. And add transaction id. * @param string $mollie_payment_id * @return bool */ public function save_order_transaction_id($mollie_payment_id) { // retrieve ALL payments of order. // in the case of a cancel or expired on banktransfer, this will fire too. // if no OrderPayment objects is retrieved in the collection, do nothing. $order = new Order($this->module->currentOrder); $collection = OrderPayment::getByOrderReference($order->reference); if (count($collection) > 0) { $order_payment = $collection[0]; // for older versions (1.5) , we check if it hasn't been filled yet. if (!$order_payment->transaction_id) { $order_payment->transaction_id = $mollie_payment_id; $order_payment->update(); } } }
private function onCancelPayments($Model) { //$this->log('ESTADO DE LA ORDEN AL TRATAR DE CANCELAR EL PAGO'); //$this->log($Model->data['Order']['status']); $OrderPayment = new OrderPayment(); if ('cancelled' == $Model->data['Order']['status'] && 0 < $Model->data['Order']['total_amt']) { $OrderPayment->recursive = -1; if (!$OrderPayment->updateAll(array('OrderPayment.order_id' => $Model->data['Order']["id"]), array('OrderPayment.status =' => 'cancelled'))) { $this->log('NO SE PUDIERON ACTUALIZARLOSPAGOS A CANCELADOS'); } } return $Model; }
/** * 更新 * * @param $id */ public function actionUpdate($id) { $model = OrdersAdmin::model()->findByPk($id); $order_payment = OrderPayment::model()->find('order_id=:order_id', array(':order_id' => $id)); if (!empty($order_payment)) { $order_payment = OrderPayment::model()->find('order_id=:order_id', array(':order_id' => $id)); if ($order_payment->aid > 0) { $user = User::model()->findByPk($order_payment->aid); if (!empty($user)) { $admin_name = $user->username; } else { $admin_name = '管理员ID' . $order_payment->aid; } } else { $admin_name = '系统'; } } if (isset($_POST['OrdersAdmin'])) { $model->attributes = $_POST['OrdersAdmin']; //更新时间 $model->update_time = date('Y-m-d H:i:s'); if ($model->save()) { $this->message('success', Yii::t('admin', 'Update Success'), $this->createUrl('index')); } else { $this->message('error', Yii::t('admin', 'Update error'), $this->createUrl('index')); } } $this->render('update', array('model' => $model, 'order_payment' => $order_payment, 'admin_name' => $admin_name)); }
public function validateOrderPay($id_cart, $id_order_state, $amount_paid, $extraCosts, $payment_method = 'Unknown', $message = null, $extra_vars = array(), $currency_special = null, $dont_touch_amount = false, $secure_key = false, Shop $shop = null) { $statusPending = Configuration::get('PAYNL_WAIT'); $statusPaid = Configuration::get('PAYNL_SUCCESS'); // Als er nog geen order van dit cartid is, de order valideren. $orderId = Order::getOrderByCartId($id_cart); if ($orderId == false) { if ($id_order_state == $statusPaid) { if ($extraCosts != 0) { $id_order_state_tmp = $statusPending; } else { $id_order_state_tmp = $statusPaid; } } else { $id_order_state_tmp = $id_order_state; } $result = parent::validateOrder($id_cart, $id_order_state_tmp, $amount_paid, $payment_method, $message, $extra_vars, $currency_special, $dont_touch_amount, $secure_key, $shop); $orderId = $this->currentOrder; if ($extraCosts == 0 && $id_order_state_tmp == $statusPaid) { //Als er geen extra kosten zijn, en de order staat op betaald zijn we klaar return $result; } } if ($orderId && $id_order_state == $statusPaid) { $order = new Order($orderId); $shippingCost = $order->total_shipping; $newShippingCosts = $shippingCost + $extraCosts; $extraCostsExcl = round($extraCosts / (1 + 21 / 100), 2); if ($extraCosts != 0) { //als de order extra kosten heeft, moeten deze worden toegevoegd. $order->total_shipping = $newShippingCosts; $order->total_shipping_tax_excl = $order->total_shipping_tax_excl + $extraCostsExcl; $order->total_shipping_tax_incl = $newShippingCosts; $order->total_paid_tax_excl = $order->total_paid_tax_excl + $extraCostsExcl; $order->total_paid_tax_incl = $order->total_paid_real = $order->total_paid = $order->total_paid + $extraCosts; } $result = $order->addOrderPayment($amount_paid, $payment_method, $extra_vars['transaction_id']); if (number_format($order->total_paid_tax_incl, 2) !== number_format($amount_paid, 2)) { $id_order_state = Configuration::get('PS_OS_ERROR'); } //paymentid ophalen $orderPayment = OrderPayment::getByOrderId($order->id); $history = new OrderHistory(); $history->id_order = (int) $order->id; $history->changeIdOrderState((int) $id_order_state, $order, $orderPayment); $res = Db::getInstance()->getRow(' SELECT `invoice_number`, `invoice_date`, `delivery_number`, `delivery_date` FROM `' . _DB_PREFIX_ . 'orders` WHERE `id_order` = ' . (int) $order->id); $order->invoice_date = $res['invoice_date']; $order->invoice_number = $res['invoice_number']; $order->delivery_date = $res['delivery_date']; $order->delivery_number = $res['delivery_number']; $order->update(); $history->addWithemail(); } return $result; }
/** * postPayment */ public function postPayment() { $data = Input::all(); //$data['paydate'] = strtotime($data['paydate']); //插入payments $payment = OrderPayment::create($data); $payments = OrderPayment::where('order_id', Input::get('order_id'))->get(); return View::make('admin.orders.payment')->with('payments', $payments); }
/** * Confirms requesting a refund */ public function displayAjax() { $order = new Order(Tools::getValue('order')); $payments = OrderPayment::getByOrderId(Tools::getValue('order')); $sumOfPayments = 0.0; foreach ($payments as $payment) { if ($payment->payment_method == $this->module->displayName) { $sumOfPayments += (double) $payment->amount; } } if (abs($sumOfPayments) < 0.01) { $sumOfPayments = 0.0; } $sa = new DotpaySellerApi($this->config->getDotpaySellerApiUrl()); $payment = $sa->getPaymentByNumber($this->config->getDotpayApiUsername(), $this->config->getDotpayApiPassword(), Tools::getValue('payment')); if (isset($payment->payment_method)) { $channel = $payment->payment_method->channel_id; unset($payment->payment_method); $payment->channel_id = $channel; } $payment->sum_of_payments = $sumOfPayments; $payment->return_description = $this->l('Refund of order:') . ' ' . $order->reference; die(json_encode($payment)); }
/** * * This method allows to add a payment to the current order * @since 1.5.0.1 * @param float $amount_paid * @param string $payment_method * @param string $payment_transaction_id * @param Currency $currency * @param string $date * @param OrderInvoice $order_invoice * @return bool */ public function addOrderPayment($amount_paid, $payment_method = null, $payment_transaction_id = null, $currency = null, $date = null, $order_invoice = null) { $order_payment = new OrderPayment(); $order_payment->order_reference = $this->reference; $order_payment->id_currency = $currency ? $currency->id : $this->id_currency; // we kept the currency rate for historization reasons $order_payment->conversion_rate = $currency ? $currency->conversion_rate : 1; // if payment_method is define, we used this $order_payment->payment_method = $payment_method ? $payment_method : $this->payment; $order_payment->transaction_id = $payment_transaction_id; $order_payment->amount = $amount_paid; $order_payment->date_add = $date ? $date : null; // Update total_paid_real value for backward compatibility reasons if ($order_payment->id_currency == $this->id_currency) { $this->total_paid_real += $order_payment->amount; } else { $this->total_paid_real += Tools::ps_round(Tools::convertPrice($order_payment->amount, $order_payment->id_currency, false), 2); } // We put autodate parameter of add method to true if date_add field is null $res = $order_payment->add(is_null($order_payment->date_add)) && $this->update(); if (!$res) { return false; } if (!is_null($order_invoice)) { $res = Db::getInstance()->execute(' INSERT INTO `' . _DB_PREFIX_ . 'order_invoice_payment` (`id_order_invoice`, `id_order_payment`, `id_order`) VALUES(' . (int) $order_invoice->id . ', ' . (int) $order_payment->id . ', ' . (int) $this->id . ')'); // Clear cache Cache::clean('order_invoice_paid_*'); } return $res; }
/** * Sets the new state of the given order * * @param int $new_order_state * @param int/object $id_order * @param bool $use_existing_payment */ public function changeIdOrderState($new_order_state, $id_order, $use_existing_payment = false) { if (!$new_order_state || !$id_order) { return; } if (!is_object($id_order) && is_numeric($id_order)) { $order = new Order((int) $id_order); } elseif (is_object($id_order)) { $order = $id_order; } else { return; } ShopUrl::cacheMainDomainForShop($order->id_shop); $new_os = new OrderState((int) $new_order_state, $order->id_lang); $old_os = $order->getCurrentOrderState(); $is_validated = $this->isValidated(); // executes hook if (in_array($new_os->id, array(Configuration::get('PS_OS_PAYMENT'), Configuration::get('PS_OS_WS_PAYMENT')))) { Hook::exec('actionPaymentConfirmation', array('id_order' => (int) $order->id), null, false, true, false, $order->id_shop); } // executes hook Hook::exec('actionOrderStatusUpdate', array('newOrderStatus' => $new_os, 'id_order' => (int) $order->id), null, false, true, false, $order->id_shop); if (Validate::isLoadedObject($order) && $new_os instanceof OrderState) { // An email is sent the first time a virtual item is validated $virtual_products = $order->getVirtualProducts(); if ($virtual_products && (!$old_os || !$old_os->logable) && $new_os && $new_os->logable) { $context = Context::getContext(); $assign = array(); foreach ($virtual_products as $key => $virtual_product) { $id_product_download = ProductDownload::getIdFromIdProduct($virtual_product['product_id']); $product_download = new ProductDownload($id_product_download); // If this virtual item has an associated file, we'll provide the link to download the file in the email if ($product_download->display_filename != '') { $assign[$key]['name'] = $product_download->display_filename; $dl_link = $product_download->getTextLink(false, $virtual_product['download_hash']) . '&id_order=' . (int) $order->id . '&secure_key=' . $order->secure_key; $assign[$key]['link'] = $dl_link; if (isset($virtual_product['download_deadline']) && $virtual_product['download_deadline'] != '0000-00-00 00:00:00') { $assign[$key]['deadline'] = Tools::displayDate($virtual_product['download_deadline']); } if ($product_download->nb_downloadable != 0) { $assign[$key]['downloadable'] = (int) $product_download->nb_downloadable; } } } $customer = new Customer((int) $order->id_customer); $links = '<ul>'; foreach ($assign as $product) { $links .= '<li>'; $links .= '<a href="' . $product['link'] . '">' . Tools::htmlentitiesUTF8($product['name']) . '</a>'; if (isset($product['deadline'])) { $links .= ' ' . Tools::htmlentitiesUTF8(Tools::displayError('expires on', false)) . ' ' . $product['deadline']; } if (isset($product['downloadable'])) { $links .= ' ' . Tools::htmlentitiesUTF8(sprintf(Tools::displayError('downloadable %d time(s)', false), (int) $product['downloadable'])); } $links .= '</li>'; } $links .= '</ul>'; $data = array('{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{id_order}' => (int) $order->id, '{order_name}' => $order->getUniqReference(), '{nbProducts}' => count($virtual_products), '{virtualProducts}' => $links); // If there's at least one downloadable file if (!empty($assign)) { Mail::Send((int) $order->id_lang, 'download_product', Mail::l('Virtual product to download', $order->id_lang), $data, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, null, null, _PS_MAIL_DIR_, false, (int) $order->id_shop); } } // @since 1.5.0 : gets the stock manager $manager = null; if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { $manager = StockManagerFactory::getManager(); } $errorOrCanceledStatuses = array(Configuration::get('PS_OS_ERROR'), Configuration::get('PS_OS_CANCELED')); // foreach products of the order if (Validate::isLoadedObject($old_os)) { foreach ($order->getProductsDetail() as $product) { // if becoming logable => adds sale if ($new_os->logable && !$old_os->logable) { ProductSale::addProductSale($product['product_id'], $product['product_quantity']); // @since 1.5.0 - Stock Management if (!Pack::isPack($product['product_id']) && in_array($old_os->id, $errorOrCanceledStatuses) && !StockAvailable::dependsOnStock($product['id_product'], (int) $order->id_shop)) { StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int) $product['product_quantity'], $order->id_shop); } } elseif (!$new_os->logable && $old_os->logable) { ProductSale::removeProductSale($product['product_id'], $product['product_quantity']); // @since 1.5.0 - Stock Management if (!Pack::isPack($product['product_id']) && in_array($new_os->id, $errorOrCanceledStatuses) && !StockAvailable::dependsOnStock($product['id_product'])) { StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int) $product['product_quantity'], $order->id_shop); } } elseif (!$new_os->logable && !$old_os->logable && in_array($new_os->id, $errorOrCanceledStatuses) && !in_array($old_os->id, $errorOrCanceledStatuses) && !StockAvailable::dependsOnStock($product['id_product'])) { StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int) $product['product_quantity'], $order->id_shop); } // @since 1.5.0 : if the order is being shipped and this products uses the advanced stock management : // decrements the physical stock using $id_warehouse if ($new_os->shipped == 1 && $old_os->shipped == 0 && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && Warehouse::exists($product['id_warehouse']) && $manager != null && ((int) $product['advanced_stock_management'] == 1 || Pack::usesAdvancedStockManagement($product['product_id']))) { // gets the warehouse $warehouse = new Warehouse($product['id_warehouse']); // decrements the stock (if it's a pack, the StockManager does what is needed) $manager->removeProduct($product['product_id'], $product['product_attribute_id'], $warehouse, $product['product_quantity'], Configuration::get('PS_STOCK_CUSTOMER_ORDER_REASON'), true, (int) $order->id); } elseif ($new_os->shipped == 0 && $old_os->shipped == 1 && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && Warehouse::exists($product['id_warehouse']) && $manager != null && ((int) $product['advanced_stock_management'] == 1 || Pack::usesAdvancedStockManagement($product['product_id']))) { // if the product is a pack, we restock every products in the pack using the last negative stock mvts if (Pack::isPack($product['product_id'])) { $pack_products = Pack::getItems($product['product_id'], Configuration::get('PS_LANG_DEFAULT', null, null, $order->id_shop)); foreach ($pack_products as $pack_product) { if ($pack_product->advanced_stock_management == 1) { $mvts = StockMvt::getNegativeStockMvts($order->id, $pack_product->id, 0, $pack_product->pack_quantity * $product['product_quantity']); foreach ($mvts as $mvt) { $manager->addProduct($pack_product->id, 0, new Warehouse($mvt['id_warehouse']), $mvt['physical_quantity'], null, $mvt['price_te'], true); } if (!StockAvailable::dependsOnStock($product['id_product'])) { StockAvailable::updateQuantity($pack_product->id, 0, (int) $pack_product->pack_quantity * $product['product_quantity'], $order->id_shop); } } } } else { $mvts = StockMvt::getNegativeStockMvts($order->id, $product['product_id'], $product['product_attribute_id'], $product['product_quantity']); foreach ($mvts as $mvt) { $manager->addProduct($product['product_id'], $product['product_attribute_id'], new Warehouse($mvt['id_warehouse']), $mvt['physical_quantity'], null, $mvt['price_te'], true); } } } } } } $this->id_order_state = (int) $new_order_state; // changes invoice number of order ? if (!Validate::isLoadedObject($new_os) || !Validate::isLoadedObject($order)) { die(Tools::displayError('Invalid new order state')); } // the order is valid if and only if the invoice is available and the order is not cancelled $order->current_state = $this->id_order_state; $order->valid = $new_os->logable; $order->update(); if ($new_os->invoice && !$order->invoice_number) { $order->setInvoice($use_existing_payment); } // set orders as paid if ($new_os->paid == 1) { $invoices = $order->getInvoicesCollection(); if ($order->total_paid != 0) { $payment_method = Module::getInstanceByName($order->module); } foreach ($invoices as $invoice) { $rest_paid = $invoice->getRestPaid(); if ($rest_paid > 0) { $payment = new OrderPayment(); $payment->order_reference = $order->reference; $payment->id_currency = $order->id_currency; $payment->amount = $rest_paid; if ($order->total_paid != 0) { $payment->payment_method = $payment_method->displayName; } else { $payment->payment_method = null; } // Update total_paid_real value for backward compatibility reasons if ($payment->id_currency == $order->id_currency) { $order->total_paid_real += $payment->amount; } else { $order->total_paid_real += Tools::ps_round(Tools::convertPrice($payment->amount, $payment->id_currency, false), 2); } $order->save(); $payment->conversion_rate = 1; $payment->save(); Db::getInstance()->execute(' INSERT INTO `' . _DB_PREFIX_ . 'order_invoice_payment` VALUES(' . (int) $invoice->id . ', ' . (int) $payment->id . ', ' . (int) $order->id . ')'); } } } // updates delivery date even if it was already set by another state change if ($new_os->delivery) { $order->setDelivery(); } // executes hook Hook::exec('actionOrderStatusPostUpdate', array('newOrderStatus' => $new_os, 'id_order' => (int) $order->id), null, false, true, false, $order->id_shop); ShopUrl::resetMainDomainCache(); }
/** * Get the detailed payment of an order * * @deprecated 1.5.3.0 * @param int $id_order * @return array */ public static function getByOrderId($id_order) { Tools::displayAsDeprecated(); $order = new Order($id_order); return OrderPayment::getByOrderReference($order->reference); }
function GetLastInvoiceOrder($id) { return \OrderPayment::where(function ($query) { $query->where('status', 2)->orWhereNull('payment_reff'); })->where('order_id', $id)->orderBy('id', 'desc')->first(); }
/** * Sets the new state of the given order * * @param int $new_order_state * @param int $id_order * @param bool $use_existing_payment */ public function changeIdOrderState($new_order_state, &$id_order, $use_existing_payment = false) { if (!$new_order_state || !$id_order) { return; } if (!is_object($id_order) && is_numeric($id_order)) { $order = new Order((int) $id_order); } elseif (is_object($id_order)) { $order = $id_order; } else { return; } $new_os = new OrderState((int) $new_order_state, $order->id_lang); $old_os = $order->getCurrentOrderState(); $is_validated = $this->isValidated(); // executes hook if ($new_os->id == Configuration::get('PS_OS_PAYMENT')) { Hook::exec('actionPaymentConfirmation', array('id_order' => (int) $order->id)); } // executes hook Hook::exec('actionOrderStatusUpdate', array('newOrderStatus' => $new_os, 'id_order' => (int) $order->id)); if (Validate::isLoadedObject($order) && $old_os instanceof OrderState && $new_os instanceof OrderState) { // @since 1.5.0 : gets the stock manager $manager = null; if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { $manager = StockManagerFactory::getManager(); } // foreach products of the order foreach ($order->getProductsDetail() as $product) { // if becoming logable => adds sale if ($new_os->logable && !$old_os->logable) { ProductSale::addProductSale($product['product_id'], $product['product_quantity']); // @since 1.5.0 - Stock Management if (!Pack::isPack($product['product_id']) && ($old_os->id == Configuration::get('PS_OS_ERROR') || $old_os->id == Configuration::get('PS_OS_CANCELED')) && !StockAvailable::dependsOnStock($product['id_product'], (int) $order->id_shop)) { StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int) $product['product_quantity'], $order->id_shop); } } elseif (!$new_os->logable && $old_os->logable) { ProductSale::removeProductSale($product['product_id'], $product['product_quantity']); // @since 1.5.0 - Stock Management if (!Pack::isPack($product['product_id']) && ($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED')) && !StockAvailable::dependsOnStock($product['id_product'])) { StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int) $product['product_quantity'], $order->id_shop); } } elseif (!$new_os->logable && !$old_os->logable && ($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED')) && !StockAvailable::dependsOnStock($product['id_product'])) { StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int) $product['product_quantity'], $order->id_shop); } // @since 1.5.0 : if the order is being shipped and this products uses the advanced stock management : // decrements the physical stock using $id_warehouse if ($new_os->shipped == 1 && $old_os->shipped == 0 && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && Warehouse::exists($product['id_warehouse']) && $manager != null && ((int) $product['advanced_stock_management'] == 1 || Pack::usesAdvancedStockManagement($product['product_id']))) { // gets the warehouse $warehouse = new Warehouse($product['id_warehouse']); // decrements the stock (if it's a pack, the StockManager does what is needed) $manager->removeProduct($product['product_id'], $product['product_attribute_id'], $warehouse, $product['product_quantity'], Configuration::get('PS_STOCK_CUSTOMER_ORDER_REASON'), true, (int) $order->id); } elseif ($new_os->shipped == 0 && $old_os->shipped == 1 && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && Warehouse::exists($product['id_warehouse']) && $manager != null && ((int) $product['advanced_stock_management'] == 1 || Pack::usesAdvancedStockManagement($product['product_id']))) { // if the product is a pack, we restock every products in the pack using the last negative stock mvts if (Pack::isPack($product['product_id'])) { $pack_products = Pack::getItems($product['product_id'], Configuration::get('PS_LANG_DEFAULT')); foreach ($pack_products as $pack_product) { if ($pack_product->advanced_stock_management == 1) { $mvts = StockMvt::getNegativeStockMvts($order->id, $pack_product->id, 0, $pack_product->pack_quantity * $product['product_quantity']); foreach ($mvts as $mvt) { $manager->addProduct($pack_product->id, 0, new Warehouse($mvt['id_warehouse']), $mvt['physical_quantity'], null, $mvt['price_te'], true); } if (!StockAvailable::dependsOnStock($product['id_product'])) { StockAvailable::updateQuantity($pack_product->id, 0, (int) $pack_product->pack_quantity * $product['product_quantity'], $order->id_shop); } } } } else { $mvts = StockMvt::getNegativeStockMvts($order->id, $product['product_id'], $product['product_attribute_id'], $product['product_quantity']); foreach ($mvts as $mvt) { $manager->addProduct($product['product_id'], $product['product_attribute_id'], new Warehouse($mvt['id_warehouse']), $mvt['physical_quantity'], null, $mvt['price_te'], true); } } } } } $this->id_order_state = (int) $new_order_state; // changes invoice number of order ? if (!Validate::isLoadedObject($new_os) || !Validate::isLoadedObject($order)) { die(Tools::displayError('Invalid new order state')); } // the order is valid if and only if the invoice is available and the order is not cancelled $order->current_state = $this->id_order_state; $order->valid = $new_os->logable; $order->update(); if ($new_os->invoice && !$order->invoice_number) { $order->setInvoice($use_existing_payment); } // set orders as paid if ($new_os->paid == 1) { $invoices = $order->getInvoicesCollection(); if ($order->total_paid != 0) { $payment_method = Module::getInstanceByName($order->module); } foreach ($invoices as $invoice) { $rest_paid = $invoice->getRestPaid(); if ($rest_paid > 0) { $payment = new OrderPayment(); $payment->order_reference = $order->reference; $payment->id_currency = $order->id_currency; $payment->amount = $rest_paid; if ($order->total_paid != 0) { $payment->payment_method = $payment_method->displayName; } else { $payment->payment_method = null; } // Update total_paid_real value for backward compatibility reasons if ($payment->id_currency == $order->id_currency) { $order->total_paid_real += $payment->amount; } else { $order->total_paid_real += Tools::ps_round(Tools::convertPrice($payment->amount, $payment->id_currency, false), 2); } $order->save(); $payment->conversion_rate = 1; $payment->save(); Db::getInstance()->execute(' INSERT INTO `' . _DB_PREFIX_ . 'order_invoice_payment` VALUES(' . (int) $invoice->id . ', ' . (int) $payment->id . ', ' . (int) $order->id . ')'); } } } // updates delivery date even if it was already set by another state change if ($new_os->delivery) { $order->setDelivery(); } // executes hook Hook::exec('actionOrderStatusPostUpdate', array('newOrderStatus' => $new_os, 'id_order' => (int) $order->id)); }
public function ajaxProcessPayOrder() { $id_order = Tools::getValue('id_order'); $order = new Order($id_order); $id_order_detail = Tools::getValue('id_order_detail'); $order_detail = new AphOrderDetail($id_order_detail); $order_detail->id_order = $id_order; $order_detail->product_quantity = 0; $res = $order_detail->update(); $order_payment = new OrderPayment(); $order_payment->order_reference = $order->reference; $order_payment->id_currency = (int) Context::getContext()->currency->id; $order_payment->amount = $products_total_price; $order_payment->payment_method = $order->payment; $order_payment->conversion_rate = $order->conversion_rate; $order_payment->add(); $order_details = AphOrderDetail::getList($id_order); if ($res && !empty($order_details) && is_array($order_details)) { $empty_detail = 0; foreach ($order_details as &$order_detail) { if ((int) $order_detail['product_quantity'] < 1) { $empty_detail++; } } if ($empty_detail == sizeof($order_details)) { $order = new Order($id_order); $order->setCurrentState(Configuration::get('APH_RESERVATION_DELETED_STATUS'), (int) Context::getContext()->employee->id); } } die(Tools::jsonEncode(array('result' => $res))); }
/** * Get Invoice Info * * @param \Illuminate\Database\Eloquent\Model * @return array $data */ protected function _getInvoiceInfo($orderPayments) { $data = []; foreach ($orderPayments as $payment) { $temp = (array) $payment; // get user info $temp['user_info'] = \User::find($payment->user_id); /** ** Menentukan date invoice used, expired date dan expired on dengan Carbon */ // get date of invoice used if ($payment->used_start == null) { if ($payment->pickup_date == null) { $temp['date_invoice_used'] = $payment->delivery_date; } else { $temp['date_invoice_used'] = $payment->pickup_date; } } else { $temp['date_invoice_used'] = $payment->used_start; } // get expired date of invoice $temp['expired_date'] = \Carbon\Carbon::parse($temp['date_invoice_used'])->addDays(31); // get interval day to expired date $now = \Carbon\Carbon::parse(date('Y-m-d')); $temp['expired_on'] = \Carbon\Carbon::parse($temp['expired_date'])->diffInDays($now, false); // get stuff invoice $temp['stuff'] = \OrderStuff::where('order_id', $payment->order_id)->whereNull('return_schedule_id')->select(['type', \DB::raw("COUNT(*) jumlah"), \DB::raw("if(type = 'box','" . \Config::get('thankspace.box.price') . "','" . \Config::get('thankspace.item.price') . "') price"), \DB::raw("(COUNT(*) * if(type = 'box','" . \Config::get('thankspace.box.price') . "','" . \Config::get('thankspace.item.price') . "')) subtotal"), \DB::raw("GROUP_CONCAT(description SEPARATOR ',') barang "), \DB::raw("GROUP_CONCAT(id SEPARATOR ',') ids ")])->groupBy('type')->get()->toArray(); // set input for new invoice $temp['new_invoice_input'] = ['payment_reff' => $payment->invoice_code, 'used_start' => $temp['expired_date']->format('Y-m-d')]; foreach ($temp['stuff'] as $val) { $type = $val['type']; $temp['new_invoice_input'][$type] = $val['jumlah']; } // new invoice $temp['new_invoice'] = null; if ($temp['next_invoice'] != null) { $temp['new_invoice'] = \OrderPayment::where('code', $temp['next_invoice'])->first(); } // push to array for return data array_push($data, $temp); } return $data; }
/** * Get a collection of order payments * * @since 1.5.0.13 */ public function getOrderPayments() { return OrderPayment::getByOrderReference($this->reference); }
/** * Function which is used to making refunds */ private function makeRefund() { $api = $this->api; $statusName = $this->api->getOperationStatusName(); if ($statusName != $api::operationCompleted && $statusName != $api::operationRejected) { die('OK'); } $order = new Order((int) $this->getDotControl(Tools::getValue('control'))); $currency = new Currency($order->id_currency); $payments = OrderPayment::getByOrderId($order->id); $foundPaymet = false; $sumOfPayments = 0.0; foreach ($payments as $payment) { $currency = Currency::getCurrency($order->id_currency); if ($payment->transaction_id == $this->api->getOperationNumber()) { die('PrestaShop - PAYMENT ' . $this->api->getOperationNumber() . ' IS ALREADY SAVED'); } else { if ($payment->transaction_id == $this->api->getRelatedOperationNumber()) { $foundPaymet = true; } } if ($payment->payment_method == $this->module->displayName) { $sumOfPayments += (double) $payment->amount; } } if (!$foundPaymet) { die('PrestaShop - PAYMENT ' . $this->api->getRelatedOperationNumber() . ' IS NOT SAVED'); } $receivedAmount = floatval($this->api->getTotalAmount()); if ($receivedAmount - $sumOfPayments >= 0.01) { die('PrestaShop - NO MATCH OR WRONG AMOUNT - ' . $receivedAmount . ' > ' . $sumOfPayments); } $lastOrderState = OrderHistory::getLastOrderState($order->id); if ($lastOrderState->id != $this->config->getDotpayWaitingRefundStatusId()) { die('PrestaShop - REFUND HAVEN\'T BEEN SUBMITTED'); } if ($this->api->getOperationStatusName() == $api::operationCompleted) { $payment = new OrderPayment(); $payment->order_reference = $order->reference; $payment->amount = (double) ('-' . Tools::getValue('operation_original_amount')); $payment->id_currency = $order->id_currency; $payment->conversion_rate = 1; $payment->transaction_id = $this->api->getOperationNumber(); $payment->payment_method = $this->module->displayName; $payment->date_add = new \DateTime(); $payment->add(); if ($receivedAmount < $sumOfPayments) { $state = $this->config->getDotpayPartialRefundStatusId(); } else { $state = $this->config->getDotpayTotalRefundStatusId(); } $history = new OrderHistory(); $history->id_order = $order->id; $history->changeIdOrderState($state, $history->id_order); $history->addWithemail(true); } else { if ($this->api->getOperationStatusName() == $api::operationRejected) { $state = $this->config->getDotpayFailedRefundStatusId(); $history = new OrderHistory(); $history->id_order = $order->id; $history->changeIdOrderState($state, $history->id_order); $history->addWithemail(true); } } die('OK'); }
/** * Save payment information. */ public function savePayment($order, $payzenResponse) { $payments = $order->getOrderPayments(); if (is_array($payments) && !empty($payments)) { foreach ($payments as $payment) { $payment->delete(); } $order->total_paid_real = 0; } if (!$this->_isSuccessState($order)) { // no payment creation return; } // save transaction info $this->logger->logInfo("Save payment information for cart #{$order->id_cart}."); $invoices = $order->getInvoicesCollection(); $invoice = count($invoices) > 0 ? $invoices[0] : null; $currency = $this->getLoadedApi()->findCurrencyByNumCode($payzenResponse->get('currency')); $paymentIds = array(); if ($payzenResponse->get('card_brand') == 'MULTI') { $sequences = json_decode($payzenResponse->get('payment_seq')); $transactions = $sequences->transactions; foreach ($transactions as $trs) { $amount = $currency->convertAmountToFloat($trs->{'amount'}); $transaction_id = $trs->{'sequence_number'} . '-' . $trs->{'trans_id'}; if ($trs->{'ext_trans_id'}) { $transaction_id .= '-' . $trs->{'ext_trans_id'}; } if (!$order->addOrderPayment($amount, null, $transaction_id, null, null, $invoice)) { throw new PrestaShopException('Can\'t save Order Payment'); } $pcc = new OrderPayment($this->_lastOrderPaymentId($order)); $paymentIds[] = $pcc->id; // set card info $pcc->card_number = $trs->{'card_number'}; $pcc->card_brand = $trs->{'card_brand'}; if ($trs->{'expiry_month'} && $trs->{'expiry_year'}) { $pcc->card_expiration = str_pad($trs->{'expiry_month'}, 2, '0', STR_PAD_LEFT) . '/' . $trs->{'expiry_year'}; } $pcc->card_holder = NULL; $pcc->update(); } } else { $amount = $currency->convertAmountToFloat($payzenResponse->get('amount')); if (!$order->addOrderPayment($amount, null, $payzenResponse->get('trans_id'), null, null, $invoice)) { throw new PrestaShopException('Can\'t save Order Payment'); } $pcc = new OrderPayment($this->_lastOrderPaymentId($order)); $paymentIds[] = $pcc->id; // set card info $pcc->card_number = $payzenResponse->get('card_number'); $pcc->card_brand = $payzenResponse->get('card_brand'); if ($payzenResponse->get('expiry_month') && $payzenResponse->get('expiry_year')) { $pcc->card_expiration = str_pad($payzenResponse->get('expiry_month'), 2, '0', STR_PAD_LEFT) . '/' . $payzenResponse->get('expiry_year'); } $pcc->card_holder = NULL; $pcc->update(); } $paymentIds = implode(', ', $paymentIds); $this->logger->logInfo("Payment information with ID(s) {$paymentIds} saved successfully for cart #{$order->id_cart}."); }
/** * Hook for displaying order by shop admin * @param array $params Details of displayed order * @return type */ public function hookDisplayAdminOrder($params) { if (!$this->config->isDotpayRefundEn()) { return; } if (Tools::getValue('dotpay_refund') !== false) { if (Tools::getValue('dotpay_refund') == 'success') { $this->context->controller->confirmations[] = $this->l('Request of refund was sent'); } else { if (Tools::getValue('dotpay_refund') == 'error') { $this->context->controller->errors[] = $this->l('An error occurred during request of refund') . '<br /><i>' . $this->context->cookie->dotpay_error . '</i>'; } } } $order = new Order($params['id_order']); $payments = OrderPayment::getByOrderId($order->id); foreach ($payments as $key => $payment) { if ($payment->amount < 0) { unset($payments[$key]); } } $paidViaDotpay = false; foreach ($payments as $payment) { $currency = Currency::getCurrency($order->id_currency); if ($payment->payment_method === $this->displayName && $currency["iso_code"] === 'PLN') { $paidViaDotpay = true; } break; } if ($paidViaDotpay) { $this->smarty->assign(array('orderId' => $order->id, 'payments' => $payments, 'returnUrl' => $this->context->link->getAdminLink('AdminDotpayRefund'))); return $this->display(__FILE__, 'orderDetails.tpl'); } return; }
/** * Get invoice detail * * @param integer $id * @return \Illuminate\Database\Eloquent\Model */ public function getInvoiceDetail($id) { return \OrderPayment::with(['Order' => function ($query) { $query->with('orderSchedule', 'orderStuff', 'user'); }])->find($id); }
/** * @since 1.5.0.2 * @return PrestaShopCollection Collection of Order payment */ public function getOrderPaymentCollection() { return OrderPayment::getByInvoiceId($this->id); }
public function hookactionBeforeAddOrder($params) { if (!$this->active) { return false; } if ($this->ref_orderid or $this->ref_cartid or $this->ref_prefsign) { $order_payment = new OrderPayment(); $transaction_id = $order_payment->getByOrderReference($params['order']->reference); if ($ref = $this->generateReferenceFromID($params['order']->id, $params['cart']->id, $params['order']->reference)) { $params['order']->reference = $ref; } if (count($transaction_id)) { foreach ($transaction_id as $transaction) { $transaction->order_reference = $params['order']->reference; $transaction->update(); } } return $ref; } else { return false; } }