条纹支付意向卡如何实施?

时间:2019-05-08 12:56:03

标签: angular stripe-payments

我正在尝试使用PaymentIntent API在条带上实现支付。 我的问题是我找不到在哪里/如何为PaymentIntent提供卡详细信息(编号,exp_year,exp_month,cvc)。

这是我的代码https://github.com/rever96/example-stripe-paymentIntent,用于创建PaymentIntent,然后进行确认。确认将状态更改为succeded。因此,我想到:“哇,它在起作用!”但是卡的详细信息呢?

那是服务器代码感兴趣的:

const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');

app.post("/createPayment", (req, res) => {
    console.log('i\'m trying to create a paymentIntent');
    (async () => {
        paymentIntent = await stripe.paymentIntents.create({
            amount: 1099,
            currency: 'eur',
            payment_method_types: ['card'],
        }).then(paymentIntentResponse => {
            console.log("paymentIntent created");
            res.send(paymentIntentResponse)
        });
    })();
});

app.post("/confirmPayment", (req, res) => {
    console.log(req.body);
    (async () => {
        paymentIntent = await stripe.paymentIntents.confirm(req.body.id, { payment_method: 'pm_card_visa' })
            .then(paymentIntentResponse => {
                console.log("paymentIntent confirmed");
                res.send(paymentIntentResponse)
            });
    })();
});

这是客户代码感兴趣的:

constructor(
    private http: HttpClient) {
  }
  ngOnInit() {
    this.http.post('http://localhost:8080/createPayment', {}).subscribe(res => {
      console.log('back from server!');
      console.log(res);
      this.paymentIntentID = res['id'];
      this.paymentIntentClientSecret = res['client_secret'];
    });
  }

  submitPaymentData() {
    this.collectCardDetails();
    console.log('confirm payment');
    this.http.post('http://localhost:8080/confirmPayment', { id: this.paymentIntentID }).subscribe(res => {
      console.log('back from server!');
      console.log(res);
    });
  }

1 个答案:

答案 0 :(得分:1)

PaymentIntent的流程通常如下:

  1. 在服务器上创建PaymentIntent
  2. 将客户端机密传递给前端
  3. 使用Stripe Elements收集卡信息
  4. 使用Stripe.js handleCardPayment处理付款

您已经完成了步骤1,您需要完成其余的步骤: https://stripe.com/docs/payments/payment-intents/quickstart#passing-to-client