-
Notifications
You must be signed in to change notification settings - Fork 982
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ads fix and let users change stripe credit card for subscriptions
- Loading branch information
Daniel Neto
committed
Feb 3, 2025
1 parent
d5075f4
commit bec77e3
Showing
9 changed files
with
508 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
require_once '../../videos/configuration.php'; | ||
|
||
header('Content-Type: application/json'); | ||
$obj = new stdClass(); | ||
$obj->error = true; | ||
$obj->msg = ""; | ||
|
||
if (empty($_POST['paymentMethodId'])) { | ||
forbiddenPage('Invalid paymentMethodId'); | ||
} | ||
|
||
if (empty($_REQUEST['subscription_id'])) { | ||
forbiddenPage('subscription_id not found'); | ||
} | ||
|
||
if (!User::isLogged()) { | ||
forbiddenPage('Invalid user'); | ||
} | ||
|
||
$users_id = User::getId(); | ||
|
||
$plugin = AVideoPlugin::loadPluginIfEnabled("StripeYPT"); | ||
|
||
if (empty($plugin)) { | ||
forbiddenPage('Invalid StripeYPT'); | ||
} | ||
|
||
$s = new SubscriptionTable($_REQUEST['subscription_id']); | ||
|
||
if($s->getUsers_id() != User::getId()){ | ||
forbiddenPage('This plan does not belong to you'); | ||
} | ||
|
||
$customer_id = $s->getStripe_costumer_id(); | ||
|
||
if (empty($customer_id)) { | ||
forbiddenPage('Invalid customer_id'); | ||
} | ||
|
||
$stripe = AVideoPlugin::loadPlugin("StripeYPT"); | ||
|
||
$paymentMethod = $stripe->addCard($customer_id, $_POST['paymentMethodId']); | ||
|
||
if(!empty($paymentMethod )){ | ||
$subscription = $stripe->userHasActiveSubscriptionOnPlan($s->getSubscriptions_plans_id()); | ||
if(!empty($subscription)){ | ||
|
||
} | ||
} | ||
|
||
$obj->error = !$stripe->addCard($customer_id, $_POST['paymentMethodId']); | ||
$obj->msg = $addCardErrorMessage; | ||
|
||
echo json_encode($obj); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,41 @@ | ||
<?php | ||
|
||
// check recurrent payments | ||
header('Content-Type: application/json'); | ||
|
||
if (empty($global['systemRootPath'])) { | ||
$global['systemRootPath'] = '../../'; | ||
} | ||
require_once $global['systemRootPath'] . 'videos/configuration.php'; | ||
|
||
_error_log("StripeINTENT Start"); | ||
$plugin = AVideoPlugin::loadPluginIfEnabled("YPTWallet"); | ||
$walletObject = AVideoPlugin::getObjectData("YPTWallet"); | ||
$stripe = AVideoPlugin::loadPluginIfEnabled("StripeYPT"); | ||
$stripeObject = AVideoPlugin::getObjectData("StripeYPT"); | ||
|
||
$obj = new stdClass(); | ||
$obj->error = true; | ||
$obj->msg = ""; | ||
|
||
if (!User::isAdmin()) { | ||
$obj->msg = "Admin only"; | ||
die(json_encode($obj)); | ||
} | ||
|
||
if (empty($stripe)) { | ||
$obj->msg = "Stripe Plugin Disabled"; | ||
die(json_encode($obj)); | ||
} | ||
if (empty($plugin)) { | ||
$obj->msg = "Wallet Plugin Disabled"; | ||
die(json_encode($obj)); | ||
} | ||
|
||
|
||
StripeYPT::_start(); | ||
$obj->webhook = StripeYPT::getWebhook(); | ||
$obj->error = empty($obj->webhook); | ||
|
||
die(json_encode($obj)); | ||
?> | ||
<?php | ||
|
||
// check recurrent payments | ||
header('Content-Type: application/json'); | ||
|
||
if (empty($global['systemRootPath'])) { | ||
$global['systemRootPath'] = '../../'; | ||
} | ||
require_once $global['systemRootPath'] . 'videos/configuration.php'; | ||
|
||
_error_log("StripeINTENT Webhook Start"); | ||
$plugin = AVideoPlugin::loadPluginIfEnabled("YPTWallet"); | ||
$walletObject = AVideoPlugin::getObjectData("YPTWallet"); | ||
$stripe = AVideoPlugin::loadPluginIfEnabled("StripeYPT"); | ||
$stripeObject = AVideoPlugin::getObjectData("StripeYPT"); | ||
|
||
$obj = new stdClass(); | ||
$obj->error = true; | ||
$obj->msg = ""; | ||
|
||
if (!User::isAdmin()) { | ||
$obj->msg = "Admin only"; | ||
die(json_encode($obj)); | ||
} | ||
|
||
if (empty($stripe)) { | ||
$obj->msg = "Stripe Plugin Disabled"; | ||
die(json_encode($obj)); | ||
} | ||
if (empty($plugin)) { | ||
$obj->msg = "Wallet Plugin Disabled"; | ||
die(json_encode($obj)); | ||
} | ||
|
||
|
||
StripeYPT::_start(); | ||
$obj->webhook = StripeYPT::getWebhook(); | ||
$obj->error = empty($obj->webhook); | ||
|
||
die(json_encode($obj)); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
require_once '../../videos/configuration.php'; | ||
|
||
header('Content-Type: application/json'); | ||
$obj = new stdClass(); | ||
$obj->error = true; | ||
$obj->msg = ""; | ||
|
||
if (empty($_POST['paymentMethodId'])) { | ||
forbiddenPage('Invalid paymentMethodId'); | ||
} | ||
|
||
if (empty($_REQUEST['subscription_id'])) { | ||
forbiddenPage('subscription_id not found'); | ||
} | ||
|
||
if (!User::isLogged()) { | ||
forbiddenPage('Invalid user'); | ||
} | ||
|
||
$users_id = User::getId(); | ||
|
||
$plugin = AVideoPlugin::loadPluginIfEnabled("StripeYPT"); | ||
|
||
if (empty($plugin)) { | ||
forbiddenPage('Invalid StripeYPT'); | ||
} | ||
|
||
$s = new SubscriptionTable($_REQUEST['subscription_id']); | ||
|
||
if($s->getUsers_id() != User::getId()){ | ||
forbiddenPage('This plan does not belong to you'); | ||
} | ||
|
||
$customer_id = $s->getStripe_costumer_id(); | ||
|
||
if (empty($customer_id)) { | ||
forbiddenPage('Invalid customer_id'); | ||
} | ||
|
||
$stripe = AVideoPlugin::loadPlugin("StripeYPT"); | ||
|
||
$obj->error = !$stripe->deleteCard($customer_id, $_POST['paymentMethodId']); | ||
$obj->msg = $addCardErrorMessage; | ||
|
||
echo json_encode($obj); | ||
?> |
Oops, something went wrong.