#sive_subscription-paymentintent

1 messages ยท Page 1 of 1 (latest)

safe wharfBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1291434755786674176

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

chrome kraken
#

client side

        let stripe;
    let elements;
    let paymentElement;
    let checkoutDialog = false;

    // Initialize Stripe Elements
    async function createCheckout() {
        stripe = await loadStripe(PUBLIC_STRIPE_KEY);
        const appearance = { theme: 'night' };
        const options = { layout: { type: 'tabs', defaultCollapsed: false } };

        elements = stripe.elements({ clientSecret, appearance });
        paymentElement = elements.create('payment', options);
        paymentElement.mount('#payment-element');
    }

    // Handle form submission and payment confirmation
    async function submitCheckout(event) {
        event.preventDefault(); // Prevent the default form submit

        if (!stripe || !elements) {
            console.error('Stripe has not been initialized');
            return;
        }

        // Call confirmPayment method from Stripe
        const { error, paymentIntent } = await stripe.confirmPayment({
            elements,
            confirmParams: {
                return_url: window.location.href // Optional redirect URL after successful payment
            }
        });

        if (error) {
            // Display error to the customer (e.g., insufficient funds)
            const errorMessage = document.getElementById('error-message');
            errorMessage.textContent = error.message;
        } else if (paymentIntent.status === 'succeeded') {
            // Payment succeeded, redirect to success page or show confirmation
            console.log('Payment succeeded!', paymentIntent);
            window.location.href = '/success'; // Redirect to success page
        }
    }
#

error

{
  "error": {
    "code": "payment_intent_unexpected_state",
    "doc_url": "https://stripe.com/docs/error-codes/payment-intent-unexpected-state",
    "message": "This PaymentIntent's payment_method could not be updated because it has a status of canceled. You may only update the payment_method of a PaymentIntent with one of the following statuses: requires_payment_method, requires_confirmation, requires_action.",
    "param": "payment_method",
    "payment_intent": {
      "id": "pi_3PcCYSJIHVF6tQpN0P26LCbe",
      "object": "payment_intent",
      "amount": 1500,
      "amount_details": {
        "tip": {
        }
      },
      "automatic_payment_methods": null,
      "canceled_at": 1720985333,
      "cancellation_reason": "void_invoice",
      "capture_method": "automatic",
      "client_secret": "pi_3PcCYSJIHVF6tQpN0P26LCbe_secret_Xc02dv2f59g9EdyRMPRVIEDrK",
      "confirmation_method": "automatic",
      "created": 1720902508,
      "currency": "usd",
      "description": "Subscription creation",
      "last_payment_error": null,
      "livemode": false,
      "next_action": null,
      "payment_method": null,
      "payment_method_configuration_details": null,
      "payment_method_types": [
        "card",
        "cashapp"
      ],
      "processing": null,
      "receipt_email": null,
      "setup_future_usage": "off_session",
      "shipping": null,
      "source": null,
      "status": "canceled"
    },
    "request_log_url": "https://dashboard.stripe.com/test/logs/req_NKohcXI6ZJ6gri?t=1727970948",
    "type": "invalid_request_error"
  }
}
west lintel
#

@chrome kraken you are likely mixing up certain things. The PaymentIntent that you are trying to use was canceled because it's from July and was deleted since
You need to create a new Subscription and then try that Subscription's latest Invoice's PaymentIntent

#

sive_subscription-paymentintent

chrome kraken
#

ahh i see, i accidentally hard coded a secret to return on the server side, you realized very fast because i was looking at the payment intent returned by the subscription and it was a valid status but this is a different payment intent id

west lintel
#

yeah it's not easy to debug when you have some hardcoded value you forgot about. It was easy for me to debug since with the request I could look up that PaymentIntent and see it was old ๐Ÿ™‚

chrome kraken
#

You may close this thread, thanks and props to your speedy reply