public function charge() { $id = $this->inputfilter->clean($this->app->get('PARAMS.id'), 'alnum'); $request = $this->getModel()->setState('filter.id', $id)->getItem(); $settings = \Striper\Models\Settings::fetch(); // 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($settings->{$settings->mode . '.secret_key'}); // Get the credit card token submitted by the form $token = $this->inputfilter->clean($this->app->get('POST.stripeToken'), 'string'); // Create the charge on Stripe's servers - this will charge the user's card try { $charge = \Stripe_Charge::create(array("amount" => $request->amountForStripe(), "currency" => "usd", "card" => $token, "description" => $request->{'client.email'})); // this needs to be created empty in model $request->acceptPayment($charge); // SEND email to the client $request->sendChargeEmailClient($charge); $request->sendChargeEmailAdmin($charge); $this->app->set('charge', $charge); $this->app->set('paymentrequest', $request); $view = \Dsc\System::instance()->get('theme'); echo $view->render('Striper/Site/Views::paymentrequest/success.php'); } catch (\Stripe_CardError $e) { // The card has been declined $view = \Dsc\System::instance()->get('theme'); echo $view->render('Striper/Site/Views::paymentrequest/index.php'); } }
protected function runSite() { \Dsc\System::instance()->get('theme')->registerViewPath($this->dir . '/src/Striper/Site/Views', 'Striper/Site/Views'); $settings = \Striper\Models\Settings::fetch(); // 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($settings->{$settings->mode . '.secret_key'}); parent::runSite(); }
public function read() { $id = $this->inputfilter->clean($this->app->get('PARAMS.id'), 'alnum'); $number = $this->inputfilter->clean($this->app->get('PARAMS.number'), 'cmd'); // these are like slugs, and can have a hyphen in them $model = $this->getModel(); if ($id) { $model->setState('filter.id', $id); } elseif ($number) { $model->setState('filter.number', $number); } else { \Dsc\System::instance()->addMessage("Invalid Item", 'error'); $this->app->reroute('/'); } try { $subscription = $model->getItem(); if (empty($subscription->id)) { throw new \Exception(); } } catch (\Exception $e) { \Dsc\System::instance()->addMessage("Invalid Item", 'error'); $this->app->reroute('/'); return; } $this->app->set('subscription', $subscription); if (empty($subscription->subscriber)) { $this->app->set('meta.title', $subscription->title); $settings = \Striper\Models\Settings::fetch(); // Set your secret key: remember to change this to your live secret key in production // See your keys here https://manage.stripe.com/account $this->app->set('plan', \Stripe_Plan::retrieve($subscription->{'plan'})); $this->app->set('settings', $settings); echo $this->theme->render('Striper/Site/Views::subscription/read.php'); } else { echo $this->theme->render('Striper/Site/Views::subscription/alreadypaid.php'); } }
protected function doAdd($data) { if (empty($this->list_route)) { throw new \Exception('Must define a route for listing the items'); } if (empty($this->create_item_route)) { throw new \Exception('Must define a route for creating the item'); } if (empty($this->edit_item_route)) { throw new \Exception('Must define a route for editing the item'); } if (!isset($data['submitType'])) { $data['submitType'] = "save_edit"; } $f3 = \Base::instance(); $flash = \Dsc\Flash::instance(); $model = $this->getModel(); // save try { $values = $data; $create = array_filter($values['stripe']); //make a method for this, convert float to cents $create['amount'] = (int) $create['amount']; $settings = \Striper\Models\Settings::fetch(); // 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($settings->{$settings->mode . '.secret_key'}); $plan = \Stripe\Plan::create($create); $values['stripe'] = array('id' => $plan->id, 'name' => $plan->name, 'created' => $plan->created, 'amount' => $plan->amount, 'interval' => $plan->interval, 'currency' => $plan->currency, 'interval_count' => $plan->interval_count, 'trial_period_days' => $plan->trial_period_days); unset($values['submitType']); //\Dsc\System::instance()->addMessage(\Dsc\Debug::dump($values), 'warning'); $this->item = $model->create($values); } catch (\Exception $e) { \Dsc\System::instance()->addMessage('Save failed with the following errors:', 'error'); \Dsc\System::instance()->addMessage($e->getMessage(), 'error'); if (\Base::instance()->get('DEBUG')) { \Dsc\System::instance()->addMessage($e->getTraceAsString(), 'error'); } if ($f3->get('AJAX')) { // output system messages in response object return $this->outputJson($this->getJsonResponse(array('error' => true, 'message' => \Dsc\System::instance()->renderMessages()))); } // redirect back to the create form with the fields pre-populated \Dsc\System::instance()->setUserState('use_flash.' . $this->create_item_route, true); $flash->store($data); $this->setRedirect($this->create_item_route); return false; } // redirect to the editing form for the new item \Dsc\System::instance()->addMessage('Item saved', 'success'); if (method_exists($this->item, 'cast')) { $this->item_data = $this->item->cast(); } else { $this->item_data = \Joomla\Utilities\ArrayHelper::fromObject($this->item); } if ($f3->get('AJAX')) { return $this->outputJson($this->getJsonResponse(array('message' => \Dsc\System::instance()->renderMessages(), 'result' => $this->item_data))); } switch ($data['submitType']) { case "save_new": $route = $this->create_item_route; break; case "save_close": $route = $this->list_route; break; default: $flash->store($this->item_data); $id = $this->item->get($this->getItemKey()); $route = str_replace('{id}', $id, $this->edit_item_route); break; } $this->setRedirect($route); return $this; }