PageSourceSearch

https://app.exabler.com/app/userPlan.js

js exabler.com collected 2026-09-24 10:21:10 UTC 6,433 bytes, 215 lines download raw bytes

1app.controller('editUserPlan', function ($scope,
2                                         $rootScope,
3                                         $http,
4                                         $uibModalInstance,
5                                         $cookies,
6                                         Data,
7                                         userPlan,
8                                         billing,
9                                         AuthService) { // this
10
11
12    $scope.billing = billing;
13    //$scope.paymentDetails = {};
14
15    token = '';
16    $scope.stripe_customer_obj = {};
17
18    //$rootScope.userPlan = userPlan;
19
20    $scope.selectedPlan = {};
21    $scope.selectedPlan.plan_number = $rootScope.userPlan.plan_selection;
22
23    $scope.carddetails = {};
24    $scope.billingcycle = {};
25    $scope.edit_plan = {};
26
27
28    if (!$rootScope.userPlan.stripe_id && $rootScope.userPlan.plan_selection != 0) {
29
30        $scope.changecard = true;
31
32    } else {
33
34        $scope.changecard = false;
35
36    }
37
38
39    $scope.updatePlan = function () {
40
41
42        // upgrading from Logon - subscriptions never created
43        if ($rootScope.userPlan.plan_selection == 0 && !$rootScope.userPlan.stripe_id) {
44            // token is set to null to process just the plan change
45            processPlanChange(null, $rootScope.uid, $rootScope.email, $scope.selectedPlan.plan_number, null, $rootScope.userPlan.plan_selection);
46
47        }
48
49        // upgrading from Logon - customer id created previously
50        else if ($scope.userPlan.plan_selection == 0 && $scope.userPlan.stripe_id) {
51            // token is set to null to process just the plan change
52            processPlanChange(null, $rootScope.uid, $rootScope.email, $scope.selectedPlan.plan_number, $rootScope.userPlan.stripe_id, $rootScope.userPlan.plan_selection);
53
54        }
55
56        // up or downgrading from any plan - customer id created previously
57        else {
58            // token is set to null to process just the plan change
59            processPlanChange(null, $rootScope.uid, $rootScope.email, $scope.selectedPlan.plan_number, $rootScope.userPlan.stripe_id, $rootScope.userPlan.plan_selection);
60
61        }
62
63
64    };
65
66
67    $scope.handleStripe = function (status, response) {
68
69        $scope.edit_plan.submitted = true;
70
71        // For new or updated card details
72        if (response.error) {
73            // there was an error. Fix it.
74            var msgobj = {status: "error", message: response.error.message + " Card not charged."};
75            Data.toast(msgobj);
76
77        } else {
78            // got stripe token, now charge it or smt
79            token = response.id;
80
81
82            if ($scope.userPlan.stripe_id) {  // $scope.changecard && ($scope.selectedPlan.plan_number == $rootScope.userPlan.plan_selection) && 
83                // Existing customer
84                processPlanChange(token, null, $rootScope.email, null, $rootScope.userPlan.stripe_id, $rootScope.userPlan.plan_selection);
85
86            } else {
87                // New customer	
88                processPlanChange(token, $rootScope.uid, $rootScope.email, $scope.selectedPlan.plan_number, null, $rootScope.userPlan.plan_selection);
89
90            }
91        }
92    };
93
94    // no longer used
95    getPaymentDetails = function (stripe_id) {
96
97        postdata = {stripe_id};
98
99        $http({
100
101            method: 'POST',
102            url: '/get_payment_details.php',
103            data: postdata,
104            headers: {
105                'Content-Type': 'application/x-www-form-urlencoded'
106            }
107            // cache: $templateCache
108        }).success(function (response) {
109
110            $scope.carddetails = response.sources.data[0];
111
112            if (userPlan.plan_details.plan_number != 0) {
113                var billCycleDate = new Date(response.subscriptions.data[0].current_period_end * 1000).getDate();
114            }
115            $scope.billingcycle = billCycleDate;
116
117        }).error(function (response) {
118
119            $scope.codeStatus = response || "Request failed";
120
121
122        });
123
124
125    };
126
127
128    $scope.cancel = function () {
129
130        $uibModalInstance.close('cancel');
131
132    };
133
134
135    if ($rootScope.userPlan.stripe_id) {
136
137        getPaymentDetails($rootScope.userPlan.stripe_id);
138
139    }
140
141    // no longer used
142    processPlanChange = function (token, uid, email, plan_id, stripe_id, prev_plan_id) {
143
144
145        postdata = {token, uid, email, plan_id, stripe_id, prev_plan_id};
146
147
148        $http({
149            method: 'POST',
150            url: '/update_user_plan.php',
151            data: postdata,
152            headers: {
153                'Content-Type': 'application/x-www-form-urlencoded'
154            }
155            // cache: $templateCache
156        }).success(function (response) {
157
158            //$scope.codeStatus = response.data;
159
160            Data.toast(response);
161
162            // update the MVC and cookie (used to communicate with php)
163
164            if (response.status != 'error') {
165
166                // Existing customer and new customer
167                if (!$scope.changecard || !stripe_id) {
168
169                    $rootScope.userPlan.plan_selection = $scope.selectedPlan.plan_number;
170                    $rootScope.userPlan.plan_details = $rootScope.billing[$scope.selectedPlan.plan_number];
171
172                    // response.data.id contains all details - can just return the customer stripe id if required
173                    if (!stripe_id) {
174                        $rootScope.userPlan.stripe_id = response.data.id;
175                    }
176
177                    Data.post('plan_upgrade', {
178                        plan_selection: $scope.selectedPlan.plan_number,
179                        stripe_id: $rootScope.userPlan.stripe_id
180                    }).then(function (results) {
181
182                    });
183
184
185                    $cookies.put("plan_name", $rootScope.userPlan.plan_details.plan_name);
186
187
188                    $uibModalInstance.close('ok');
189                }
190
191                if ($scope.changecard) {
192
193                    $scope.changecard = false;
194                    $scope.carddetails = response.data.sources.data[0];
195
196
197                }
198
199            } else {
200                // do nothing
201            }
202
203
204        }).error(function (response) {
205
206            $scope.codeStatus = response || "Request failed";
207            var msgobj = {status: 'error', message: 'There was an error in updating your details. Code M1.'};
208            Data.toast(msgobj);
209
210        });
211
212        return false;
213    };
214
215});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.