Last active
April 27, 2017 13:29
-
-
Save awilson28/74dc8dbfff772364f3c3007964c1286d 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
// Set your secret key: remember to change this to your live secret key in production | |
// See your keys here: https://dashboard.stripe.com/account/apikeys | |
var stripe = require("stripe")("sk_test_lgbvEqHnmqpoLJ8ZwBjded8X"); | |
// Token is created using Stripe.js or Checkout! | |
// Get the payment token submitted by the form: | |
var token = request.body.stripeToken; // Using Express | |
// Create a Customer: | |
stripe.customers.create({ | |
email: "[email protected]", | |
source: token.id, // STORE TOKEN ID: http://stackoverflow.com/questions/34754142/stripe-error-token-is-not-supported-when-trying-to-sign-up-to-subscription | |
}).then(function(customer) { | |
// YOUR CODE: Save the customer ID and other info in a database for later. | |
return stripe.charges.create({ | |
amount: 1000, | |
currency: "usd", | |
customer: customer.id, | |
}); | |
}).then(function(charge) { | |
// Use and save the charge info. | |
}); | |
// YOUR CODE (LATER): When it's time to charge the customer again, retrieve the customer ID. | |
stripe.charges.create({ | |
amount: 1500, // $15.00 this time | |
currency: "usd", | |
customer: customerId, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment