Saya mempunyai produk yang ditakrifkan dalam Stripe yang saya ingin sediakan sebagai percubaan percuma selama 7 hari dan kemudian mengenakan bayaran kepada pelanggan (melainkan mereka membatalkan terlebih dahulu)
Menggunakan fungsi Nodejs tersuai melalui Firebase - Saya mendapat ralat berikut:
Missing value for stripe.confirmCardPayment intent secret: value should be a client_secret string
Fungsi bahagian hadapan saya:
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 ); };
dan fungsi nod saya:
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" }); } });
Jika saya mengeluarkan Trial_period_days maka ia berfungsi dengan baik, tetapi jika saya memasukkannya ia mengembalikan ralat seperti yang dinyatakan di atas.
Apabila anda membuat langganan percubaan, PaymentIntent tidak dibuat kerana tiada pembayaran diperlukan pada masa ini.
Sebaliknya, SetupIntent boleh digunakan untuk mengumpul butiran kaedah pembayaran. Anda boleh melanjutkan
pending_setup_intent
[0] apabila membuat langganan dan lulus confirmCardSetup一个>.[0] https://stripe.com/docs/api/subscription/object#subscription_object-pending_setup_intent