-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
45 lines (39 loc) · 1.36 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
let readlineSync = require('readline-sync');
let creditCardNumber = readlineSync.question(`\nEnter your card number: `);
let expiryMonth = readlineSync.question(`\nEnter card expiry month: `);
let expiryYear = readlineSync.question(`\nEnter card expiry year: `);
let cvcCode = readlineSync.question(`\nEnter card CVC Code: `);
let cardObj = {
"creditCardNumber": creditCardNumber,
"expiryMonth": expiryMonth,
"expiryYear": expiryYear,
"cvcCode": cvcCode
}
const stripe = require('stripe')('sk_test_51LFrJxDFuopDtcibKS1UtQ7A2bF6QIzady9sCrbzOhaWzfkPUIF9jFXaBU6bwiv6qmTqrB7HvluJm11cnDGJGUGM00itW5gpWm');
let tokenid = 0;
let chargeid = 0;
const token = stripe.tokens.create({
card: {
number: creditCardNumber,
exp_month: expiryMonth,
exp_year: expiryYear,
cvc: cvcCode,
},
})
.then(data => {
tokenid = data.id;
cardObj["Token ID"] = tokenid;
const charge = stripe.charges.create({
amount: 360,
currency: 'usd',
description: 'Example charge',
source: tokenid,
statement_descriptor: 'Custom descriptor',
})
.then(response => {
chargeid = response.id
cardObj["Charge ID"] = chargeid;
console.log(`Payment Successful`)
console.log(cardObj)
});
})