public function savePaymentDetails($type, $order, $status, $statusDetail, $response = array()) { // start - update number of stock for successful payment if ($status == 'Completed') { foreach ($order->products as $product) { if ($product->attributes_id) { $get_attributes = \Product\Model_Attribute::find_one_by(array('product_id' => $product->product_id, 'attributes' => $product->attributes_id)); $get_attributes->set(array('stock_quantity' => $get_attributes->stock_quantity - $product->quantity)); $get_attributes->save(); } else { $get_attributes = \Product\Model_Attribute::find_one_by_product_id($product->product_id); $get_attributes->set(array('stock_quantity' => $get_attributes->stock_quantity - $product->quantity)); $get_attributes->save(); } } } // end - update number of stock for successful payment $exists = \Payment\Model_Payment::find_one_by_order_id($order->id); if ($exists) { $this->payment = $exists; } $this->payment->set(array('order_id' => $order->id, 'total_price' => $order->total_price + $order->shipping_price - $order->discount_amount, 'method' => $type, 'status' => $status, 'status_detail' => $statusDetail, 'response' => json_encode($response))); $this->savePayment(); }
public function action_credit() { if (!$this->check_logged()) { \Messages::error('You must be logged in if you want to continue with your order.'); \Response::redirect(\Uri::create('order/checkout/address')); } if (!\Input::post()) { throw new \HttpNotFoundException(); } if (\Input::post('order_type') == 'payment') { \Response::redirect(\Uri::create('order/checkout/payment')); } $credit_account = \Order\Model_Order::credit_account(null, \Cart::getTotal('price')); if (\Input::post('order_type') != 'credit') { \Messages::error('There was an error while trying to save your order.'); \Response::redirect(\Input::referrer(\Uri::create('order/checkout/cost'))); } if (!$credit_account['credit'] || $credit_account['over_limit']) { \Messages::error("You don't have permission for this action."); \Response::redirect(\Input::referrer(\Uri::create('order/checkout/cost'))); } $items = \Cart::items(); $user = \Sentry::user(); if ($order = $this->save_order()) { $payment = \Payment\Model_Payment::find_one_by_order_id($order->id); if (!isset($payment)) { $payment = \Payment\Model_Payment::forge(); } $total_price = $order->total_price ? $order->total_price + $order->shipping_price - $order->discount_amount : $order['total_price'] + $order['shipping_price'] - $order['discount_amount']; $payment->set(array('order_id' => $order->id, 'total_price' => $total_price, 'method' => 'credit', 'status' => 'ordered', 'status_detail' => 'Credit Account')); $payment->save(); $this->autoresponder($user, $order); \Response::redirect(\Input::referrer(\Uri::create('order/checkout/complete/' . $order->id))); } \Messages::error('There was an error while trying to save your order.'); \Response::redirect(\Input::referrer(\Uri::create('order/checkout/cost'))); }