Skip to content

Commit

Permalink
fix(account): cancel a subscription
Browse files Browse the repository at this point in the history
A user needs to be able to cancel their subscription. This includes some
style changes to reflect what we currently have on app.webpagetest plus
moving an ill-placed redirect (that was happening _before_ the call for
some reason).
  • Loading branch information
jefflembeck committed May 10, 2022
1 parent 77e396e commit 286192c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions www/cpauth/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
$billing_info['plan_renewal'] = $plan_renewal_date->format('m/d/Y');
}

$billing_info['is_canceled'] = str_contains($customer_details['status'], 'CANCEL');
$billing_info['billing_frequency'] = $billing_frequency;
$client_token = $billing_info['braintreeClientToken'];
} else {
Expand Down
8 changes: 8 additions & 0 deletions www/css/account.css
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ body.theme-b {
content: ':';
}

.subscription-plan .cancel span {
padding: 0px 10px;
border-radius: 2px;
background-color: rgb(237, 47, 47);
color: rgb(255, 255, 255);
}

.billing-history {
display: block;
}
Expand Down Expand Up @@ -684,3 +691,4 @@ body.theme-b {
.account-layout body {
background-color: rgb(234, 234, 234);
}

13 changes: 7 additions & 6 deletions www/src/Handlers/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,16 @@ public static function cancelSubscription(RequestContext $request_context)
{

$subscription_id = filter_input(INPUT_POST, 'subscription-id', FILTER_SANITIZE_STRING);
$protocol = $request_context->getUrlProtocol();
$host = Util::getSetting('host');
$route = '/account';
$redirect_uri = "{$protocol}://{$host}{$route}";

header("Location: {$redirect_uri}");
exit();
try {
$request_context->getClient()->cancelWptSubscription($subscription_id);
$protocol = $request_context->getUrlProtocol();
$host = Util::getSetting('host');
$route = '/account';
$redirect_uri = "{$protocol}://{$host}{$route}";

header("Location: {$redirect_uri}");
exit();
} catch (BaseException $e) {
error_log($e->getMessage());
throw new ClientException("There was an error", "/account");
Expand Down
5 changes: 5 additions & 0 deletions www/templates/account/includes/billing-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
<?php echo isset($runs_renewal) ? "<li><strong>Runs Renewal</strong> {$runs_renewal}</li>" : "" ?>
<li><strong>Price</strong> <?= "\${$braintreeCustomerDetails['subscriptionPrice']}"; ?></li>
<li><strong>Payment</strong> <?= $billing_frequency ?></li>
<?php if ($is_canceled): ?>
<li><strong>Plan Renewal</strong> <s><?= $plan_renewal ?></s></li>
<li class="cancel"><strong>Status</strong> <span><?= $braintreeCustomerDetails['status']; ?></span></li>
<?php else: ?>
<li><strong>Plan Renewal</strong> <?= $plan_renewal ?></li>
<li><strong>Status</strong> <?= $braintreeCustomerDetails['status']; ?></li>
<?php endif; ?>
</ul>
</div>
</div>
Expand Down

0 comments on commit 286192c

Please sign in to comment.