Permalink
Browse files

Added confirmation messages after upgrade and downgrade.

Also, added "Being downgraded..." scenario.
  • Loading branch information...
mortengf committed Jul 22, 2015
1 parent fcff77e commit f73003558d251d360ad79500a5f3941e433a05ed
@@ -38,6 +38,7 @@ mongoose.connect(conf.db.uri, function(err) {
logger.info("Handling: " + user.id);
var oldEndDay = user.payment.endDate;
user.payment.endDate = null;
user.payment.cancelled = null;
user.level = 'free';
user.save(function (err, user) {
if (err) {
View
@@ -48,7 +48,8 @@ var UserSchema = new Schema({
date: { type: Date, default: Date.now },
type: { type: String, enum: ['recurring', 'single'] },
description: { type: String}
}]
}],
cancelled: { type: Boolean, default: false }
}
});
@@ -101,7 +101,8 @@ <h1>HSSDSDSDSD</h1> <a id="confirmationClose" ng-click="confirmationClose()">Clo
<!-- TODO: is there an easier way to conditionally apply the appropriate "upgrade-text" class? -->
<span data-ng-bind-html="upgradeText[user.level]" data-ng-class="{ 'upgrade-text-free': user.level == 'free', 'upgrade-text-premium': user.level == 'premium' }"></span>
<a id="upgradeButton" ng-click="upgrade()" ng-if="user.level == 'free'">Upgrade</a>
<a id="upgradeButton" ng-click="upgrade()" ng-if="user.level == 'premium'">Change</a>
<a id="upgradeButton" ng-click="upgrade()" ng-if="user.level != 'free' && !user.payment.cancelled">Change</a>
<div ng-if="user.level != 'free' && user.payment.cancelled" class="upgrade-text-being-downgraded">Being downgraded...</div>
</div>
</div>
</div>
@@ -443,6 +443,10 @@ hr {
.upgrade-text-premium {
color: #fff;
}
.upgrade-text .upgrade-text-being-downgraded {
text-decoration: none;
color: #fff;
}
#useFree:hover{
color:#c6c6c6;
@@ -30,17 +30,17 @@ app.controller('appController', [ '$http', '$scope', 'userService', '$rootScope'
if (err) {
alert("An error occurred connecting to the payment gateway: " + JSON.stringify(err));
} else {
paymentService.cancelSubscription($scope.user, function (err) {
paymentService.cancelSubscription($scope.user, function (err, data) {
if (data) {
$scope.user.payment.cancelled = data.user.payment.cancelled;
} else {
alert("An error occurred cancelling your subscription: " + JSON.stringify(err));
}
var confirmationPromise = modals.open("confirmation");
confirmationPromise.then(
function handleResolve(response) {
if (err) {
alert("An error occurred cancelling your subscription: " + JSON.stringify(err));
} else {
// TODO: get the date on which the user's premium subscription ends
// The user's level will not be changed until we receive cancellation confirmation from Braintree
alert("Your subscription has now been cancelled. You will remain Premium until the end of your current billing period ends.");
}
},
function handleReject(error) {
if (error) alert("An error occurred closing the confirmation window: " + JSON.stringify(error));
@@ -414,9 +414,9 @@ app.service('paymentService', function($http, $q) {
},
cancelSubscription: function(user, next) {
$http.delete('/payment/subscription', user)
.success( function() {
.success( function(data) {
if (next) {
return next();
return next(null, data);
}
})
.error(function(data) {
@@ -751,11 +751,18 @@ app.controller("PaymentModalController",
app.controller("UpgradeDowngradeConfirmationController", [ '$scope', 'modals',
function( $scope, modals ) {
// TODO: for downgrade, add info about when the user loses premium access.
$scope.upgradeDowngradeConfirmationMessage = $scope.user.level && $scope.user.level == 'free' ? "Your account has now been downgraded" : 'Your payment has been received and your subscription created. You will receive a confirmation email shortly.';
if ($scope.user.level == 'premium' && !$scope.user.payment.cancelled) {
$scope.upgradeDowngradeConfirmationMessage = 'Your payment has been received and your subscription created. You will receive a confirmation email shortly.';
} else if ($scope.user.level != 'free' && $scope.user.payment.cancelled) { // User's level does not change until the subscription has expired so level is not 'free' yet
// TODO: get the date on which the user's premium subscription expires
$scope.upgradeDowngradeConfirmationMessage = "Your subscription has now been cancelled. You will remain Premium until your subscription expires.";
} else {
console.log('ERROR in UpgradeDowngradeConfirmationController: user\'s level was not "premium" or "subscriptionHasBeenCancelled" was not set');
}
//$scope.upgradeDowngradeConfirmationMessage = $scope.user.level && $scope.user.level == 'free' ? "Your account has now been downgraded" : 'Your payment has been received and your subscription created. You will receive a confirmation email shortly.';
$scope.confirmationClose = modals.resolve;
$scope.confirmationClose = modals.reject;
}]
);
View
@@ -291,7 +291,14 @@ exports.cancel_subscription = function (req, res, next) {
gateway.subscription.cancel(user.payment.subscriptionId, function (err, result) {
if (result.success) {
// All good. We will notify the customer by email when we get the cancellation confirmation from Braintree through webhook.
res.send({});
user.payment.cancelled = true;
user.save(function (err) {
if (err) {
return next(err);
} else {
res.send({user: utils.cleanUserObject(user)});
}
})
} else {
return next( {message: result.message, status: 591} );
}

0 comments on commit f730035

Please sign in to comment.