Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 /**
  * [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()) {
         if (isset($_POST['stripeToken'])) {
             //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)));
             }
             // include class vendor
             require Kohana::find_file('vendor/stripe/lib', 'Stripe');
             // Set your secret key: remember to change this to your live secret key in production
             // See your keys here https://manage.stripe.com/account
             Stripe::setApiKey(Core::config('payment.stripe_private'));
             // Get the credit card details submitted by the form
             $token = Core::post('stripeToken');
             // email
             $email = Core::post('stripeEmail');
             // Create the charge on Stripe's servers - this will charge the user's card
             try {
                 $charge = Stripe_Charge::create(array("amount" => StripeKO::money_format($order->amount), "currency" => $order->currency, "card" => $token, "description" => $order->product->title));
                 //mark as paid
                 $order->confirm_payment('stripe', Core::post('stripeToken'), NULL, NULL, NULL, StripeKO::calculate_fee($order->amount));
             } catch (Stripe_CardError $e) {
                 // The card has been declined
                 Kohana::$log->add(Log::ERROR, 'Stripe The card has been declined');
                 Alert::set(Alert::ERROR, 'Stripe The card has been declined');
                 $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'checkout', 'id' => $order->id_order)));
             }
             //redirect him to the goal
             Alert::set(Alert::SUCCESS, __('Thanks for your payment!'));
             $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'goal', '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)));
     }
 }
Ejemplo n.º 3
0
 /**
  * [action_form] generates the form to pay at paypal
  */
 public function action_3d()
 {
     $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()) {
         //dr($_GET);
         if (Core::get('status') == 'succeeded' and Core::get('id') != NULL) {
             try {
                 // include class vendor
                 require Kohana::find_file('vendor/stripe', 'init');
                 // Set your secret key: remember to change this to your live secret key in production
                 // See your keys here https://manage.stripe.com/account
                 \Stripe\Stripe::setAppInfo('Open eShop', Core::VERSION, 'https://open-eshop.com');
                 \Stripe\Stripe::setApiKey(Core::config('payment.stripe_private'));
                 // Create the charge on Stripe's servers - this will charge the user's card
                 $charge = \Stripe\Charge::create(array("amount" => StripeKO::money_format($order->amount), "currency" => $order->currency, "card" => Core::get('id'), "description" => $order->product->title, "metadata" => array("id_order" => $order->id_order)));
                 //mark as paid
                 $order->confirm_payment('stripe', $charge->id, NULL, NULL, NULL, StripeKO::calculate_fee($order->amount));
             } catch (Exception $e) {
                 // The card has been declined
                 Kohana::$log->add(Log::ERROR, 'Stripe The card has been declined');
                 Alert::set(Alert::ERROR, 'The card has been declined');
                 $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'checkout', 'id' => $order->id_order)));
             }
             //redirect him to the goal
             Alert::set(Alert::SUCCESS, __('Thanks for your payment!'));
             $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'goal', '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)));
     }
 }