簡體   English   中英

使用支付方式進行條帶支付意圖

[英]use payment method for stripe paymentintent

我有這個:

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)

所以然后我 go 來運行這個 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. 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.

PaymentIntent 需要付款方式 Object,例如;

   payment_method_types: [card],

PaymentIntent object

   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...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM