Stripe Backend Demo

node v4.9.1
version: 1.0.0
endpointsharetweet
var stripe = require("stripe")( "sk_test_BQokikJOvBiI2HlWgH4olfQ2" ) // On the client-side web app or mobile app var tok = (await stripe.tokens.create({ card: { "number": '4242424242424242', "exp_month": 12, "exp_year": 2018, "cvc": '124' } })) console.log(" Token ID: " + tok.id) console.log(" Card Last 4: " + tok.card.last4) console.log(" Card Expiry: " + tok.card.exp_month + "/" + tok.card.exp_year) console.log(" Card Type: Brand - " + tok.card.brand + "; Country - " + tok.card.country + "; Type - " + tok.card.funding + ";") console.log(" Card Fingerprint: " + tok.card.fingerprint) tok
Now that you have the token on your client side, you send it to your server. Once the token is on your server, you can use it to either charge the card or to save the card for later use.
// Save the card var cus = (await stripe.customers.create({ description: 'Stripe customer for User ID: 23321194729', source: tok.id // obtained with client-side app })) console.log("Card saved on Stripe for future use") console.log(" Card Fingerprint: " + cus.sources.data[0].fingerprint) cus
// Charge the customer var charge = (await stripe.charges.create({ amount: 2000, currency: "usd", customer: cus.id, description: "Order ID: 233959672" })) console.log("Charge successfully created on customer: " + charge.customer + " for " + charge.currency + " " + charge.amount + " on card: " + charge.source.fingerprint) charge
Loading…

no comments

    sign in to comment