Add bookmark exports and sharing + various fixes

This commit is contained in:
Joey Kimsey
2024-12-15 17:20:57 -05:00
parent 3ef97138a2
commit ab2f009e5b
26 changed files with 975 additions and 297 deletions

View File

@ -30,42 +30,46 @@ use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Classes\Forms;
use TheTempusProject\Bedrock\Functions\Hash;
use TheTempusProject\Canary\Bin\Canary as Debug;
use Stripe\StripeClient;
class Member extends Controller {
public static $customers;
public static $products;
public static $stripe;
private static $loaded = false;
public function __construct() {
parent::__construct();
Template::noIndex();
$api_key = Config::getValue( 'memberships/stripeSecret' );
self::$customers = new MembershipCustomers;
self::$products = new MembershipProducts;
if ( ! self::$loaded ) {
Template::noIndex();
self::$customers = new MembershipCustomers;
self::$products = new MembershipProducts;
$api_key = Config::getValue( 'memberships/stripeSecret' );
if ( $api_key == 'sk_xxxxxxxxxxxxxxx' || empty($api_key) ) {
Debug::error( "Memberships:__construct No Stripe Key found" );
} else {
self::$stripe = new StripeClient( $api_key );
}
self::$loaded = true;
}
}
public function index() {
$this->confirmAuth();
self::$title = 'Members Area';
if ( !App::$isMember ) {
Session::flash( 'error', 'You do not have permission to view this page.' );
return Redirect::home();
}
Views::view( 'members.members' );
}
public function managepayment( $id = null ) {
$api_key = Config::getValue( 'memberships/stripeSecret' );
$stripe = new \Stripe\StripeClient( $api_key );
$customer = self::$customers->findOrCreate( App::$activeUser->ID );
$this->confirmAuth();
$customer = self::$customers->findByUserID( App::$activeUser->ID );
if ( empty( $customer ) ) {
Session::flash( 'error', 'You do not have any active payment methods. You can subscribe by going <a href="/member/join/1">here</a>' );
return Redirect::to( 'member/manage' );
}
try {
$session = $stripe->billingPortal->sessions->create([
$session = self::$stripe->billingPortal->sessions->create([
'customer' => $customer,
'return_url' => Routes::getAddress() . 'member/manage',
]);
@ -76,21 +80,14 @@ class Member extends Controller {
return Redirect::to( 'member/manage' );
}
header('Location: ' . $session->url);
exit;
}
public function cancelconfirm( $id = null ) {
$this->confirmAuth();
$memberships = new Memberships;
$result = $memberships->cancel( $id );
// dv( $result );
if ( ! empty( $result ) ) {
Session::flash( 'success', 'Your Membership has been paused.' );
Redirect::to( 'member/manage' );
@ -101,9 +98,9 @@ class Member extends Controller {
}
public function pauseconfirm( $id = null ) {
$this->confirmAuth();
$memberships = new Memberships;
$result = $memberships->cancel( $id );
// dv( $result );
if ( ! empty( $result ) ) {
Session::flash( 'success', 'Your Membership has been paused.' );
Redirect::to( 'member/manage' );
@ -114,42 +111,64 @@ class Member extends Controller {
}
public function pause( $id = null ) {
$this->confirmAuth();
self::$title = 'pause Membership';
Components::set( 'pauseid', $id );
Views::view( 'members.pause' );
}
public function resume( $id = null ) {
$this->confirmAuth();
self::$title = 'resume Membership';
Views::view( 'members.resume' );
}
public function cancel( $id = null ) {
$this->confirmAuth();
self::$title = 'Cancel Membership';
Components::set( 'cancelid', $id );
Views::view( 'members.cancel' );
}
public function manage( $id = null ) {
if ( ! App::$isLoggedIn ) {
Session::flash( 'error', 'You do not have permission to access this page.' );
return Redirect::home();
}
self::$title = 'Manage Membership';
$menu = Views::simpleView( 'nav.usercp', App::$userCPlinks );
Navigation::activePageSelect( $menu, null, true, true );
$memberships = new Memberships;
$userMemberships = $memberships->getUserSubs();
Views::view( 'members.manage', $userMemberships );
}
public function upgrade( $id = null ) {
if ( ! App::$isLoggedIn ) {
Session::flash( 'error', 'You do not have permission to access this page.' );
return Redirect::home();
}
self::$title = 'Upgrade Membership';
Views::view( 'members.upgrade' );
}
public function join( $id = null ) {
public function join( $plan = 'monthly' ) {
if ( ! App::$isLoggedIn ) {
Session::flash( 'error', 'You do not have permission to access this page.' );
return Redirect::home();
}
$plan = strtolower( $plan );
if ( ! in_array( $plan, ['monthly','yearly'] ) ) {
Session::flash( 'error', 'Unknown plan' );
return Redirect::to( 'home/index' );
}
self::$title = 'Join {SIITENAME}!';
$product = self::$products->findById( $id );
$stripePrice = $this->findPrice( $plan );
$product = self::$products->findByPriceID( $stripePrice );
if ( empty( $product ) ) {
Session::flash( 'success', 'We aren\'t currently accepting new members, please check back soon!' );
return Redirect::home();
@ -157,92 +176,50 @@ class Member extends Controller {
Views::view( 'members.landing1', $product );
}
public function getyearly( $id = null ) {
if ( empty( $id ) ) {
Issues::add( 'error', 'no id' );
return $this->index();
}
$product = self::$products->findById( $id );
if ( empty( $product ) ) {
Issues::add( 'error', 'no product' );
return $this->index();
public function checkout( $plan = 'monthly' ) {
if ( ! App::$isLoggedIn ) {
Session::flash( 'error', 'You do not have permission to access this page.' );
return Redirect::home();
}
$customer = self::$customers->findOrCreate( App::$activeUser->ID );
if ( empty( $customer ) ) {
Issues::add( 'error', 'no customer' );
return $this->index();
}
$stripePrice = $this->findPrice( $plan );
self::$title = 'Purchase';
$price = $product->stripe_price_yearly;
$api_key = Config::getValue( 'memberships/stripeSecret' );
$stripe = new \Stripe\StripeClient( $api_key );
$session = $stripe->checkout->sessions->create([
$session = self::$stripe->checkout->sessions->create([
'payment_method_types' => ['card'],
'customer' => $customer,
'line_items' => [[
'price' => $price,
'price' => $stripePrice,
'quantity' => 1,
]],
'mode' => 'subscription',
'success_url' => Routes::getAddress() . 'member/paymentcomplete?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => Routes::getAddress() . 'member/paymentcanceled',
'success_url' => Routes::getAddress() . 'member/payment/complete?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => Routes::getAddress() . 'member/payment/cancel',
]);
header('Location: ' . $session->url);
exit;
}
public function getmonthly( $id = null ) {
if ( empty( $id ) ) {
Issues::add( 'error', 'no id' );
return $this->index();
}
$product = self::$products->findById( $id );
if ( empty( $product ) ) {
Issues::add( 'error', 'no product' );
return $this->index();
}
$customer = self::$customers->findOrCreate( App::$activeUser->ID );
if ( empty( $customer ) ) {
Issues::add( 'error', 'no customer' );
return $this->index();
public function payment( $type = '' ) {
$type = strtolower( $type );
if ( ! in_array( $type, ['cancel','complete'] ) ) {
Session::flash( 'error', 'Unknown Payment' );
return Redirect::to( 'home/index' );
}
self::$title = 'Purchase';
$price = $product->stripe_price_monthly;
$api_key = Config::getValue( 'memberships/stripeSecret' );
$stripe = new \Stripe\StripeClient( $api_key );
$session = $stripe->checkout->sessions->create([
'payment_method_types' => ['card'],
'customer' => $customer,
'line_items' => [[
'price' => $price,
'quantity' => 1,
]],
'mode' => 'subscription',
'success_url' => Routes::getAddress() . 'member/paymentcomplete?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => Routes::getAddress() . 'member/paymentcanceled',
]);
header('Location: ' . $session->url);
exit;
}
public function paymentcanceled() {
self::$title = '(almost) Members Area';
Views::view( 'members.paymentcanceled' );
}
if ( $type == 'cancel' ) {
self::$title = '(almost) Members Area';
return Views::view( 'members.paymentcanceled' );
}
public function paymentcomplete() {
self::$title = '(almost) Members Area';
Views::view( 'members.paymentcomplete' );
}
// This combines a registration with a checkout
public function signup( $plan = 'monthly' ) {
$plan = strtolower( $plan );
if ( ! in_array( $plan, ['monthly','yearly'] ) ) {
@ -255,11 +232,10 @@ class Member extends Controller {
Session::flash( 'error', 'Unknown product' );
return Redirect::to( 'home/index' );
}
$stripePrice = $this->findPrice( $plan );
$index = 'stripe_price_' . $plan;
$pretty = 'prettyPrice' . ucfirst( $plan );
$stripePrice = $product->$index;
$prettyPrice = $product->$pretty;
self::$title = 'Sign up for {SITENAME} ' . ucfirst( $plan );
@ -267,17 +243,21 @@ class Member extends Controller {
Components::set( 'planName', ucfirst( $plan ) );
Components::set( 'prettyPrice', $prettyPrice );
Components::set( 'TERMS', Views::simpleView( 'terms' ) );
if ( App::$isLoggedIn ) {
Session::flash( 'notice', 'You are already logged in, were you looking for information on <a href="#">Upgrading</a>?' );
Session::flash( 'notice', 'You are already logged in, you can <a href="/member/join">subscribe here</a>, or <a href="/member/upgrade">upgrade here</a>.' );
return Redirect::to( 'home/index' );
}
if ( !Input::exists() ) {
return Views::view( 'members.register' );
}
if ( ! Forms::check( 'register' ) ) {
Issues::add( 'error', [ 'There was an error with your registration.' => Check::userErrors() ] );
return Views::view( 'members.register' );
}
self::$user->create( [
'username' => Input::post( 'username' ),
'password' => Hash::make( Input::post( 'password' ) ),
@ -297,10 +277,7 @@ class Member extends Controller {
Session::flash( 'error', 'Thank you for registering! Unfortunately, there was an issue communicating with Stripe and we can\'t collect payment right now.' );
return Redirect::to( 'home/index' );
}
$api_key = Config::getValue( 'memberships/stripeSecret' );
$stripe = new \Stripe\StripeClient( $api_key );
$session = $stripe->checkout->sessions->create([
$session = self::$stripe->checkout->sessions->create([
'payment_method_types' => ['card'],
'customer' => $customer,
'line_items' => [[
@ -308,10 +285,34 @@ class Member extends Controller {
'quantity' => 1,
]],
'mode' => 'subscription',
'success_url' => Routes::getAddress() . 'member/paymentcomplete?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => Routes::getAddress() . 'member/paymentcanceled',
'success_url' => Routes::getAddress() . 'member/payment/complete?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => Routes::getAddress() . 'member/payment/cancel',
]);
header('Location: ' . $session->url);
exit;
}
private function findPrice( $plan ) {
$plan = strtolower( $plan );
if ( ! in_array( $plan, ['monthly','yearly'] ) ) {
Session::flash( 'error', 'Unknown plan' );
return Redirect::to( 'home/index' );
}
$product = self::$products->mainProduct();
if ( empty( $product ) ) {
Session::flash( 'error', 'Unknown product' );
return Redirect::to( 'home/index' );
}
$index = 'stripe_price_' . $plan;
$stripePrice = $product->$index;
return $stripePrice;
}
private function confirmAuth() {
if ( ! App::$isLoggedIn || ! App::$isMember ) {
Session::flash( 'error', 'You do not have permission to access this page.' );
return Redirect::home();
}
}
}

View File

@ -49,8 +49,6 @@ class Memberships extends DatabaseModel {
}
self::$loaded = true;
}
}
public function filter( $postArray, $params = [] ) {

View File

@ -18,6 +18,7 @@ use Stripe\StripeClient;
use TheTempusProject\Bedrock\Classes\Config;
use TheTempusProject\Hermes\Functions\Route as Routes;
use TheTempusProject\Models\Memberships;
use TheTempusProject\Models\MembershipProducts as Products;
class Members extends Plugin {
public static $stripe;
@ -42,7 +43,7 @@ class Members extends Plugin {
];
public $admin_links = [
[
'text' => '<i class="fa fa-fw fa-arrows-v"></i> Memberships',
'text' => '<i class="fa fa-fw fa-arrow-down"></i> Memberships',
'url' => [
[
'text' => '<i class="fa fa-fw fa-database"></i> Products',
@ -60,15 +61,20 @@ class Members extends Plugin {
],
];
public $main_links = [
// [
// 'text' => 'Members',
// 'url' => '{ROOT_URL}member/index',
// 'filter' => 'member',
// ],
[
'text' => 'Members',
'url' => '{ROOT_URL}member/index',
'filter' => 'member',
'text' => 'Subscribe',
'url' => '{ROOT_URL}member/join',
'filter' => 'nonmember',
],
[
'text' => 'Become a Member',
'url' => '{ROOT_URL}member/join/1',
'filter' => 'nonmember',
'text' => 'Upgrade',
'url' => '{ROOT_URL}member/upgrade',
'filter' => 'upgrade',
],
];
public $resourceMatrix = [
@ -129,7 +135,13 @@ class Members extends Plugin {
$this->filters[] = [
'name' => 'nonmember',
'find' => '#{NONMEMBER}(.*?){/NONMEMBER}#is',
'replace' => ( App::$isLoggedIn && ! App::$isMember ? '$1' : '' ),
'replace' => ( App::$isLoggedIn && App::$isMember == false ? '$1' : '' ),
'enabled' => true,
];
$this->filters[] = [
'name' => 'upgrade',
'find' => '#{UPGRADE}(.*?){/UPGRADE}#is',
'replace' => ( App::$isLoggedIn && ( App::$isMember === 'monthly' ) ? '$1' : '' ),
'enabled' => true,
];
$api_key = Config::getValue( 'memberships/stripeSecret' );
@ -147,14 +159,20 @@ class Members extends Plugin {
}
return false;
}
public function userHasActiveMembership( $user_id ) {
self::$memberships = new Memberships;
$membership = self::$memberships->findActiveByUserID( $user_id );
$memberships = new Memberships;
$membership = $memberships->findActiveByUserID( $user_id );
if ( empty( $membership ) ) {
return false;
}
return true;
$products = new Products;
$product = $products->findByPriceID( $membership->subscription_price_id );
if ( $product->stripe_price_monthly == $membership->subscription_price_id ) {
return 'monthly';
}
return 'yearly';
}
public static function webhookSetup() {

View File

@ -1,62 +1,128 @@
<section id="features" class="container">
<div class="row">
<div class="col-md-4">
<h3>Organize Your Bookmarks</h3>
<p>Keep all your bookmarks organized with custom categories and tags.</p>
</div>
<div class="col-md-4">
<h3>Import and Export</h3>
<p>Seamlessly import and export your bookmarks (paid plans).</p>
</div>
<div class="col-md-4">
<h3>Accessible Anywhere</h3>
<p>Your bookmarks are securely stored and accessible from any device.</p>
</div>
</div>
</section>
<section id="pricing" class="text-center bg-light-gray" style="padding-top: 30px;">
<div class="container">
<h2>Pricing</h2>
<div class="row">
<div class="col-sm-4">
<div class="card">
<div class="card-header">
<h3>Free</h3>
</div>
<div class="card-body">
<p>Basic bookmark storage</p>
<p>No import/export</p>
<p>Completely free</p>
<a href="{ROOT_URL}member/getmonthly/{ID}" class="btn btn-success">Sign Up</a>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="card">
<div class="card-header bg-primary">
<h3>{name} Monthly</h3>
</div>
<div class="card-body">
<p>Import/export bookmarks</p>
<p>Advanced curation tools</p>
<p>{prettyPriceMonthly}/month</p>
<a href="{ROOT_URL}member/getmonthly/{ID}" class="btn btn-primary">Sign Up</a>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="card">
<div class="card-header bg-primary">
<h3>{name} Yearly</h3>
</div>
<div class="card-body">
<p>Save with annual billing</p>
<p>All features included</p>
<p>{prettyPriceYearly}/year</p>
<a href="{ROOT_URL}member/getyearly/{ID}" class="btn btn-primary">Sign Up</a>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Compare plans -->
<div class="table-responsive pricing-container container pb-4" id="compare">
<h1 class="display-6 text-center my-4">Compare plans</h1>
<table class="table text-center context-main">
<thead>
<tr>
<th style="width: 34%;"></th>
<th style="width: 22%;">Free</th>
<th style="width: 22%;">Pro</th>
<th style="width: 22%;">Enterprise</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row" class="text-start">Add and Manage Bookmarks</th>
<td><i class="fa fa-fw fa-check"></i></td>
<td><i class="fa fa-fw fa-check"></i></td>
<td><i class="fa fa-fw fa-check"></i></td>
</tr>
<tr>
<th scope="row" class="text-start">Extensions for all major browsers</th>
<td><i class="fa fa-fw fa-check"></i></td>
<td><i class="fa fa-fw fa-check"></i></td>
<td><i class="fa fa-fw fa-check"></i></td>
</tr>
</tbody>
<tbody>
<tr>
<th scope="row" class="text-start">Access from any device</th>
<td><i class="fa fa-fw fa-check"></i></td>
<td><i class="fa fa-fw fa-check"></i></td>
<td><i class="fa fa-fw fa-check"></i></td>
</tr>
<tr>
<th scope="row" class="text-start">Import/Export Features</th>
<td></td>
<td><i class="fa fa-fw fa-check"></i></td>
<td><i class="fa fa-fw fa-check"></i></td>
</tr>
<tr>
<th scope="row" class="text-start">Customizable Dashboards / Pages</th>
<td></td>
<td><i class="fa fa-fw fa-check"></i></td>
<td><i class="fa fa-fw fa-check"></i></td>
</tr>
<tr>
<th scope="row" class="text-start">Request/Influence Development</th>
<td></td>
<td><i class="fa fa-fw fa-check"></i></td>
<td><i class="fa fa-fw fa-check"></i></td>
</tr>
<tr>
<th scope="row" class="text-start">Early Access</th>
<td></td>
<td><i class="fa fa-fw fa-check"></i></td>
<td><i class="fa-solid fa-check"></i></td>
</tr>
<tr>
<th scope="row" class="text-start">Cheaper</th>
<td></td>
<td></td>
<td><i class="fa-solid fa-check"></i></td>
</tr>
</tbody>
</table>
</div>
<div class="b-example-divider"></div>
<!-- Plan Choices -->
<div class="d-flex justify-content-center" id="pricing">
<div class="pricing-container container row row-cols-1 row-cols-md-3 my-5 text-center">
<div class="col">
<div class="card mb-4 rounded-3 shadow-sm h-100 context-main-bg">
<div class="card-header py-3">
<h4 class="my-0 fw-normal">Free</h4>
</div>
<div class="card-body d-flex flex-column">
<h1 class="card-title pricing-card-title">&#36;0<small class="text-muted fw-light">/mo</small></h1>
<ul class="list-unstyled mt-3 mb-4">
<li>Add / Manage your bookmarks</li>
<li>Extensions for all major browsers</li>
<li>Access from any device</li>
</ul>
<a href="/register" class="mt-auto w-100 btn btn-lg btn-outline-primary">
Sign-Up for Free
</a>
</div>
</div>
</div>
<div class="col">
<div class="card mb-4 rounded-3 shadow-sm h-100 context-main-bg">
<div class="card-header py-3">
<h4 class="my-0 fw-normal">Monthly</h4>
</div>
<div class="card-body d-flex flex-column">
<h1 class="card-title pricing-card-title">&#36;4.99<small class="text-muted fw-light">/month</small></h1>
<ul class="list-unstyled mt-3 mb-4">
<li>Import/Export Features</li>
<li>Integration with TempusTools App (WIP)</li>
<li>Customizable Dashboards / Pages</li>
<li>Direct control of Feature Development</li>
<li>Early Access to new features</li>
</ul>
<a href="/member/checkout/monthly" class="mt-auto w-100 btn btn-lg btn-primary">
Get started
</a>
</div>
</div>
</div>
<div class="col">
<div class="card mb-4 rounded-3 shadow-sm border-primary h-100 context-main-bg">
<div class="card-header py-3 text-bg-primary border-primary">
<h4 class="my-0 fw-normal">Yearly</h4>
</div>
<div class="card-body d-flex flex-column">
<h1 class="card-title pricing-card-title">&#36;19.99<small class="text-muted fw-light">/year</small></h1>
<ul class="list-unstyled mt-3 mb-4">
<li>Its cheaper if you like the product</li>
</ul>
<a href="/member/checkout/yearly" class="mt-auto w-100 btn btn-lg btn-primary">
Get started
</a>
</div>
</div>
</div>
</div>
</div>

View File

@ -20,7 +20,7 @@
<div class="card-body">
<p>{prettyPriceMonthly}/month</p>
<p>All pro features unlocked</p>
<a href="{ROOT_URL}member/getmonthly/{ID}" class="btn btn-success btn-block">Get Started</a>
<a href="{ROOT_URL}member/checkout/monthly" class="btn btn-success btn-block">Get Started</a>
</div>
</div>
</div>
@ -30,7 +30,7 @@
<div class="card-body">
<p>{prettyPriceYearly}/year</p>
<p>Save {prettySavings} annually!</p>
<a href="{ROOT_URL}member/getyearly/{ID}" class="btn btn-info btn-block">Sign Up</a>
<a href="{ROOT_URL}member/checkout/yearly" class="btn btn-info btn-block">Sign Up</a>
</div>
</div>
</div>

View File

@ -1,27 +1,24 @@
<div class="container">
<div class="col-8 mx-auto p-4 rounded shadow-sm mb-5 context-main-bg mt-4 text-center">
<div class="row">
<div class="col-md-8 col-md-offset-2 text-center">
<h2>Upgrade to a Yearly Plan</h2>
<h2 class="text-primary mb-4">Upgrade to a Yearly Plan</h2>
<p class="lead">
Save more and enjoy uninterrupted access to all features with our yearly plan!
Save more and enjoy uninterrupted access to all features with our yearly plan!
</p>
<p>
Upgrading now means you'll save <strong>X%</strong> compared to the monthly plan.
Stay committed and make the most of our service.
Upgrading now means you'll save <strong> nearly &#36;40 a year</strong> compared to the monthly plan.
Stay committed and make the most of our service.
</p>
<div class="row">
<div class="col-md-6">
<button class="btn btn-lg btn-success btn-block">
Upgrade to Yearly
</button>
</div>
<div class="col-md-6">
<button class="btn btn-lg btn-primary btn-block">
Stay on Monthly
</button>
</div>
<div class="col-md-6">
<a href="/member/checkout/yearly" class="btn btn-lg btn-success btn-block">
Upgrade to Yearly
</a>
</div>
<div class="col-md-6">
<a href="/member/upgrade" class="btn btn-lg btn-primary btn-block">
Stay on Monthly
</a>
</div>
</div>
</div>
</div>
</div>
</div>