little background...... we use stripe for payment.... is in our strip _charge. we have 3 member groups. two are paid groups. included the strip info as shows joining and leaving a group.
if ($error == false) {
// no errors and everything was created correctly.
// assign to new role, if applicable
if($joingroup == 'STD_Members') {
$user->leaveGroup('STD_Trial');
$user->joinGroup('STD_Members');
$user->save();
}
elseif($joingroup == 'STD_Members_ID') {
$user->leaveGroup('STD_Trial');
$user->leaveGroup('STD_Members');
$user->joinGroup('STD_Members_ID');
$user->save();
}
// Give the correct chunk
if($chunktype == 'show_success') {
return $modx->getChunk('Subscription_Change_Success',array('Success_Message' => $Success_Message));
} else {
$modx->runSnippet('Session_Refresh');
return $modx->getChunk('Subscription_Upgrade_Complete',array('Subscription_Type' => $Subscription_Type));
}
}
else {
if($errors['type'] == 'buy') {
$url = $modx->makeUrl(95,'',$errors);
$modx->sendRedirect($url);
} else {
return 'An error has happened: <br>' . $errors['Stripe_Error'];
}
}
This gets called by the stripe charge snippit exact lines here from above....
$modx->runSnippet('Session_Refresh');
return $modx->getChunk('Subscription_Upgrade_Complete',array('Subscription_Type' => $Subscription_Type));
Snippit Session_Refresh
<?php
$key = "modx.user.{$modx->user->id}";
$keyLength = strlen($key);
foreach ($_SESSION as $sKey => $sVal) {
if (substr($sKey, 0, $keyLength) === $key) unset($_SESSION[$sKey]);
}
the following call then shows that membership has been completed, and then redirects to the main profile page for the user.
chunk
Subscription_Upgrade_Complete
<h1>Success</h1>
<div class="twelve columns">
<p>You have successfully upgraded your membership to [[+Subscription_Type]]. </p>
<p>Please wait while the change to your account is applied.</p>
<p id="countdown">Redirecting in 3 seconds</p>
</div>
<script type="text/javascript">
var count=3;
var counter=setInterval(timer, 1000);
function timer()
{
count=count-1;
if (count <= 0)
{
clearInterval(counter);
window.location="[[~24]]";
return;
}
document.getElementById("countdown").innerHTML="Redirecting in " + count + " seconds";
}
</script>