Add donate and memberships

This commit is contained in:
Joey Kimsey
2024-12-05 15:33:25 -05:00
parent 03aedc3020
commit 402182714e
39 changed files with 2109 additions and 21 deletions

View File

@ -0,0 +1,84 @@
<?php
/**
* app/plugins/donate/controllers/donate.php
*
* This is the Donations controller.
*
* @package TP Donate
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Controllers;
use TheTempusProject\Hermes\Functions\Redirect;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Bedrock\Functions\Session;
use TheTempusProject\Houdini\Classes\Issues;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Classes\Controller;
use TheTempusProject\Classes\Forms;
use TheTempusProject\Models\Bugreport as BugreportModel;
use TheTempusProject\TheTempusProject as App;
use TheTempusProject\Bedrock\Classes\Config;
use TheTempusProject\Hermes\Functions\Route as Routes;
class Donate extends Controller {
protected static $bugreport;
public function index() {
self::$title = 'Donate - {SITENAME}';
self::$pageDescription = 'Donations help support our cause and our efforts. Please use this page to select an amount and give today.';
if ( !Input::exists() ) {
return Views::view( 'donate.donate' );
}
if ( !Forms::check( 'donate' ) ) {
Issues::add( 'error', [ 'There was an error with your form.' => Check::userErrors() ] );
return Views::view( 'donate.donate' );
}
try {
$api_key = Config::getValue( 'donations/stripeSecret' );
$stripe = new \Stripe\StripeClient( $api_key );
$session = $stripe->checkout->sessions->create([
'payment_method_types' => ['card'],
'line_items' => [[
'price_data' => [
'currency' => 'usd',
'product_data' => [
'name' => 'Donation',
],
'unit_amount' => Input::post("amount"), // Amount in cents ($10)
],
'quantity' => 1,
]],
'mode' => 'payment',
'metadata' => [
'note' => Input::post("comment"),
],
'success_url' => Routes::getAddress() . 'donate/success?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => Routes::getAddress() . 'donate/continue',
]);
// Redirect to the Checkout session
header('Location: ' . $session->url);
exit;
} catch (\Stripe\Exception\ApiErrorException $e) {
echo "Error creating Checkout session: " . $e->getMessage();
}
}
public function success() {
self::$title = 'Thank you!';
Views::view( 'donate.success' );
}
public function continue() {
self::$title = 'Thank you!';
Views::view( 'donate.fail' );
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* app/plugins/donate/forms.php
*
* This houses all of the form checking functions for this plugin.
*
* @package TP Donate
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Plugins\Donate;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Classes\Forms;
class DonateForms extends Forms {
/**
* Adds these functions to the form list.
*/
public function __construct() {
self::addHandler( 'donate', __CLASS__, 'donate' );
}
/**
* Validates the bug report form.
*
* @return {bool}
*/
public static function donate() {
if ( !Input::exists( 'amount' ) ) {
self::addUserError( 'You must specify an amount' );
return false;
}
if ( !self::token() ) {
return false;
}
return true;
}
}
new DonateForms;

View File

@ -0,0 +1,35 @@
<?php
/**
* app/plugins/donate/models/donations.php
*
* This class is used for the manipulation of the donations database table.
*
* @package TP Donate
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Models;
use TheTempusProject\Classes\DatabaseModel;
use TheTempusProject\Plugins\Bugreport as Plugin;
class Donations extends DatabaseModel {
public $tableName = 'donations';
public $databaseMatrix = [
[ 'amount', 'int', '11' ],
[ 'createdAt', 'int', '10' ],
[ 'user_d', 'int', '10' ],
[ 'comment', 'text', '' ],
];
public $plugin;
/**
* The model constructor.
*/
public function __construct() {
parent::__construct();
$this->plugin = new Plugin;
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* app/plugins/donate/plugin.php
*
* This houses all of the main plugin info and functionality.
*
* @package TP Donate
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
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 Donate extends Plugin {
public static $stripe;
private static $loaded = false;
public $pluginName = 'TP Donations';
public $configName = 'donations';
public $pluginAuthor = 'JoeyK';
public $pluginWebsite = 'https://TheTempusProject.com';
public $modelVersion = '1.0';
public $pluginVersion = '3.0';
public $pluginDescription = 'A simple plugin which adds a site wide donation system.';
public $permissionMatrix = [
'controlMemberships' => [
'pretty' => 'Can donate.',
'default' => true,
],
];
public $main_links = [
[
'text' => 'Donate!',
'url' => '{ROOT_URL}donate',
],
];
public $configMatrix = [
'stripePublishable' => [
'type' => 'text',
'pretty' => 'Stripe Publishable key',
'default' => 'pk_xxxxxxxxxxxxxxx',
],
'stripeSecret' => [
'type' => 'text',
'pretty' => 'Stripe Secret key',
'default' => 'sk_xxxxxxxxxxxxxxx',
],
];
public function __construct( $load = false ) {
parent::__construct( $load );
}
}

View File

@ -0,0 +1,37 @@
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="jumbotron text-center">
<h1>Support Our Projects</h1>
<p>Your funding helps provide more time and resources, enables exciting new projects, and ensures continued updates and improvements to all of our services.</p>
<p>By contributing, you're supporting these platforms:</p>
<ul class="list-unstyled">
<li><strong>AllTheBookmarks.com</strong> - Your one-stop bookmark management service.</li>
<li><strong>ForgottenPlanner.com</strong> - Keep your plans on track.</li>
<li><strong>TempusToolkit.com</strong> - Time management made easier.</li>
<li><strong>WoWditions.com</strong> - Enhancing your World of Warcraft experience.</li>
<li><strong>WhatsThatUploadSite.com</strong> - Simplified upload site discovery.</li>
<li><strong>PollingDownTheStreet.com</strong> - Find your local polling station effortlessly.</li>
</ul>
<p>Every donation helps us grow and continue providing value to our community. Thank you for your support!</p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<form action="" method="POST" role="form">
<div class="form-group">
<label for="donation-amount">Donation Amount ($):</label>
<input type="number" class="form-control" id="donation-amount" name="amount" placeholder="Enter amount">
</div>
<div class="form-group">
<label for="donation-comment">Leave a Comment (Optional):</label>
<textarea class="form-control" id="donation-comment" name="comment" rows="4" placeholder="Share your thoughts or specify how you'd like your donation to be used."></textarea>
</div>
<input type="hidden" name="token" value="{TOKEN}">
<button type="submit" value="submit" name="submit" class="btn btn-primary btn-lg btn-block">Donate Now</button>
</form>
</div>
</div>
</div>

View File

@ -0,0 +1,4 @@
<div class="jumbotron text-center">
<h1>Thanks for taking the time to explore donation.</h1>
<p>Now may not be the right time, but we thank you anyways!</p>
</div>

View File

@ -0,0 +1,5 @@
<div class="jumbotron text-center">
<h1>Thanks for supporting!</h1>
<p>Its people like you who keep the pixels on around here.
Every Dollar counts, so thank you again.</p>
</div>