即使提供了 customerId,条带客户也未知

问题描述 投票:0回答:1

我觉得有些事情我没有在这里做。 所以基本上我确保 customerId 匹配,但在处理付款后,它仍然显示客户未知。

后端

    const user = await strapi.entityService.findOne(
      "plugin::users-permissions.user",
      ctx.state.user.id
    );

    if (user.stripeCustomerId == null) {
      const customer = await stripe.customers.create({ email: user.email });
      const result = await strapi.entityService.update(
        "plugin::users-permissions.user",
        ctx.state.user.id,
        {
          data: {
            stripeCustomerId: customer.id,
          },
        }
      );

      const ephemeralKey = await stripe.ephemeralKeys.create(
        { customer: customer.id },
        { apiVersion: "2024-06-20" }
      );

      const paymentIntent = await stripe.paymentIntents.create({
        amount: 4444,
        currency: "usd",
      });

      return {
        ephemeralKey: ephemeralKey.secret,
        paymentIntent: paymentIntent.client_secret,
        customerId: customer.id,
      };
    } else {
      const ephemeralKey = await stripe.ephemeralKeys.create(
        { customer: user.stripeCustomerId },
        { apiVersion: "2024-06-20" }
      );

      const paymentIntent = await stripe.paymentIntents.create({
        amount: 4444,
        currency: "usd",
      });

      return {
        ephemeralKey: ephemeralKey.secret,
        paymentIntent: paymentIntent.client_secret,
        customerId: user.stripeCustomerId,
      };
    }

前端

    const { initPaymentSheet, presentPaymentSheet } = useStripe();
    const { status, jwt } = useAuthStore();

    const proceedToOrder = () => {
        var config = {
            method: 'post',
            url: 'http://192.168.50.61:1337/api/orders/create-payment-intent',
            headers: {
                Authorization: `Bearer ${jwt}`,
            },
        };

        axios(config).then(async (response) => {
            const { error } = await initPaymentSheet({
                merchantDisplayName: 'Panda Eats',
                customerId: response.data.customerId,
                customerEphemeralKeySecret: response.data.ephemeralKey,
                paymentIntentClientSecret: response.data.paymentIntent,
                returnURL: 'stripe-example://stripe-redirect',
                // retrieve this from your server
            });
            if (error) {
                // handle error
            } else {
                presentPaymentSheet();
            }
        });
    };
    const { showAuthSheet } = useAuthSheet();
    const handleOrderNow = () => {
        if (status == 'authenticated') {
            proceedToOrder();
        } else {
            showAuthSheet();
        }
    };

非常感谢任何帮助!

我尝试使用 stripe api 生成的客户端 ID 处理付款,我希望从 stripe 仪表板中看到该付款属于生成的客户,但付款显示为访客。

stripe-payments
1个回答
0
投票

您的 PaymentIntent 应使用相应的

customer
id

创建
const paymentIntent = await stripe.paymentIntents.create({
   amount: 4444,
   currency: "usd",
   customer : customer.id
});

https://docs.stripe.com/api/ payment_intents/create#create_ payment_intent-customer

© www.soinside.com 2019 - 2024. All rights reserved.