<commit_before>app.controller('chooseController', ['$scope', '$http', '$q', 'StripeFactory', 'HelperFactory', 'SubscriptionFactory', function ($scope, $http, $q, StripeFactory, HelperFactory, SubscriptionFactory) {

    $scope.showingCreditForm = false;
    $scope.showCardForm = false;
    $scope.posting = false;
    $scope.showCoupon = false;
    $scope.couponCode = '';

    //$scope.successSubscribe = false;
    $scope.card = {};

    $scope.toggleCouponShow = function() {
      $scope.showCoupon = !$scope.showCoupon;
    };
    $scope.subscribeToPlan = function(planID) {
        console.log('PLAN ID::: ' + planID);

        $scope.posting = true;

        var stripeCard = HelperFactory.createStripeCardObjectFromFormattedInput($scope.card);

        var StripePromise = StripeFactory.createToken(stripeCard);

        StripePromise.then(function(response)
        {
            console.log(response);
            console.log(StripeFactory.getToken());

            if ($scope.couponCode.length > 0) {
                var createSubscriptionPromise = SubscriptionFactory.createSubscription(planID, StripeFactory.getToken().id, $scope.couponCode);
            }

            else {
                var createSubscriptionPromise = SubscriptionFactory.createSubscription(planID, StripeFactory.getToken().id);
            }


            createSubscriptionPromise.then(function(responseObject) {

                $scope.posting = false;
                $scope.showCardForm = false;
                //Success!
                console.log('SUCCESS on server subscription create');
                console.log(responseObject);
                humane.log(responseObject.message);
                window.location =  responseObject.redirect_url;
            },

            function(responseObject) {
                //Fail :(
                $scope.posting = false;
                $scope.$apply(function() {
                    $scope.posting = false;
                });

                console.log('Subscription fail::   --');
                console.log(responseObject);
                humane.log(responseObject.message);

            });


        }, function(response)
       {
           $scope.posting = false;
           console.log('Stripe card fail::::');
           console.log(response);

           humane.log(StripeFactory.getErrors().message);

       });

    };

    $scope.handleSubscribeButtonPressed = function() {
        if (!$scope.showingCreditForm) {
            //cardFormContainer.slideToggle();
            $scope.showCardForm = true;
            $scope.showingCreditForm = true;
        }


    }<commit_msg>Makes coupon code on subscribe work and error messages display properly<commit_after>app.controller('chooseController', ['$scope', '$http', '$q', 'StripeFactory', 'HelperFactory', 'SubscriptionFactory', function ($scope, $http, $q, StripeFactory, HelperFactory, SubscriptionFactory) {

    $scope.showingCreditForm = false;
    $scope.showCardForm = false;
    $scope.posting = false;
    $scope.showCoupon = false;
    $scope.couponCode = '';

    //$scope.successSubscribe = false;
    $scope.card = {};

    $scope.toggleCouponShow = function() {
      $scope.showCoupon = !$scope.showCoupon;
    };
    $scope.subscribeToPlan = function(planID) {
        console.log('PLAN ID::: ' + planID);

        $scope.posting = true;

        var stripeCard = HelperFactory.createStripeCardObjectFromFormattedInput($scope.card);

        var StripePromise = StripeFactory.createToken(stripeCard);

        StripePromise.then(function(response)
        {
            console.log(response);
            console.log(StripeFactory.getToken());

            if ($scope.couponCode) {

                var createSubscriptionPromise = SubscriptionFactory.createSubscription(planID, StripeFactory.getToken().id, $scope.couponCode);
            }

            else {
                var createSubscriptionPromise = SubscriptionFactory.createSubscription(planID, StripeFactory.getToken().id);
            }


            createSubscriptionPromise.then(function(responseObject) {

                $scope.posting = false;
                $scope.showCardForm = false;
                //Success!
                console.log('SUCCESS on server subscription create');
                console.log(responseObject);
                humane.log(responseObject.message);
                window.location =  responseObject.redirect_url;
            },

            function(responseObject) {
                //Fail :(
                $scope.posting = false;
                $scope.$apply(function() {
                    $scope.posting = false;
                });

                console.log('Subscription fail::   --');
                console.log(responseObject);
                humane.log(responseObject.data.message);

            });


        }, function(response)
       {
           $scope.posting = false;
           console.log('Stripe card fail::::');
           console.log(response);

           humane.log(StripeFactory.getErrors().message);

       });

    };

    $scope.handleSubscribeButtonPressed = function() {
        if (!$scope.showingCreditForm) {
            //cardFormContainer.slideToggle();
            $scope.showCardForm = true;
            $scope.showingCreditForm = true;
        }


    }
{'fraction_non_alphanumeric': 0.11940018744142455, 'fraction_numerical': 0.00018744142455482662, 'mean_word_length': 2.056128293241695, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6956562', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1387, 'n_words': 213}