Heim  >  Fragen und Antworten  >  Hauptteil

React/Node: Beim Abonnieren mit Trial_period_days ist ein Integrationsfehler aufgetreten

Ich habe in Stripe ein Produkt definiert, das ich als 7-tägige kostenlose Testversion einrichten und dann dem Kunden in Rechnung stellen möchte (es sei denn, er kündigt vorher)

Bei Verwendung einer benutzerdefinierten Nodejs-Funktion über Firebase erhalte ich die folgende Fehlermeldung:

Missing value for stripe.confirmCardPayment intent secret: value should be a client_secret string

Meine Frontend-Funktionalität:

const createSubscription = async () => {
    setProcessing(true);
    setWait('PLEASE WAIT');
    try {
      
      // create a payment method
      const paymentMethod = await stripe?.createPaymentMethod({
        type: "card",
        card: elements?.getElement(CardElement),
        billing_details: {
          name,
          email,
        },
      });

      // call the backend to create subscription
      const response = await fetch("https://XXX.cloudfunctions.net/tplannersubscription", {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
        },
        body: JSON.stringify({
          paymentMethod: paymentMethod?.paymentMethod?.id,
          name,
          lname,
          email,
          priceId
        }),
      }).then((res) => res.json());
      
      const confirmPayment = await stripe?.confirmCardPayment(
        response.clientSecret
      );
};

und meine Knotenfunktion:

cors(request, response, async () => {
        // create a stripe customer
        try {
            if (request.method != "POST") return response.status(400);
            const { name, email, paymentMethod } = request.body;
            // Create a customer
            const customer = await stripe.customers.create({
              email,
              name,
              payment_method: paymentMethod,
              invoice_settings: { default_payment_method: paymentMethod },
            });

            // const priceId = request.priceId;

            // Create a subscription
            const subscription = await stripe.subscriptions.create({
                customer: customer.id,
                items: [{ price: "price_1KZ3nTGxUje7SlyIDUfIXkr3" }],
                payment_settings: {
                  payment_method_options: {
                    card: {
                      request_three_d_secure: "any",
                    },
                  },
                  payment_method_types: ["card"],
                  save_default_payment_method: "on_subscription",
                },
                payment_behavior: "default_incomplete",
                trial_period_days: 7,
                expand: ["latest_invoice.payment_intent"],
              });
            
              // Send back the client secret for payment
            response.json({
              message: "Subscription successfully initiated",
              clientSecret: subscription.latest_invoice.payment_intent.client_secret,
              subID:subscription.id
            });
          } catch (err) {
            console.error(err);
            response.status(500).json({ message: "Internal server error" });
          }
   });

Wenn ich die Trial_period_days herausnehme, funktioniert es einwandfrei, aber wenn ich sie einbeziehe, wird der oben erwähnte Fehler zurückgegeben.

P粉378264633P粉378264633168 Tage vor316

Antworte allen(1)Ich werde antworten

  • P粉497463473

    P粉4974634732024-04-05 13:16:23

    当您创建试用订阅时,不会创建 PaymentIntent,因为目前不需要付款。

    相反,SetupIntent 可用于收集付款方式详细信息。您可以在创建订阅时扩展 pending_setup_intent [0],并通过 confirmCardSetup.

    [0] https://stripe.com/docs/api/订阅/对象#subscription_object-pending_setup_intent

    Antwort
    0
  • StornierenAntwort