Merge branch '1.11.x.buycourses-plugin-add-stripe-support' of git://github.com/NosoloredChamilo/chamilo-lms into NosoloredChamilo-1.11.x.buycourses-plugin-add-stripe-support
commit
cfc1d96523
@ -0,0 +1,30 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Success page for the purchase of a course in the Buy Courses plugin. |
||||
* |
||||
* @package chamilo.plugin.buycourses |
||||
*/ |
||||
require_once '../config.php'; |
||||
|
||||
$plugin = BuyCoursesPlugin::create(); |
||||
$stripeEnabled = $plugin->get('stripe_enable') === 'true'; |
||||
|
||||
if (!$stripeEnabled) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$sale = $plugin->getSale($_SESSION['bc_sale_id']); |
||||
|
||||
if (empty($sale)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
Display::addFlash( |
||||
Display::return_message($plugin->get_lang('ErrorContactPlatformAdmin'), 'error') |
||||
); |
||||
|
||||
unset($_SESSION['bc_sale_id']); |
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/course_catalog.php'); |
||||
exit; |
||||
@ -0,0 +1,64 @@ |
||||
<?php |
||||
|
||||
require_once '../config.php'; |
||||
|
||||
$plugin = BuyCoursesPlugin::create(); |
||||
$stripeEnabled = $plugin->get('stripe_enable') === 'true'; |
||||
|
||||
if (!$stripeEnabled) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$stripeParams = $plugin->getStripeParams(); |
||||
|
||||
$payload = @file_get_contents('php://input'); |
||||
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE']; |
||||
$event = null; |
||||
|
||||
try { |
||||
$event = \Stripe\Webhook::constructEvent( |
||||
$payload, $sig_header, $stripeParams['endpoint_secret'] |
||||
); |
||||
} catch(\UnexpectedValueException $e) { |
||||
http_response_code(400); |
||||
exit(); |
||||
} catch(\Stripe\Exception\SignatureVerificationException $e) { |
||||
http_response_code(400); |
||||
exit(); |
||||
} |
||||
|
||||
switch ($event->type) { |
||||
case 'payment_intent.succeeded': |
||||
$paymentIntent = $event->data->object; |
||||
|
||||
$sale = $plugin->getSaleFromReference($paymentIntent->id); |
||||
|
||||
if (empty($sale) ) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$buyingCourse = false; |
||||
$buyingSession = false; |
||||
|
||||
switch ($sale['product_type']) { |
||||
case BuyCoursesPlugin::PRODUCT_TYPE_COURSE: |
||||
$buyingCourse = true; |
||||
$course = $plugin->getCourseInfo($sale['product_id']); |
||||
break; |
||||
case BuyCoursesPlugin::PRODUCT_TYPE_SESSION: |
||||
$buyingSession = true; |
||||
$session = $plugin->getSessionInfo($sale['product_id']); |
||||
break; |
||||
} |
||||
|
||||
$saleIsCompleted = $plugin->completeSale($sale['id']); |
||||
|
||||
if ($saleIsCompleted) { |
||||
$plugin->storePayouts($sale['id']); |
||||
} |
||||
|
||||
default: |
||||
echo 'Received unknown event type ' . $event->type; |
||||
} |
||||
|
||||
http_response_code(200); |
||||
@ -0,0 +1,30 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Success page for the purchase of a course in the Buy Courses plugin. |
||||
* |
||||
* @package chamilo.plugin.buycourses |
||||
*/ |
||||
require_once '../config.php'; |
||||
|
||||
$plugin = BuyCoursesPlugin::create(); |
||||
$stripeEnabled = $plugin->get('stripe_enable') === 'true'; |
||||
|
||||
if (!$stripeEnabled) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$sale = $plugin->getSale($_SESSION['bc_sale_id']); |
||||
|
||||
if (empty($sale)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
Display::addFlash( |
||||
$plugin->getSubscriptionSuccessMessage($sale) |
||||
); |
||||
|
||||
unset($_SESSION['bc_sale_id']); |
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/course_catalog.php'); |
||||
exit; |
||||
Loading…
Reference in new issue