mxstgr
mxstgr

Reputation: 1

Stripe Checkout page not showing payment methods at all

I implemented stripe on my website that runs on Vercel, NodeJS, React.

I specify the payment methods in my code. And half of the times it works and I can checkout with credit card, Apple Pay and PayPal. But other times those are just not displayed at all. Shown in the pictures. Or you can see for yourself with this checkout link: https://checkout.stripe.com/c/pay/cs_live_b1r0b1liKGrMcWBoga8ydq6cIUjJdSnwQQs7Wn4OEV97HiS3sH0TVikavn#fidkdWxOYHwnPyd1blppbHNgWjA0SHIxR0xJdTYwcERSMWBuY0lLQnNQZGYxZ3F2N2NPQUJRd1FScH1fMWdPZlc2bHFDa0xPQ3JLcVBWNVZXMXQ1dnBIRlBPf05yclx9UnJEXDViV2lfb3NANTV2RmthMmRQdycpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8dWAnPydocGlxbFpscWBoJyknYGtkZ2lgVWlkZmBtamlhYHd2Jz9xd3BgeCUl

This is the code where I create the stripe checkout page:

// 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');
  }
}

And this is the response I can see in the Stripe logs. So the payment methods should be there. But they are not:

Checkout with payment methods

Checkout with payment methods not working

{
  "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"
}

I consulted the customer service, who did not really help. I switched from the automatic payment methods, where you don't specify them in the code, but in the dashboard, to the manual one. Both yielding the same results. I just want to make the customers able to checkout with some payment method 100% of the time.

Upvotes: 0

Views: 408

Answers (1)

orakaro
orakaro

Reputation: 1991

First you are testing on a Live mode Secret key, so it created a Live mode Checkout Session. Please use Test mode instead.

Each Checkout Session is only valid for 24 hours. You would want to generate a new Test mode Checkout Session and share its URL with Stripe Support as soon as possible, so they can investigate within its expiration window.

A couple more question to speed up the investigation:

  • Does it happen in Test mode at all?
  • Are there specific conditions that you can trigger it?
  • A displayable URL of Test mode within 24 hours as mentioned above.

Good luck!

Upvotes: 0

Related Questions