MCPcopy Create free account
hub / github.com/codecombat/codecombat / unsubscribe

Method unsubscribe

app/views/account/SubscriptionView.js:249–281  ·  view source on GitHub ↗
(message, render)

Source from the content-addressed store, hash-verified

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

Callers 4

onTrialRequestSubmitMethod · 0.45
destroyMethod · 0.45

Calls 7

reloadMethod · 0.80
patchMethod · 0.80
getMethod · 0.45
cloneMethod · 0.45
trackEventMethod · 0.45
errorMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected