我在我的网站上实现了在 Vercel、NodeJS、React 上运行的 stripe。
我在代码中指定了付款方式。一半的情况下,我可以使用信用卡、Apple Pay 和 PayPal 结帐。但其他时候这些根本不显示。如图所示。或者您可以通过此结账链接亲自查看:https://checkout.stripe.com/c/pay/cs_live_b1r0b1liKGrMcWBoga8ydq6cIUjJdSnwQQs7Wn4OEV97HiS3sH0TVikavn#fidkdWxOYHwnPyd1blppbHNgWjA0SHIxR0xJdTYwcERS MWBuY0lLQnNQZGYxZ3F2N2NPQUJRd1FSCH1fMWdPZlc2bHFDa0xPQ3JLcVBWNVZXMXQ1dnBIRlBPf05yclx9UnJEXDViV2lfb3NANTV2RmthMmRQdycpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8 dWANPydocGlxbFpscWBoJyknYGtkZ2lgVWlkZmBtamlhYHD2Jz9xd3BgeCUl
这是我创建条纹结帐页面的代码:
// pages/api/create-checkout-session.js
import Stripe from 'stripe';
// Initialize Stripe with your secret key
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
export default async function handler(req, res) {
if (req.method === 'POST') {
const { name, productId, referenceText } = req.body;
try {
const product = await stripe.products.retrieve(productId);
const price = await stripe.prices.list({
product: productId,
active: true,
limit: 1
});
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card', 'paypal', 'eps', 'giropay'], // Add all desired payment methods here
currency: 'eur',
line_items: [
{
price: price.data[0].id,
adjustable_quantity: {
enabled: true,
minimum: 1,
maximum: 10,
},
quantity: 1,
},
],
custom_fields: [
{
key: 'Notes',
label: {
type: 'custom',
custom: 'Nachricht an Meine Schnitten',
},
type: 'text',
optional: true,
},
],
mode: 'payment',
shipping_address_collection: {
allowed_countries: ['AT', 'DE', 'CH'],
},
allow_promotion_codes: true,
shipping_options: [
{
shipping_rate: 'shr_1PXUBaLp35uAW4ekj0MA8cVz',
},
],
success_url: `${req.headers.origin}/success`,
cancel_url: `${req.headers.origin}/get-started`,
metadata: {
reference: referenceText,
},
});
console.log('Checkout session created:', session.id);
res.status(200).json({ id: session.id });
} catch (err) {
console.error('Error creating checkout session:', err);
res.status(500).json({ error: err.message });
}
} else {
res.setHeader('Allow', 'POST');
res.status(405).end('Method Not Allowed');
}
}
这是我在 Stripe 日志中看到的响应。所以付款方式应该在那里。但他们不是:
{
"id": "cs_live_b1r0b1liKGrMcWBoga8ydq6cIUjJdSnwQQs7Wn4OEV97HiS3sH0TVikavn",
"object": "checkout.session",
"after_expiration": null,
"allow_promotion_codes": true,
"amount_subtotal": 3400,
"amount_total": 3695,
"automatic_tax": {
"enabled": false,
"liability": null,
"status": null
},
"billing_address_collection": null,
"cancel_url": "https://www.meineschnitten.at/get-started",
"client_reference_id": null,
"client_secret": null,
"consent": null,
"consent_collection": null,
"created": 1722118002,
"currency": "eur",
"currency_conversion": null,
"custom_fields": [
{
"key": "Notes",
"label": {
"custom": "Nachricht an Meine Schnitten",
"type": "custom"
},
"optional": true,
"text": {
"default_value": null,
"maximum_length": null,
"minimum_length": null,
"value": null
},
"type": "text"
}
],
"custom_text": {
"after_submit": null,
"shipping_address": null,
"submit": null,
"terms_of_service_acceptance": null
},
"customer": null,
"customer_creation": "if_required",
"customer_details": null,
"customer_email": null,
"expires_at": 1722204402,
"invoice": null,
"invoice_creation": {
"enabled": false,
"invoice_data": {
"account_tax_ids": null,
"custom_fields": null,
"description": null,
"footer": null,
"issuer": null,
"metadata": {
},
"rendering_options": null
}
},
"livemode": true,
"locale": null,
"metadata": {
"reference": "fsd-fc4d1fd4-7952-4f51-b981-17cf000cc30c"
},
"mode": "payment",
"payment_intent": null,
"payment_link": null,
"payment_method_collection": "if_required",
"payment_method_configuration_details": null,
"payment_method_options": {
"card": {
"request_three_d_secure": "automatic"
}
},
"payment_method_types": [
"card",
"paypal",
"eps"
],
"payment_status": "unpaid",
"phone_number_collection": {
"enabled": false
},
"recovered_from": null,
"saved_payment_method_options": null,
"setup_intent": null,
"shipping_address_collection": {
"allowed_countries": [
"AT",
"DE",
"CH"
]
},
"shipping_cost": {
"amount_subtotal": 295,
"amount_tax": 0,
"amount_total": 295,
"shipping_rate": "shr_1PXUBaLp35uAW4ekj0MA8cVz"
},
"shipping_details": null,
"shipping_options": [
{
"shipping_amount": 295,
"shipping_rate": "shr_1PXUBaLp35uAW4ekj0MA8cVz"
}
],
"status": "open",
"submit_type": null,
"subscription": null,
"success_url": "https://www.meineschnitten.at/success",
"total_details": {
"amount_discount": 0,
"amount_shipping": 295,
"amount_tax": 0
},
"ui_mode": "hosted",
"url": "https://checkout.stripe.com/c/pay/cs_live_b1r0b1liKGrMcWBoga8ydq6cIUjJdSnwQQs7Wn4OEV97HiS3sH0TVikavn#fidkdWxOYHwnPyd1blppbHNgWjA0SHIxR0xJdTYwcERSMWBuY0lLQnNQZGYxZ3F2N2NPQUJRd1FScH1fMWdPZlc2bHFDa0xPQ3JLcVBWNVZXMXQ1dnBIRlBPf05yclx9UnJEXDViV2lfb3NANTV2RmthMmRQdycpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8dWAnPydocGlxbFpscWBoJyknYGtkZ2lgVWlkZmBtamlhYHd2Jz9xd3BgeCUl"
}
我咨询了客服,但客服并没有真正提供帮助。我从自动付款方式(您无需在代码中指定而是在仪表板中指定)切换为手动付款方式。两者产生相同的结果。我只是想让客户 100% 能够通过某种付款方式结账。
首先,您正在测试实时模式密钥,因此它创建了一个实时模式结账会话。请改用测试模式。
每个结账时段仅在 24 小时内有效。您可能希望生成一个新的测试模式结帐会话,并尽快与 Stripe 支持人员共享其 URL,以便他们可以在其过期窗口内进行调查。 还有几个问题可以加快调查速度:
在测试模式下是否会发生这种情况?