Skip to content

Instantly share code, notes, and snippets.

@shanwixcode
Last active June 28, 2020 05:35
Show Gist options
  • Save shanwixcode/8a9e364b7b112dab52326ed4b6547b41 to your computer and use it in GitHub Desktop.
Save shanwixcode/8a9e364b7b112dab52326ed4b6547b41 to your computer and use it in GitHub Desktop.
Stripe Tutorial - Dude Lemon
//stripeProcessor.jsw
import stripe from 'stripe';
const key = require("stripe")("sk_test_xxxxxx"); //Stripe SECRET API Key
//---------------------------------------------Create Customer---------------------------------------------//
export function createCustomer(token, emailId) {
return key.customers.create({
email: emailId,
source: token
})
.then( function(err, customer) {
if (err) {
return Promise.resolve(err); //does not work
}
return Promise.resolve(customer);
})
.catch( (err) => {
return err;
});
}
//---------------------------------------------Create Subscription---------------------------------------------//
export function createSubscription(cus, plan) {
return key.subscriptions.create({
customer: cus,
items: plan
})
.then( function(err, subscription) {
if (err) {
return Promise.resolve(err); //does not work
}
return Promise.resolve(subscription);
})
.catch( (err) => {
return err;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment