66 lines
1.8 KiB
CoffeeScript
66 lines
1.8 KiB
CoffeeScript
$ = jQuery
|
|
context = window
|
|
logger = context.JK.logger
|
|
|
|
@SubscriptionStore = Reflux.createStore(
|
|
{
|
|
listenables: @SubscriptionActions
|
|
|
|
subscription: null
|
|
|
|
|
|
init: ->
|
|
this.listenTo(context.AppStore, this.onAppInit)
|
|
|
|
onAppInit: (@app) ->
|
|
|
|
onUpdateSubscription: (subscription) ->
|
|
|
|
rest.getSubscription().done (subscription) =>
|
|
@subscription = subscription
|
|
console.log("subscription store update", subscription)
|
|
@trigger(@subscription)
|
|
.fail(() =>
|
|
@app.layout.notify({
|
|
title: "unable to fetch subscription status",
|
|
text: "Please contact support@jamkazam.com"
|
|
})
|
|
)
|
|
|
|
onChangeSubscription: (plan_code) ->
|
|
rest.changeSubscription({plan_code: plan_code}).done((subscription) =>
|
|
@subscription = subscription
|
|
console.log("subscription change update", subscription)
|
|
@app.layout.notify({
|
|
title: "Subscription updated!",
|
|
text: "Thank you for supporting JamKazam!"
|
|
})
|
|
@trigger(@subscription)
|
|
)
|
|
.fail((jqXHR) =>
|
|
if jqXHR.status == 422
|
|
@app.layout.notify({
|
|
title: "you already have this subscription",
|
|
text: "No changes were made to your account."
|
|
})
|
|
else
|
|
@app.layout.notify({
|
|
title: "unable to update subscription status",
|
|
text: "Please contact support@jamkazam.com. Error:\n #{jqXHR.responseText}"
|
|
})
|
|
)
|
|
|
|
onCancelSubscription: () ->
|
|
rest.cancelSubscription().done((result) =>
|
|
@subscription = {}
|
|
console.log("cancelled successfully")
|
|
@trigger(@subscription)
|
|
)
|
|
.fail((jqXHR) =>
|
|
@app.layout.notify({
|
|
title: "Subscription Cancelled",
|
|
text: "Thanks for being a supporter!"
|
|
})
|
|
)
|
|
}
|
|
) |