简体   繁体   中英

How can I create a card using Stripe and Node,js

I'm using Stripe as a payment method in my project using Node.js. I'm following the docs to archive this.

What I need is to create a card with the following information: credit card number, person's name, expiration date and security code.

This is my code:

const createCard = (customer, cardInfo) => {
  return new Promise((resolve, reject) => {
    stripe.customers.createSource(
      customer,
      {
        source: {
          object: 'card',
          ...cardInfo
        }
      },
      (err, card) => {
        if (err) {
          debug('There was an error while creating a new card')
          reject(err)
        }
        debug(card)
        resolve(card)
      }
    )
  })
}

The cardInfo object looks like this:

{
  "number": "4242424242424242",
  "exp_month": "11",
  "exp_year": "2021",
  "cvc": "123",
  "name": "My name"
}

This is what I get in the callback answer:

Sending credit card numbers directly to the Stripe API is generally unsafe. We suggest you use test tokens that map to the test card you are using, see https://stripe.com/docs/testing."

I'm using my develpment api key.

You should be using Stripe.js and Elements (a client-side Javascript library) to tokenize cards on your webpage, and then using the tokens Stripe gives you, on your server-side Node.js code (to either charge them or save for future use).

https://stripe.com/docs/payments/accept-a-payment#web-collect-card-details

Passing card details directly to your server is highly not recommended as it has much higher PCI compliance burden on your integration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM