(message, render)
| 247 | } |
| 248 | |
| 249 | unsubscribe (message, render) { |
| 250 | const payPalInfo = me.get('payPal') |
| 251 | const stripeInfo = _.clone(me.get('stripe')) |
| 252 | if (payPalInfo != null ? payPalInfo.billingAgreementID : undefined) { |
| 253 | api.users.cancelBillingAgreement({ userID: me.id, billingAgreementID: (payPalInfo != null ? payPalInfo.billingAgreementID : undefined) }) |
| 254 | .then(response => { |
| 255 | if (window.tracker != null) { |
| 256 | window.tracker.trackEvent('Unsubscribe End', { message, category: 'Subscription' }) |
| 257 | } |
| 258 | return document.location.reload() |
| 259 | }).catch(jqxhr => { |
| 260 | return console.error('PayPal unsubscribe', jqxhr) |
| 261 | }) |
| 262 | } else if (stripeInfo) { |
| 263 | delete stripeInfo.planID |
| 264 | me.set('stripe', stripeInfo) |
| 265 | me.once('sync', function () { |
| 266 | if (window.tracker != null) { |
| 267 | window.tracker.trackEvent('Unsubscribe End', { message, category: 'Subscription' }) |
| 268 | } |
| 269 | return document.location.reload() |
| 270 | }) |
| 271 | me.patch({ headers: { 'X-Change-Plan': 'true' } }) |
| 272 | } else { |
| 273 | console.error('Tried to unsubscribe without PayPal or Stripe user info.') |
| 274 | this.state = 'unknown_error' |
| 275 | this.stateMessage = 'You do not appear to be subscribed.' |
| 276 | render() |
| 277 | } |
| 278 | if (message) { |
| 279 | return $.post('/contact', { message, subject: 'Cancellation' }) |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | update (render) { |
| 284 | let payments |
no test coverage detected