Last active
June 28, 2020 05:35
-
-
Save shanwixcode/8a9e364b7b112dab52326ed4b6547b41 to your computer and use it in GitHub Desktop.
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