/** * 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()) { //hack jquery paymill Paymill::jquery(); //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(__('Pricing'))->set_url(Route::url('pricing'))); 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')); } }
public function action_210() { //add new order fields try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "orders` ADD `amount_net` DECIMAL(14,3) NOT NULL DEFAULT '0' AFTER `amount`;")->execute(); DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "orders` ADD `gateway_fee` DECIMAL(14,3) NOT NULL DEFAULT '0' AFTER `amount_net`;")->execute(); DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "orders` ADD `VAT_amount` DECIMAL(14,3) NOT NULL DEFAULT '0' AFTER `VAT`;")->execute(); } catch (exception $e) { } //make posts bigger description try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "posts` CHANGE `description` `description` LONGTEXT;")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "content` CHANGE `description` `description` LONGTEXT;")->execute(); } catch (exception $e) { } //bigger configs try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "config` CHANGE `config_value` `config_value` LONGTEXT;")->execute(); } catch (exception $e) { } //recalculate all the orders $orders = new Model_Order(); $orders = $orders->where('status', '=', Model_Order::STATUS_PAID)->where('amount_net', '=', 0)->find_all(); foreach ($orders as $order) { if ($order->paymethod == 'stripe') { $order->gateway_fee = StripeKO::calculate_fee($order->amount); } elseif ($order->paymethod == '2checkout') { $order->gateway_fee = Twocheckout::calculate_fee($order->amount); } elseif ($order->paymethod == 'paymill') { $order->gateway_fee = Paymill::calculate_fee($order->amount); } elseif ($order->paymethod == 'authorize') { $order->gateway_fee = Controller_Authorize::calculate_fee($order->amount); } elseif ($order->paymethod == 'paypal') { //we dont have the history of the transactions so we clculate an aproximation using 4% $order->gateway_fee = 4 * $order->amount / 100; } else { $order->gateway_fee = 0; } //get VAT paid if ($order->VAT > 0) { $order->VAT_amount = $order->amount - 100 * $order->amount / (100 + $order->VAT); } else { $order->VAT_amount = 0; } //calculate net amount $order->amount_net = $order->amount - $order->gateway_fee - $order->VAT_amount; try { $order->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } //new configs $configs = array(array('config_key' => 'stripe_alipay', 'group_name' => 'payment', 'config_value' => '0'), array('config_key' => 'captcha', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'recaptcha_active', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'recaptcha_secretkey', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'recaptcha_sitekey', 'group_name' => 'general', 'config_value' => '')); Model_Config::config_array($configs); }
/** * Initialize Paymill library with $config arguments */ function initialize($config = array()) { extract($config); if (isset($config['paymill_test']) && !$config['paymill_test'] || !isset($config['paymill_test'])) { self::$apiKey = $config['paymill_apiKey']; self::$apiEndPoint = $config['paymill_apiEndPoint']; } else { if (isset($config['paymill_test']) && $config['paymill_test']) { self::$apiKey = $config['paymill_apiKey_test']; self::$apiEndPoint = $config['paymill_apiEndPoint_test']; } } }
/** * [action_form] generates the form to pay at paypal */ public function action_pay() { $this->auto_render = FALSE; $id_order = $this->request->param('id'); //retrieve info for the item in DB $order = new Model_Order(); $order = $order->where('id_order', '=', $id_order)->where('status', '=', Model_Order::STATUS_CREATED)->limit(1)->find(); if ($order->loaded()) { //its a fraud...lets let him know if ($order->is_fraud() === TRUE) { Alert::set(Alert::ERROR, __('We had, issues with your transaction. Please try paying with another paymethod.')); $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'checkout', 'id' => $order->id_order))); } //Functions from https://github.com/paymill/paybutton-examples $privateApiKey = Core::config('payment.paymill_private'); if (isset($_POST['paymillToken'])) { $token = $_POST['paymillToken']; $client = Paymill::request('clients/', array(), $privateApiKey); $payment = Paymill::request('payments/', array('token' => $token, 'client' => $client['id']), $privateApiKey); $transaction = Paymill::request('transactions/', array('amount' => Paymill::money_format($order->amount), 'currency' => $order->currency, 'client' => $client['id'], 'payment' => $payment['id'], 'description' => $order->product->title), $privateApiKey); if (isset($transaction['status']) && $transaction['status'] == 'closed') { //mark as paid $order->confirm_payment('paymill', Core::post('paymillToken'), NULL, NULL, NULL, Paymill::calculate_fee($order->amount)); //redirect him to his ads Alert::set(Alert::SUCCESS, __('Thanks for your payment!')); $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'goal', 'id' => $order->id_order))); } else { $msg = __('Transaction not successful!'); if (!$transaction['status'] == 'closed') { $msg .= ' - ' . $transaction['data']['error']; } Kohana::$log->add(Log::ERROR, 'Paymill ' . $msg); Alert::set(Alert::ERROR, $msg); $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'checkout', 'id' => $order->id_order))); } } else { Alert::set(Alert::INFO, __('Please fill your card details.')); $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'checkout', 'id' => $order->id_order))); } } else { Alert::set(Alert::INFO, __('Order could not be loaded')); $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'checkout', 'id' => $order->id_order))); } }
</a> </li> </ul> <?php } ?> <?php if (Theme::get('premium') == 1) { ?> <?php echo Controller_Authorize::form($order); ?> <div class="text-right"> <ul class="list-inline"> <?php if (($pm = Paymill::button($order)) != '') { ?> <li class="text-right"><?php echo $pm; ?> </li> <?php } ?> </ul> </div> <div class="text-right"> <ul class="list-inline"> <?php if (($sk = StripeKO::button($order)) != '') { ?>
src="https://button.paymill.com/v1/" id="button" data-label="<?php echo __('Pay with Card'); ?> " data-title="<?php echo Model_Order::product_desc($order->id_product); ?> " data-description="<?php echo Text::limit_chars(Text::removebbcode($order->description), 30, NULL, TRUE); ?> " data-amount="<?php echo Paymill::money_format($order->amount); ?> " data-currency="<?php echo $order->currency; ?> " data-submit-button="<?php echo __('Pay'); ?> <?php echo i18n::format_currency($order->amount, $order->currency); ?> " data-elv="false" data-lang="en-GB"
/** * pay! */ public function action_checkout() { if (!Auth::instance()->logged_in()) { $this->redirect(Route::get('oc-panel')->uri()); } $user = Auth::instance()->get_user(); //resend confirmation email if (is_numeric($id_order = $this->request->param('id'))) { $order = new Model_Order($id_order); if ($order->loaded() and $order->id_user == $user->id_user and $order->status == Model_Order::STATUS_CREATED) { //hack jquery paymill Paymill::jquery(); //verify the coupon and check order against user information, if its different update order info and maybe price! $order->check_pricing(); $this->template->title = __('Checkout'); Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title)); $this->template->content = View::factory('pages/product/checkout', array('order' => $order, 'user' => $user, 'product' => $order->product)); } else { Alert::set(Alert::WARNING, __('Order not found or already paid')); $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders'))); } } else { Alert::set(Alert::ERROR, __('Order not found')); $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders'))); } }