/** * generates HTML for apy buton * @param Model_Order $order * @return string */ public static function button(Model_Order $order) { if (Core::config('payment.mercadopago_client_id') != '' and Core::config('payment.mercadopago_client_secret') != '' and Theme::get('premium') == 1) { // Include Mercadopago library require Kohana::find_file('vendor/mercadopago', 'mercadopago'); // Create an instance with your MercadoPago credentials (CLIENT_ID and CLIENT_SECRET): $mp = new MP(core::config('payment.mercadopago_client_id'), core::config('payment.mercadopago_client_secret')); $preference_data = array("items" => array(array("id" => $order->id_order, "title" => Model_Order::product_desc($order->id_product), "currency_id" => $order->currency, "picture_url" => $order->ad->get_first_image(), "description" => Text::limit_chars(Text::removebbcode($order->description), 30, NULL, TRUE), "category_id" => $order->ad->category->name, "quantity" => 1, "unit_price" => self::money_format($order->amount))), "payer" => array("name" => Auth::instance()->get_user()->name, "email" => Auth::instance()->get_user()->email), "back_urls" => array("success" => Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')), "failure" => Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order))), "auto_return" => "approved", "notification_url" => Route::url('default', array('controller' => 'mercadopago', 'action' => 'ipn', 'id' => $order->id_order)), "expires" => false); $preference = $mp->create_preference($preference_data); $link = $preference["response"]["init_point"]; return View::factory('pages/mercadopago/button', array('link' => $link)); } return ''; }
/** * creates an order * @param Model_Ad $ad * @param Model_User $user * @param integer $id_product * @param numeric $amount * @param string $currency * @param string $description * @return Model_Order */ public static function new_order(Model_Ad $ad, $user, $id_product, $amount, $currency = NULL, $description = NULL, $featured_days = NULL) { if ($currency === NULL) { $currency = core::config('payment.paypal_currency'); } if ($description === NULL) { $description = Model_Order::product_desc($id_product); } //get if theres an unpaid order for this product and this ad $order = new Model_Order(); $order->where('id_ad', '=', $ad->id_ad)->where('id_user', '=', $user->id_user)->where('status', '=', Model_Order::STATUS_CREATED)->where('id_product', '=', $id_product)->where('amount', '=', $amount)->where('currency', '=', $currency)->limit(1)->find(); //if no unpaid create order if (!$order->loaded()) { //add coupon ID and discount only if not AD_SELL if (Model_Coupon::valid($id_product)) { $amount = Model_Coupon::price($id_product, $amount); $order->id_coupon = Model_Coupon::current()->id_coupon; } //create order $order = new Model_Order(); $order->id_user = $user->id_user; $order->id_ad = $ad->id_ad; $order->id_product = $id_product; $order->currency = $currency; $order->amount = $amount; $order->description = $description; //store how many days the ad is featured if ($featured_days !== NULL and is_numeric($featured_days)) { $order->featured_days = $featured_days; } try { $order->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } //send email to user with link to pay $url_checkout = $user->ql('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)); $replace = array('[ORDER.ID]' => $order->id_order, '[ORDER.DESC]' => $order->description, '[URL.CHECKOUT]' => $url_checkout); //$user->email('new-order',$replace); } return $order; }
/** * creates a new ad * @param array $data * @param model_user $user * @return array */ public static function new_ad($data, $user) { $return_message = ''; $checkout_url = ''; //akismet spam filter if (isset($data['title']) and isset($data['description']) and core::akismet($data['title'], $user->email, $data['description']) == TRUE) { // is user marked as spammer? Make him one :) if (core::config('general.black_list')) { $user->user_spam(); } return array('error' => __('This post has been considered as spam! We are sorry but we can not publish this advertisement.'), 'error_type' => Alert::ALERT); } //akismet $ad = new Model_Ad(); $ad->id_user = $user->id_user; $ad->values($data); $ad->seotitle = $ad->gen_seo_title($ad->title); $ad->created = Date::unix2mysql(); try { $ad->save(); } catch (ORM_Validation_Exception $e) { return array('validation_errors' => $e->errors('ad')); } catch (Exception $e) { return array('error' => $e->getMessage(), 'error_type' => Alert::ALERT); } /////////// NOTIFICATION Emails,messages to user and Status of the ad // depending on user flow (moderation mode), change usecase $moderation = core::config('general.moderation'); //calculate how much he needs to pay in case we have payment on if ($moderation == Model_Ad::PAYMENT_ON or $moderation == Model_Ad::PAYMENT_MODERATION) { // check category price, if 0 check parent if ($ad->category->price == 0) { $cat_parent = new Model_Category($ad->category->id_category_parent); //category without price if ($cat_parent->price == 0) { //swapping moderation since theres no price :( if ($moderation == Model_Ad::PAYMENT_ON) { $moderation = Model_Ad::POST_DIRECTLY; } elseif ($moderation == Model_Ad::PAYMENT_MODERATION) { $moderation = Model_Ad::MODERATION_ON; } } else { $amount = $cat_parent->price; } } else { $amount = $ad->category->price; } } //where and what we say to the user depending ont he moderation switch ($moderation) { case Model_Ad::PAYMENT_ON: case Model_Ad::PAYMENT_MODERATION: $ad->status = Model_Ad::STATUS_NOPUBLISHED; $order = Model_Order::new_order($ad, $user, Model_Order::PRODUCT_CATEGORY, $amount, NULL, Model_Order::product_desc(Model_Order::PRODUCT_CATEGORY) . ' ' . $ad->category->name); // redirect to invoice $return_message = __('Please pay before we publish your advertisement.'); $checkout_url = Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)); break; case Model_Ad::EMAIL_MODERATION: case Model_Ad::EMAIL_CONFIRMATION: $ad->status = Model_Ad::STATUS_UNCONFIRMED; $url_ql = $user->ql('oc-panel', array('controller' => 'myads', 'action' => 'confirm', 'id' => $ad->id_ad)); $user->email('ads-confirm', array('[URL.QL]' => $url_ql, '[AD.NAME]' => $ad->title)); $return_message = __('Advertisement is posted but first you need to activate. Please check your email!'); break; case Model_Ad::MODERATION_ON: $ad->status = Model_Ad::STATUS_NOPUBLISHED; $url_ql = $user->ql('oc-panel', array('controller' => 'myads', 'action' => 'update', 'id' => $ad->id_ad)); $user->email('ads-notify', array('[URL.QL]' => $url_ql, '[AD.NAME]' => $ad->title)); // email to notify user of creating, but it is in moderation currently $return_message = __('Advertisement is received, but first administrator needs to validate. Thank you for being patient!'); break; case Model_Ad::POST_DIRECTLY: default: $ad->status = Model_Ad::STATUS_PUBLISHED; $ad->published = $ad->created; $url_cont = $user->ql('contact'); $url_ad = $user->ql('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)); $user->email('ads-user-check', array('[URL.CONTACT]' => $url_cont, '[URL.AD]' => $url_ad, '[AD.NAME]' => $ad->title)); Model_Subscribe::notify($ad); $return_message = __('Advertisement is posted. Congratulations!'); break; } //save the last changes on status $ad->save(); //notify admins new ad $ad->notify_admins(); return array('message' => $return_message, 'checkout_url' => $checkout_url, 'ad' => $ad); }
</h4> </div> <div class="modal-body"> <p><a href="<?php echo Route::url('ad', array('controller' => 'ad', 'category' => $order->ad->category->seoname, 'seotitle' => $order->ad->seotitle)); ?> "> <?php echo HTML::chars($order->ad->title); ?> </a></p> <p><b><?php echo _e('Product'); ?> :</b> <?php echo Model_Order::product_desc($order->id_product); ?> </p> <p><b><?php echo _e('Date'); ?> :</b> <?php echo $order->created; ?> </p> <p><b><?php echo _e('Date Paid'); ?> :</b> <?php echo $order->pay_date; ?>
/** * pay an invoice, renders the paymenthods button, anyone with an ID of an order can pay it, we do not have control * @return [type] [description] */ public function action_checkout() { $order = new Model_Order($this->request->param('id')); if ($order->loaded()) { //if paid...no way jose if ($order->status != Model_Order::STATUS_CREATED) { Alert::set(Alert::INFO, __('This order was already paid.')); $this->redirect(Route::url('default')); } //checks coupons or amount of featured days $order->check_pricing(); //template header $this->template->title = __('Checkout') . ' ' . Model_Order::product_desc($order->id_product); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default'))); Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title)); Controller::$full_width = TRUE; $this->template->bind('content', $content); $this->template->content = View::factory('pages/ad/checkout', array('order' => $order)); } else { //throw 404 throw HTTP_Exception::factory(404, __('Page not found')); } }
?> , <?php echo __('valid until'); ?> <?php echo Date::format(Model_Coupon::current()->valid_date); ?> . <?php if (Model_Coupon::current()->id_product != NULL) { ?> <?php echo __('only valid for'); ?> <?php echo Model_Order::product_desc(Model_Coupon::current()->id_product); ?> <?php } ?> </p> <?php } else { ?> <div class="input-group"> <input class="form-control" type="text" name="coupon" value="<?php echo Core::get('coupon'); echo Core::get('coupon'); ?> " placeholder="<?php echo __('Coupon Name');
<?php echo sprintf(__('Discount off %s'), Model_Coupon::current()->discount_amount == 0 ? round(Model_Coupon::current()->discount_percentage, 0) . '%' : i18n::money_format(Model_Coupon::current()->discount_amount)); ?> <br> <?php echo sprintf(__('%s coupons left'), Model_Coupon::current()->number_coupons); ?> , <?php echo sprintf(__('valid until %s'), Date::format(Model_Coupon::current()->valid_date, core::config('general.date_format'))); ?> . <?php if (Model_Coupon::current()->id_product != NULL) { ?> <?php echo sprintf(__('only valid for %s'), Model_Order::product_desc(Model_Coupon::current()->id_product)); ?> <?php } ?> </p> <?php } else { ?> <div class="form-group"> <div class="input-group"> <input class="form-control" type="text" name="coupon" value="<?php echo Core::get('coupon'); echo Core::get('coupon'); ?> " placeholder="<?php
<td><?php echo $element->name; ?> </td> <td> <?php if (isset($element->produt)) { ?> <?php echo $element->product->title; ?> <?php } elseif (method_exists('Model_Order', 'product_desc')) { ?> <?php echo ($product_desc = Model_Order::product_desc($element->id_product)) == '' ? __('Any') : $product_desc; ?> <?php } else { ?> <?php echo $element->id_product; ?> <?php } ?> </td> <td> <?php echo $element->discount_amount == 0 ? round($element->discount_percentage, 0) . '%' : i18n::money_format($element->discount_amount); ?>
public static function get_order_array($order) { $o = $order->as_array(); $o['user']['id'] = $order->user->id_user; $o['user']['email'] = $order->user->email; $o['product'] = Model_Order::product_desc($order->id_product); $o['coupon'] = $order->coupon->loaded() ? $order->coupon->as_array() : NULL; return $o; }
/** * pay an invoice, renders the paymenthods button, anyone with an ID of an order can pay it, we do not have control * @return [type] [description] */ public function action_checkout() { $order = new Model_Order($this->request->param('id')); if ($order->loaded()) { //if paid...no way jose if ($order->status != Model_Order::STATUS_CREATED) { Alert::set(Alert::INFO, __('This order was already paid.')); $this->redirect(Route::url('default')); } //update order based on the price and the amount of $days = core::get('featured_days'); if (is_numeric($days) and ($price = Model_Order::get_featured_price($days)) !== FALSE) { $order->amount = $price; //get price from config $order->featured_days = $days; $order->save(); } //template header $this->template->title = __('Checkout') . ' ' . Model_Order::product_desc($order->id_product); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default'))); Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title)); Controller::$full_width = TRUE; $this->template->bind('content', $content); $this->template->content = View::factory('pages/ad/checkout', array('order' => $order)); } else { //throw 404 throw HTTP_Exception::factory(404, __('Page not found')); } }