Skip to content

Instantly share code, notes, and snippets.

@naterexw
Created May 30, 2020 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naterexw/eb7e1abfb6e6ad6055e7bee578bb1026 to your computer and use it in GitHub Desktop.
Save naterexw/eb7e1abfb6e6ad6055e7bee578bb1026 to your computer and use it in GitHub Desktop.
jake
const fs = require('fs');
const stripe = require('stripe')('STRIPE KEY GOES HERE');
let { task, desc } = require('jake');
const read_stripe_config = config_name => {
const file = fs.readFileSync(`./data/${config_name}.json`);
return JSON.parse(file);
};
desc('Seeds');
task('default', () => {
const products = read_stripe_config('products');
const plans = read_stripe_config('plans');
const skus = read_stripe_config('sku');
const coupons = read_stripe_config('coupons');
products.map(async product => {
try {
await stripe.products.retrieve(product.id);
} catch (err) {
if (err.type) {
stripe.products.create(product);
}
}
});
plans.map(async plan => {
try {
await stripe.plans.retrieve(plan.id);
} catch (err) {
if (err.type) {
stripe.plans.create(plan);
}
}
});
skus.map(async sku => {
try {
await stripe.skus.retrieve(sku.id);
} catch (err) {
if (err.type) {
stripe.skus.create(sku);
}
}
});
coupons.map(async coupon => {
try {
await stripe.coupons.retrieve(coupon.id);
} catch (err) {
if (err.type) {
stripe.coupons.create(coupon);
}
}
});
});
desc('Create customer');
task('customers', async () => {
const customers = read_stripe_config('customers');
customers.map(async customer => {
const stripeCustomer = await stripe.customers.create({
email: customer.email,
});
console.log(stripeCustomer.id);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment