/** * expired featured ads * @return void */ public static function renew() { if (Core::config('general.subscriptions') == TRUE) { //get expired subscription that are active $subscriptions = new Model_Subscription(); $subscriptions = $subscriptions->where('status', '=', 1)->where('expire_date', '<=', Date::unix2mysql())->order_by('created', 'desc')->find_all(); foreach ($subscriptions as $s) { //disable the plan $s->status = 0; try { $s->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } $plan = $s->plan; if ($plan->loaded() and $plan->status == 1) { //generate a new order $order = Model_Order::new_order(NULL, $s->user, $plan->id_plan, $plan->price, core::config('payment.paypal_currency'), __('Subscription to ') . $plan->name); //free plan no checkout if ($plan->price == 0) { $order->confirm_payment('cash'); } else { $paid = FALSE; //customers who paid with sripe we can charge the recurrency if ($order->user->stripe_agreement != NULL) { StripeKO::init(); // 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, 'customer' => $order->user->stripe_agreement, "description" => $order->description, "metadata" => array("id_order" => $order->id_order))); $paid = TRUE; } catch (Exception $e) { // The card has been declined Kohana::$log->add(Log::ERROR, 'Stripe The card has been declined'); $paid = FALSE; } } if ($paid === TRUE) { //mark as paid $order->confirm_payment('stripe', $charge->id); } else { $checkout_url = $s->user->ql('default', array('controller' => 'plan', 'action' => 'checkout', 'id' => $order->id_order)); $s->user->email('plan-expired', array('[PLAN.NAME]' => $plan->name, '[URL.CHECKOUT]' => $checkout_url)); } } } //if plan loaded } //end foreach } //if subscription active }
/** * [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' => 'ad', '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->description)); } 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' => 'ad', 'action' => 'checkout', 'id' => $order->id_order))); } //mark as paid $order->confirm_payment('stripe', Core::post('stripeToken')); //redirect him to his ads Alert::set(Alert::SUCCESS, __('Thanks for your payment!')); $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders'))); } else { Alert::set(Alert::INFO, __('Please fill your card details.')); $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order))); } } else { Alert::set(Alert::INFO, __('Order could not be loaded')); $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order))); } }
/** * [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 and ($customer_id = Session::instance()->get('customer_id')) != NULL) { try { StripeKO::init(); // 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, 'customer' => $customer_id, "description" => $order->description, "metadata" => array("id_order" => $order->id_order))); } 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' => 'ad', 'action' => 'checkout', 'id' => $order->id_order))); } //its a plan product if ($order->id_product >= 100) { //save the stripe user id to be able to charge them later on renewal $order->user->stripe_agreement = $customer_id; $order->user->save(); } //mark as paid $order->confirm_payment('stripe', $charge->id); //redirect him to his ads Alert::set(Alert::SUCCESS, __('Thanks for your payment!')); $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders'))); } else { Alert::set(Alert::INFO, __('Please fill your card details.')); $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order))); } } else { Alert::set(Alert::INFO, __('Order could not be loaded')); $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order))); } }
echo __('Pay with Card'); ?> " data-name="<?php echo Model_Order::product_desc($order->id_product); ?> " data-description="<?php echo Text::limit_chars(Text::removebbcode($order->description), 30, NULL, TRUE); ?> " <?if (Auth::instance()->logged_in()):?> data-email="<?php echo Auth::instance()->get_user()->email; ?> " <?endif?> data-amount="<?php echo StripeKO::money_format($order->amount); ?> " data-currency="<?php echo $order->currency; ?> " <?php echo Core::config('payment.stripe_address') == TRUE ? 'data-address = "TRUE"' : ''; ?> > </script> </form>
/** * gets the payment token from stripe and marks order as paid. Methos for application fee */ public function action_payconnect() { //TODO only if stripe connect enabled $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)->where('id_product', '=', Model_Order::PRODUCT_AD_SELL)->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' => 'ad', 'action' => 'checkout', 'id' => $order->id_order))); } // 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::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 { //in case memberships the fee may be set on the plan ;) $fee = NULL; if ($order->ad->user->subscription()->loaded()) { $fee = $order->ad->user->subscription()->plan->marketplace_fee; } $application_fee = StripeKO::application_fee($order->amount, $fee); //we charge the fee only if its not admin if (!$order->ad->user->is_admin()) { $charge = \Stripe\Charge::create(array("amount" => StripeKO::money_format($order->amount), "currency" => $order->currency, "card" => $token, "description" => $order->description, "application_fee" => StripeKO::money_format($application_fee)), array('stripe_account' => $order->ad->user->stripe_user_id)); } else { $charge = \Stripe\Charge::create(array("amount" => StripeKO::money_format($order->amount), "currency" => $order->currency, "card" => $token, "description" => $order->description)); } } catch (Exception $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' => 'ad', 'action' => 'checkout', 'id' => $order->id_order))); } //mark as paid $order->confirm_payment('stripe', Core::post('stripeToken')); //only if is not admin if (!$order->ad->user->is_admin()) { //crete new order for the application fee so we know how much the site owner is earning ;) $order_app = Model_Order::new_order($order->ad, $order->ad->user, Model_Order::PRODUCT_APP_FEE, $application_fee, core::config('payment.paypal_currency'), 'id_order->' . $order->id_order . ' id_ad->' . $order->ad->id_ad); $order_app->confirm_payment('stripe', Core::post('stripeToken')); } //redirect him to his ads Alert::set(Alert::SUCCESS, __('Thanks for your payment!')); $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders'))); } else { Alert::set(Alert::INFO, __('Please fill your card details.')); $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order))); } } else { Alert::set(Alert::INFO, __('Order could not be loaded')); $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order))); } }
/** * [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))); } }
defined('SYSPATH') or die('No direct script access.'); ?> $('#stripe_button').click(function(){ var token = function(res){ var $input = $('<input type=hidden name=stripeToken />').val(res.id); $('#stripe_form').append($input).submit(); }; StripeCheckout.open({ key: '<?php echo Core::config('payment.stripe_public'); ?> ', amount: <?php echo StripeKO::money_format($product->final_price()); ?> , currency: '<?php echo $product->currency; ?> ', name: '<?php echo $product->title; ?> ', description: '<?php echo Text::limit_chars(Text::removebbcode($product->description), 30, NULL, TRUE); ?> ', <?php