首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用付款方式支付条状支付意图

使用付款方式支付条状支付意图
EN

Stack Overflow用户
提问于 2022-01-18 19:35:22
回答 1查看 2.2K关注 0票数 2

我有这个:

代码语言:javascript
运行
复制
const stripe = require('stripe')('sk_test', {
        stripeAccount: 'acct_...'
    });
const paymentIntent = await stripe.paymentIntents.create({
    amount: 1900,
    currency: 'cad',
    customer: 'cus_...',
    // confirm: true,
  }, {
    stripeAccount: 'acct_...',
});
console.log(paymentIntent)

然后我去运行这个paymentIntent,它可以工作,但是不会主动向客户收费,因为它说它没有文件中的支付方法。然后我取这个客户id,看看我的条形仪表板,它显示了那里的支付方法,这个方法和id相匹配。所以现在我相信我做错了创建paymentIntent,但付款是通过,只是没有确认,因为它说没有付款方式附加!那为什么这不起作用?

错误:UnhandledPromiseRejectionWarning: Error: You cannot confirm this PaymentIntent because it's missing a payment method. You can either update the PaymentIntent with a payment method and then confirm it again, or confirm it again directly with a payment method.

EN

回答 1

Stack Overflow用户

发布于 2022-01-19 02:42:58

PaymentIntent需要一个支付方法对象,例如;

代码语言:javascript
运行
复制
   payment_method_types: [card],

PaymentIntent对象

代码语言:javascript
运行
复制
   const {
  error: backendError,
  clientSecret,
  paymentIntentId,
  transfer_group,
} = await fetch('/create-payment-intent', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    paymentMethodType: 'card',
    currency: 'cad',
    customerEmail: billingDetails.email,
    description: 'Basket_Order_Id',
  }),
}).then((r) => r.json());
 and when you created the paymentintent on your backend you should return 

  app.post('/create-payment-intent', async (req, res) => {
  const {paymentMethodType, currency, customerEmail, description, 
   suppliers} =
  req.body;
  console.log('paymentIntent Create requ body', req.body);

  req.session.suppliers = suppliers;
  suppliersArray = suppliers;

 const idEmpotency = nanoid();
 // Each payment method type has support for different currencies. In order 
 to
 // support many payment method types and several currencies, this server
 // endpoint accepts both the payment method type and the currency as
// parameters
//
 // Some example payment method types include `card`, `ideal`, and 
`alipay`.
 const params = {
payment_method_types: [paymentMethodType], 'CARD'
amount: 20000,
currency: currency,
description: description,
receipt_email: customerEmail,
statement_descriptor_suffix: 'Your Bank Descriptor on Customer Account',
transfer_group: idEmpotency,
// confirm: true,
// capture_method: 'manual',
 };
   try {
   const paymentIntent = await stripe.paymentIntents.create(params);

// Send publishable key and PaymentIntent details to client
console.log('paymentIntent', paymentIntent);

res.send({
  clientSecret: paymentIntent.client_secret, - SENDING YOUR CLIENTSECRET
  paymentIntentId: paymentIntent.id,
  transfer_group: paymentIntent.transfer_group,
});
   }   catch (e) {
  return res.status(400).send({
  error: {
    message: e.message,
   },
   });
   }
  });

  client_secret and use it on your front-end 



 const {error: stripeError, paymentIntent} = await stripe.confirmCardPayment(
  clientSecret, USE YOUR CLIENT SECRET THAT RETURNED FROM YOUR BACKEND FROM  PAYMENT INTENT OBJECT
  {
    payment_method: {
      card: elements.getElement(CardElement),
      billing_details: {
        name: 'Michael',
      },
    },
  }
);


 Before confirming the client_secret that returned from payment_intent you can not succesfully confirm the payment.

 You can use stripe elements to start with their own card payment component.

 I recommend you to check here https://stripe.com/docs/payments/quickstart, you will get more idea...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70761436

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档