Skip to content

Instantly share code, notes, and snippets.

@beardedtim
Last active July 28, 2017 22:16
Show Gist options
  • Save beardedtim/36f27fc3b149e8347e0f55595287d442 to your computer and use it in GitHub Desktop.
Save beardedtim/36f27fc3b149e8347e0f55595287d442 to your computer and use it in GitHub Desktop.
Creating mass dummy data in Stripe for testing
/*
We get the dummy tokens from
https://stripe.com/docs/testing#cards-responses
*/
const stripe = require('stripe')(process.env.STRIPE_KEY);
const faker = require('faker');
const createAmount = () => Math.floor(Math.random() * 2000) + 500
const makeCharge = ({ source }) => {
const amount = createAmount();
const tenant_id = Math.floor(Math.random() * 50) + 1;
const count_name = faker.address.county();
const metadata = {
'tenant_id': tenant_id,
'order_id': Math.floor(Math.random() * 10000) + 1,
};
return stripe.charges.create({
description: `tenant_id:${tenant_id};county_name=${count_name}`,
metadata,
amount,
source,
currency: 'usd',
});
}
const methods = [
'tok_bypassPending',
'tok_domesticPricing',
];
const errorMethods = [
'tok_avsFail',
'tok_avsLine1Fail',
'tok_avsZipFail',
'tok_avsUnchecked',
'tok_cvcCheckFail',
'tok_chargeCustomerFail',
'tok_riskLevelElevated',
'tok_chargeDeclined',
'tok_chargeDeclinedFraudulent',
'tok_chargeDeclinedIncorrectCvc',
'tok_chargeDeclinedExpiredCard',
'tok_chargeDeclinedProcessingError',
];
const amountPerType = 100;
methods.forEach(source => {
for (let i = 0; i < amountPerType; i++) {
makeCharge({
source,
})
.catch(err => {
console.log(err);
})
}
})
errorMethods.forEach(source => {
for (let i = 0; i < 20; i++) {
makeCharge({
source,
})
.catch(err => {
console.log(err);
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment