Node.js 我能';t创建条带令牌使用';Stripe.tokens.create';

Node.js 我能';t创建条带令牌使用';Stripe.tokens.create';,node.js,api,stripe-payments,Node.js,Api,Stripe Payments,我使用Nodejs创建条带后端 我想创建客户信用卡使用API 我在参数中输入注册所需的所有卡信息,并访问APIhttp://localhost:5000/stripe-创建卡片, 但是返回标记为null 我根据参考资料编写了代码,因此我认为没有错误 我怎样才能得到代币 const express = require('express'); const stripe = require('stripe')('MYKEY'); const bodyParser = require('body-par

我使用Nodejs创建条带后端

我想创建客户信用卡使用API

我在参数中输入注册所需的所有卡信息,并访问API
http://localhost:5000/stripe-创建卡片
, 但是返回标记为null

我根据参考资料编写了代码,因此我认为没有错误

我怎样才能得到代币

const express = require('express');
const stripe = require('stripe')('MYKEY');
const bodyParser = require('body-parser');
const app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
    extended: true
}));

app.set('port', (process.env.PORT || 5000));
//app.listen(3000);

app.post('/create_customer',(req,res) => {
    const email = req.body.email;
    console.log(email);
    stripe.customers.create({
        email : email
   },function(err, customer) {
        // asynchronously called
        res.send(customer);
        console.log(customer);
    })
});

app.post('/body',(req,res) =>{
   //res.setHeader('Content-Type', 'text/plain');
    console.log(req.body);
    console.log(req.body.email);
});

app.post('/stripe-create-card', (req, res)=>  {
    const customer_id = req.body.customer_id;
    const card_num = req.body.card_num;
    const card_month = req.body.card_month;
    const card_year = req.body.card_year;
    const card_cvc = req.body.card_cvc;

    console.log(customer_id,card_num,card_month,card_year,card_cvc);

    stripe.tokens.create({
        card: {
            "number": '4242424242424242',
            "exp_month": 12,
            "exp_year": 2020,
            "cvc": "123"
        }
    }, function(err, token) {
        // asynchronously called
        console.log(token);
        const params = {
            source: token.id
        };
        stripe.customers.createSource(customer_id, params, function(err, card) {
            console.log(card);
        });
    });
});


app.listen(app.get('port'), function () {
    console.log('Node app is running on port', app.get('port'))
});

我获得了一个令牌,但这是通过使用以下代码从客户端获得的:

<form action="/orders/payment/confirmed" method="POST">
        <div class="formError"></div>
        <div class="formSuccess">Your payment has been successfully submitted, please check your email</div>
        <div>
            <script src="https://checkout.stripe.com/checkout.js"></script>
            <button id="paymentData" class="cta blue" >Purchase</button>            
        </div>
    </form>
之后,您可以使用令牌id来处理付款

祝你好运

    const handler = StripeCheckout.configure({
    key: 'your public key',
      image: 'your image path',
      locale: 'auto',
      token: token => {
      //Here you receive your token id as token.id, so you can make a request 
      //to your server with this key
    })