-
-
Save anonymous/98022f8febeec13db113 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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