Add donate and memberships
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/chat/plugin.php
|
||||
* app/plugins/members/plugin.php
|
||||
*
|
||||
* This houses all of the main plugin info and functionality.
|
||||
*
|
||||
* @package TP Chat
|
||||
* @package TP Members
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
@ -14,10 +14,17 @@ namespace TheTempusProject\Plugins;
|
||||
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Classes\Plugin;
|
||||
use Stripe\StripeClient;
|
||||
use TheTempusProject\Bedrock\Classes\Config;
|
||||
use TheTempusProject\Hermes\Functions\Route as Routes;
|
||||
use TheTempusProject\Models\Memberships;
|
||||
|
||||
class Members extends Plugin {
|
||||
public static $stripe;
|
||||
public static $memberships;
|
||||
private static $loaded = false;
|
||||
public $pluginName = 'TP Membership';
|
||||
public $configName = 'membership';
|
||||
public $configName = 'memberships';
|
||||
public $pluginAuthor = 'JoeyK';
|
||||
public $pluginWebsite = 'https://TheTempusProject.com';
|
||||
public $modelVersion = '1.0';
|
||||
@ -35,8 +42,21 @@ class Members extends Plugin {
|
||||
];
|
||||
public $admin_links = [
|
||||
[
|
||||
'text' => '<i class="fa fa-fw fa-lock"></i> Memberships',
|
||||
'url' => '{ROOT_URL}admin/member',
|
||||
'text' => '<i class="fa fa-fw fa-arrows-v"></i> Memberships',
|
||||
'url' => [
|
||||
[
|
||||
'text' => '<i class="fa fa-fw fa-database"></i> Products',
|
||||
'url' => '{ROOT_URL}admin/products',
|
||||
],
|
||||
[
|
||||
'text' => '<i class="fa fa-fw fa-database"></i> Subscriptions',
|
||||
'url' => '{ROOT_URL}admin/records',
|
||||
],
|
||||
[
|
||||
'text' => '<i class="fa fa-fw fa-database"></i> Invoices',
|
||||
'url' => '{ROOT_URL}admin/invoices',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
public $main_links = [
|
||||
@ -45,6 +65,11 @@ class Members extends Plugin {
|
||||
'url' => '{ROOT_URL}member/index',
|
||||
'filter' => 'member',
|
||||
],
|
||||
[
|
||||
'text' => 'Become a Member',
|
||||
'url' => '{ROOT_URL}member/join/1',
|
||||
'filter' => 'nonmember',
|
||||
],
|
||||
];
|
||||
public $resourceMatrix = [
|
||||
'groups' => [
|
||||
@ -54,11 +79,45 @@ class Members extends Plugin {
|
||||
]
|
||||
],
|
||||
];
|
||||
public $configMatrix = [
|
||||
'stripePublishable' => [
|
||||
'type' => 'text',
|
||||
'pretty' => 'Stripe Publishable key',
|
||||
'default' => 'pk_xxxxxxxxxxxxxxx',
|
||||
],
|
||||
'stripeSecret' => [
|
||||
'type' => 'text',
|
||||
'pretty' => 'Stripe Secret key',
|
||||
'default' => 'sk_xxxxxxxxxxxxxxx',
|
||||
],
|
||||
];
|
||||
|
||||
public static $webhookEvents = [
|
||||
'customer.subscription.created',
|
||||
'customer.subscription.updated',
|
||||
'customer.subscription.deleted',
|
||||
'customer.updated',
|
||||
'customer.deleted',
|
||||
'payment_method.automatically_updated',
|
||||
'invoice.payment_action_required',
|
||||
'invoice.payment_succeeded',
|
||||
'checkout.session.completed',
|
||||
];
|
||||
|
||||
public static $userLinks = [
|
||||
"url" => "{ROOT_URL}member/manage",
|
||||
"name" => "Subscriptions"
|
||||
];
|
||||
|
||||
public function __construct( $load = false ) {
|
||||
if ( ! self::$loaded ) {
|
||||
App::$userCPlinks[] = (object) self::$userLinks;
|
||||
self::$loaded = true;
|
||||
}
|
||||
if ( App::$isLoggedIn ) {
|
||||
App::$isMember = $this->hasMemberAccess( App::$activeGroup );
|
||||
App::$isMember = $this->groupHasMemberAccess( App::$activeGroup );
|
||||
if ( empty( App::$isMember ) ) {
|
||||
App::$isMember = $this->hasMemberAccess( App::$activeUser );
|
||||
App::$isMember = $this->userHasActiveMembership( App::$activeUser->ID );
|
||||
}
|
||||
}
|
||||
$this->filters[] = [
|
||||
@ -67,9 +126,54 @@ class Members extends Plugin {
|
||||
'replace' => ( App::$isMember ? '$1' : '' ),
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->filters[] = [
|
||||
'name' => 'nonmember',
|
||||
'find' => '#{NONMEMBER}(.*?){/NONMEMBER}#is',
|
||||
'replace' => ( App::$isLoggedIn && ! App::$isMember ? '$1' : '' ),
|
||||
'enabled' => true,
|
||||
];
|
||||
$api_key = Config::getValue( 'memberships/stripeSecret' );
|
||||
if ( $api_key == 'sk_xxxxxxxxxxxxxxx' || empty($api_key) ) {
|
||||
self::$stripe = false;
|
||||
} else {
|
||||
self::$stripe = new StripeClient( $api_key );
|
||||
}
|
||||
parent::__construct( $load );
|
||||
}
|
||||
public function hasMemberAccess( $input ) {
|
||||
|
||||
public function groupHasMemberAccess( $activeGroup ) {
|
||||
if ( $activeGroup->memberAccess == true ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function userHasActiveMembership( $user_id ) {
|
||||
self::$memberships = new Memberships;
|
||||
$membership = self::$memberships->findActiveByUserID( $user_id );
|
||||
if ( empty( $membership ) ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function webhookSetup() {
|
||||
$root = Routes::getAddress();
|
||||
// $root = "https://stripe.joeykimsey.com/";
|
||||
$response = self::$stripe->webhookEndpoints->create([
|
||||
'enabled_events' => self::$webhookEvents,
|
||||
'url' => $root . 'api/stripe/webhook',
|
||||
]);
|
||||
return $response;
|
||||
}
|
||||
|
||||
// public static function webhookSetup() {
|
||||
// $root = Routes::getAddress();
|
||||
// $root = "https://stripe.joeykimsey.com/";
|
||||
// $response = self::$stripe->webhookEndpoints->create([
|
||||
// 'enabled_events' => self::$webhookEvents,
|
||||
// 'url' => $root . 'api/stripe/webhook',
|
||||
// ]);
|
||||
// return $response;
|
||||
// }
|
||||
}
|
||||
|
Reference in New Issue
Block a user