Skip to content

Instantly share code, notes, and snippets.

Created May 21, 2013 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/98022f8febeec13db113 to your computer and use it in GitHub Desktop.
Save anonymous/98022f8febeec13db113 to your computer and use it in GitHub Desktop.
Parse.Cloud.define("createSubscription", function(request, response){
var currentUser = Parse.User.current();
Stripe.Customers.create({
plan: "subscription_weekly",
card: request.params.id, //contains Stripe Token
email: currentUser.getUsername(),
description: "Subscription"
}, {
success: function(httpResponse){
//console.log(httpResponse);
var SubscriptionLog = Parse.Object.extend("SubscriptionLog");
var subscriptionLog = new SubscriptionLog();
subscriptionLog.save(null, {
success: function (savedSL) {
console.log("Saved Subscription Log Object"); //Don't ever see this in the CloudLogs
//Create new Subscription Object, owned by Purchaser
var Subscription = Parse.Object.extend("Subscription");
var subscription = new Subscription();
subscription.set("SubscriptionLog", savedSL);
subscription.set("SubId", request.params.SubId);
subscription.set("stripeCustomerId", httpResponse.id);
var subscriptionACL = new Parse.ACL();
subscriptionACL.setPublicReadAccess(false);
subscriptionACL.setWriteAccess(Parse.User.current(), true);
subscriptionACL.setReadAccess(Parse.User.current(), true);
subscription.setACL(subscriptionACL);
subscription.save(null, {
success: function (savedSubscriptionOffer) {
console.log("saved Subscription offer " + savedSubscriptionOffer); //Don't ever see this in the CloudLogs
},
error: function (error) {
console.log("Couldn't save Subscription"); //Don't ever see this in the CloudLogs
}
});
},
error: function (error) {
console.log("Failed to save Subscription Log " + error); //Don't ever see this in the CloudLogs
}
})
response.success(httpResponse);
},
error: function(httpResponse){
response.error("Couldn't create Stripe User");
console.log(httpResponse);
}
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment