85 lines
2.9 KiB
PHP
85 lines
2.9 KiB
PHP
<?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' );
|
|
}
|
|
}
|