examples/checkout.js
function getToken(stripeCredentials) {
    return new Promise(function (resolve, reject) {

        var required = [
            "stripe_secret",
            "credit_card_number",
            "credit_card_cvc",
            "credit_card_expiry_month",
            "credit_card_expiry_year"
        ];

        if (stripeCredentials.stripe_api_key.indexOf("sk") === 0) {
            console.log("*** WARNING: using a secret stripe api key. ***");
        }

        var stripe = require('stripe')(stripeCredentials.stripe_api_key);

        var card = {
            number: stripeCredentials.credit_card_number,
            exp_month: stripeCredentials.credit_card_expiry_month,
            exp_year: stripeCredentials.credit_card_expiry_year,
            cvc: stripeCredentials.credit_card_cvc
        };

        stripe.tokens.create({ card: card },
            (err, token) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(token.id);
                }
            }
        );
    });
}
function getToken(stripeCredentials) {
    return new Promise(function (resolve, reject) {

        var required = [
            "stripe_secret",
            "credit_card_number",
            "credit_card_cvc",
            "credit_card_expiry_month",
            "credit_card_expiry_year"
        ];

        if (stripeCredentials.stripe_api_key.indexOf("sk") === 0) {
            console.log("*** WARNING: using a secret stripe api key. ***");
        }

        var stripe = require('stripe')(stripeCredentials.stripe_api_key);

        var card = {
            number: stripeCredentials.credit_card_number,
            exp_month: stripeCredentials.credit_card_expiry_month,
            exp_year: stripeCredentials.credit_card_expiry_year,
            cvc: stripeCredentials.credit_card_cvc
        };

        stripe.tokens.create({ card: card },
            (err, token) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(token.id);
                }
            }
        );
    });
}
function getToken ( stripeCredentials ) { return new Promise ( function ( resolve , reject ) { var required = [ "stripe_secret" , "credit_card_number" , "credit_card_cvc" , "credit_card_expiry_month" , "credit_card_expiry_year" ] ; if ( stripeCredentials . stripe_api_key . indexOf ( "sk" ) === 0 ) { console . log ( "*** WARNING: using a secret stripe api key. ***" ) ; } var stripe = require ( 'stripe' ) ( stripeCredentials . stripe_api_key ) ; var card = { number : stripeCredentials . credit_card_number , exp_month : stripeCredentials . credit_card_expiry_month , exp_year : stripeCredentials . credit_card_expiry_year , cvc : stripeCredentials . credit_card_cvc } ; stripe . tokens . create ( { card : card } , ( err , token ) => { if ( err ) { reject ( err ) ; } else { resolve ( token . id ) ; } } ) ; } ) ; }
helper function to get a stripe token
helper function to get a stripe token