示例#1
0
 /**
  * Get additional content data selected
  *
  * @param $result = Query result
  */
 public static function post_find($result)
 {
     if ($result !== null) {
         if (is_array($result)) {
             foreach ($result as $item) {
                 // It will first check if we already have result in temporary result,
                 // and only execute query if we dont. That way we dont have duplicate queries
                 // Get products
                 $item->get_products = static::lazy_load(function () use($item) {
                     return Model_Products::find(array('where' => array('order_id' => $item->id)));
                 }, $item->id, 'products');
                 // Get order payments
                 $item->get_payments = static::lazy_load(function () use($item) {
                     return \Payment\Model_Payment::find(array('where' => array('order_id' => $item->id), 'order_by' => array('id' => 'desc')));
                 }, $item->id, 'payments');
                 // Get last payment status
                 $item->get_last_payment = static::lazy_load(function () use($item) {
                     $payments = \Payment\Model_Payment::find(array('where' => array('order_id' => $item->id), 'order_by' => array('id' => 'desc')));
                     return isset($payments[0]) ? $payments[0] : array();
                 }, $item->id, 'last_payment', 'object');
             }
         }
     }
     // return the result
     return $result;
 }
示例#2
0
 /**
  * Get additional content data selected
  *
  * @param $result = Query result
  */
 public static function post_find($result)
 {
     if ($result !== null) {
         if (is_array($result)) {
             foreach ($result as $item) {
                 // It will first check if we already have result in temporary result,
                 // and only execute query if we dont. That way we dont have duplicate queries
                 // Get products
                 $item->get_products = static::lazy_load(function () use($item) {
                     return Model_Products::find(array('where' => array('order_id' => $item->id)));
                 }, $item->id, 'products');
                 // Get order payments
                 $item->get_payments = static::lazy_load(function () use($item) {
                     return \Payment\Model_Payment::find(array('where' => array('order_id' => $item->id), 'order_by' => array('id' => 'desc')));
                 }, $item->id, 'payments');
                 // Get last payment status
                 $item->get_last_payment = static::lazy_load(function () use($item) {
                     $payments = \Payment\Model_Payment::find(array('where' => array('order_id' => $item->id), 'order_by' => array('id' => 'desc')));
                     return isset($payments[0]) ? $payments[0] : array();
                 }, $item->id, 'last_payment', 'object');
                 // Get history
                 $item->get_history = static::lazy_load(function () use($item) {
                     return Model_History::find(array('where' => array('order_id' => $item->id), 'order_by' => array('created_at' => 'desc')));
                 }, $item->id, 'history');
                 // Get artworks
                 $item->get_artwork = static::lazy_load(function () use($item) {
                     return Model_Artwork::find(array('where' => array('order_id' => $item->id)));
                 }, $item->id, 'artwork');
                 // Get artworks status
                 $item->get_artwork_status = static::lazy_load(function () use($item) {
                     $out = array(0, 0);
                     $products = Model_Products::find(array('where' => array('order_id' => $item->id, 'artwork_required' => 1)));
                     if (!$products) {
                         return $out;
                     }
                     $out[0] = count($products);
                     foreach ($products as $product) {
                         if ($product->artwork) {
                             $out[1]++;
                         }
                     }
                     return $out;
                 }, $item->id, 'artwork_status', 'array');
                 // Get order user object
                 $item->get_user = static::lazy_load(function () use($item) {
                     return \Sentry::user((int) $item->user_id);
                 }, $item->id, 'user', 'object');
             }
         }
     }
     // return the result
     return $result;
 }
 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();
 }
示例#4
0
 /**
  * Publish order job
  *
  * @access public
  * @param  object	          $order = Order object
  * @param  array of objects   $products = Products from order
  * @return void
  */
 public function publish_order_job($order = false, $products = false)
 {
     return \Payment\Model_Payment::publish_order_job($order, $products);
 }
示例#5
0
 /**
  * Catch IPN response from PayPal
  *
  * @access  public
  * @return  void
  */
 public function action_ipn()
 {
     \Package::load('paypalipn');
     $post = \Input::post();
     $admin_email = '*****@*****.**';
     if (isset($post['invoice']) || is_numeric($post['invoice'])) {
         if ($order = \Order\Model_Order::find_one_by_id($post['invoice'])) {
             $order_info = $this->order_info($post['invoice']);
             //$validate_order['mc_currency'] =  strtoupper($order['currency']);
             $validate_order['mc_currency'] = "AUD";
             $validate_order['mc_gross'] = $order_info['grand_total_price'];
             $response = \PaypalIpn::forge()->validate($validate_order);
             $response_check = $response !== false;
             //                @mail($admin_email, \Config::get('site_title', 'Giant Invitation Australia') . ' Pre response ' . $response['invoice'],
             //                    'Order id : ' . $response['invoice'] . "\n" .
             //                    'Response:' . print_r($response, true) . "\n" .
             //                    'Check:' . $response_check);
             $payment = \Payment\Model_Payment::forge();
             /*
             [mc_gross] => 527.00
             [invoice] => 9
             [protection_eligibility] => Eligible
             [address_status] => confirmed
             [item_number1] =>
             [tax] => 0.00
             [item_number2] =>
             [payer_id] => 2AY578XVRY42G
             [address_street] => 1 Main St
             [payment_date] => 05:19:51 Dec 20, 2012 PST
             [payment_status] => Completed
             [charset] => windows-1252
             [address_zip] => 95131
             [mc_shipping] => 0.00
             [mc_handling] => 0.00
             [first_name] => Djordje
             [mc_fee] => 20.90
             [address_country_code] => US
             [address_name] => Djordje Dimitrijev
             [notify_version] => 3.7
             [custom] =>
             [payer_status] => verified
             [business] => s01_1354717870_biz@eximius-solutions.com
             [address_country] => United States
             [num_cart_items] => 2
             [mc_handling1] => 0.00
             [mc_handling2] => 0.00
             [address_city] => San Jose
             [verify_sign] => Amjz0My6wXvXmjP5pfTStQO3QZ2QA4.Ti6ln42PKcmRKuS-ZegoVx6nF
             [payer_email] => b01_1354717574_per@eximius-solutions.com
             [mc_shipping1] => 0.00
             [mc_shipping2] => 0.00
             [tax1] => 0.00
             [tax2] => 0.00
             [txn_id] => 3AR12649JA9996934
             [payment_type] => instant
             [last_name] => Dimitrijev
             [address_state] => CA
             [item_name1] => Fujiyama
             [receiver_email] => s01_1354717870_biz@eximius-solutions.com
             [item_name2] => Musala
             [payment_fee] =>
             [quantity1] => 2
             [quantity2] => 1
             [receiver_id] => W4MYKU8N4SVHS
             [txn_type] => cart
             [mc_gross_1] => 398.00
             [mc_currency] => EUR
             [mc_gross_2] => 129.00
             [residence_country] => US
             [test_ipn] => 1
             [transaction_subject] => Shopping CartFujiyamaMusala
             [payment_gross] =>
             [ipn_track_id] => 72c4d71c8638a
             */
             if ($response !== false) {
                 $json_response = json_encode($response);
                 $payment->order_id = $response['invoice'];
                 $payment->total_price = $response['mc_gross'];
                 $payment->method = 'paypal';
                 $payment->status = $response['payment_status'];
                 $payment->response = $json_response;
                 if (isset($response['pending_reason'])) {
                     $payment->status_detail = $response['pending_reason'];
                 }
                 if (strtolower($response['payment_status']) == 'completed') {
                     // Send email
                     /*$emailer = new \PaymentProccess\PaymentEmailer($order);
                       $emailer->send();*/
                     $emailer = new \Autorespondertrigger\Trigger();
                     $emailer->sendOrderPaymentReceivedPaypalCredit($order);
                     $order->total_price = $order_info['total_price'];
                     $order->paymentmethod = 'N/A';
                     if (isset($order->payments[0]->method)) {
                         $order->paymentmethod = $order->payments[0]->method;
                     }
                     // Create redemption code ( if order is sample order - this will be checked in RedemptionCodeSaverClass)
                     $redemptionCodeSaver = new \DiscountCodeApplier\RedemptionCodeSaver($order);
                     $redemptionCodeSaver->save();
                 } else {
                     logger(\Fuel::L_INFO, 'PayPal IPN - Pending order. Order ID: ' . $response['invoice'] . '. - ' . $json_response);
                     @mail($admin_email, \Config::get('site_title', 'Giant Invitation Australia') . ' | PayPal IPN - Pending order. Order ID: ' . $response['invoice'], 'PayPal IPN - Pending order. Order ID: ' . $response['invoice'] . "\n" . print_r($response, true));
                 }
             } else {
                 $payment->order_id = $post['invoice'];
                 $payment->total_price = $post['mc_gross'];
                 $payment->method = 'paypal';
                 $payment->status = 'Pending';
                 $payment->response = json_encode($post);
                 // Log order as failed
                 logger(\Fuel::L_INFO, 'PayPal IPN - Failed order. Order ID: ' . $response['invoice'] . '. - ' . $json_response);
                 @mail($admin_email, \Config::get('site_title', 'Giant Invitation Australia') . ' | PayPal IPN - Failed order. Order ID: ' . $response['invoice'], 'PayPal IPN - Failed order. Order ID: ' . $response['invoice'] . "\n" . print_r($response, true));
             }
             // Save payment to database
             try {
                 $payment->save();
             } catch (\Database_Exception $e) {
                 logger(\Fuel::L_INFO, 'PayPal IPN - error during inserting data into the database. Order ID: ' . $response['invoice'] . '. - ' . $json_response);
                 @mail($admin_email, \Config::get('site_title', 'My Shortlist') . ' | PayPal IPN - DB error. Order ID: ' . $response['invoice'], 'PayPal IPN - error during inserting data into the database. Order ID: ' . $response['invoice'] . "\n" . print_r($response, true));
             }
         } else {
             logger(\Fuel::L_INFO, 'PayPal IPN - error. There is no order with ID: ' . $post['invoice'] . '. - ' . json_encode($post));
             @mail($admin_email, \Config::get('site_title', 'My Shortlist') . ' | PayPal IPN - error. There is no order with ID: ' . $post['invoice'], 'PayPal IPN - there is no order with ID: ' . $post['invoice'] . "\n" . print_r($post, true));
         }
     } else {
         logger(\Fuel::L_INFO, 'PayPal IPN - error. Missing Order ID. - ' . json_encode($post));
         @mail($admin_email, \Config::get('site_title', 'My Shortlist') . ' | PayPal IPN - error. Missing Order ID.', 'PayPal IPN - Missing Order ID.' . "\n" . print_r($post, true));
     }
 }
 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')));
     }
     $user = \Sentry::user();
     if ($order = $this->save_order()) {
         $payment = \Payment\Model_Payment::forge();
         $payment->order_id = $order->id;
         $payment->total_price = $order->total_price;
         $payment->method = 'credit';
         $payment->status = 'ordered';
         $payment->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')));
 }
示例#7
0
 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')));
 }
     echo \Form::label('Payment Method');
     ?>
                                     <?php 
     echo \Form::select('payment_method', \Input::get('payment_method'), array('false' => 'Select') + $payment_method, array('class' => 'select_init filter_width'));
     ?>
                                 </div>
                             <?php 
 }
 ?>
                             
                             
                              <?php 
 /************ Start generating query for payment status ***********/
 $items = \Payment\Model_Payment::find(function ($query) {
     $query->select('status');
     $query->order_by('status', 'asc');
     $query->distinct();
 });
 $payment_status = array();
 if ($items) {
     foreach ($items as $item) {
         if (!$item->status) {
             continue;
         }
         $payment_status[$item->status] = $item->status;
     }
 }
 ?>
                             <?php 
 if (in_array('payment_status', $options)) {
     ?>