Stripe Tutorial - Dude Lemon
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
//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