Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Stripe doesn't believe client_secret is created with my account

$
0
0

I'm attempting to setup stripe connect payments on svelte-kit, however stripe keeps returning an error:

The client_secret provided does not match any associated PaymentIntent on this account. Ensure the publishable key used belongs to the same account that created the PaymentIntent.

I've triple-checked that the client secret was created with the matching secret key to my public key, I've also attempted to try a sandbox account instead of a test environment and still get the same error.

This is the sever code for generating a client_secret:

import { SECRET_STRIPE_KEY } from '$env/static/private';const stripe = new Stripe(SECRET_STRIPE_KEY, {    apiVersion: "2024-11-20.acacia" as "2024-10-28.acacia", // This is a type assertion});export async function GET() {    const ticket_price = 45;    const application_fee = 1;    const paymentIntent = await stripe.paymentIntents.create({        amount: ticket_price,        currency: 'gbp',        application_fee_amount: application_fee,        automatic_payment_methods: {            enabled: true        }    }, {        stripeAccount: 'acct_1QWcgoDArWfcz7re',    });    return json({        clientSecret: paymentIntent.client_secret    }, { status: 200 });}

This is the part of the client side that uses svelte-stipe and stripe-js to create a payment form:

<script lang="ts">    import { onMount } from 'svelte';    import { loadStripe } from '@stripe/stripe-js'    import type { Stripe, StripeElements } from '@stripe/stripe-js'    import { Elements, PaymentElement, LinkAuthenticationElement, Address } from 'svelte-stripe'    import { PUBLIC_STRIPE_KEY } from '$env/static/public';    let stripe: null | Stripe = null    let clientSecret : null | string = null    let elements: StripeElements | null | undefined    let processing = false    onMount(async () => {        stripe = await loadStripe(PUBLIC_STRIPE_KEY, { apiVersion: "2024-11-20.acacia" as "2024-10-28.acacia" })        clientSecret = await createPaymentIntent()    })    async function createPaymentIntent() {        const response = await fetch('/api/stripe/payment', {            method: 'GET',            headers: {'content-type': 'application/json'            }        })        const { clientSecret } = await response.json()        return clientSecret    }    async function submit() {        // ...    }</script>{#if clientSecret !== null}<Elements        {stripe}        {clientSecret}        theme="flat"        labels="floating"        bind:elements><form on:submit|preventDefault={submit}><LinkAuthenticationElement /><PaymentElement /><Address mode="billing" /><button disabled={processing}>            {#if processing}            Processing...            {:else}            Pay            {/if}</button></form></Elements>{:else}    Loading...{/if}

At first, I thought it might be an issue with stripe-svelte, however while looking at the network request all the parameters are correct. I triple-checked the key and also the client_secret, so is it just a Stripe issue?

https://api.stripe.com/v1/elements/sessions?client_secret=pi_3QWcxADArWfcz7re023mkEqp_secret_mHQ6ErNxsy61qqAAp57FD1rIT&key=pk_test_69buoGS6vl82TpptRDix1WEr00LnbLWpxw&_stripe_version=2024-11-20.acacia&type=payment_intent&locale=en-US&referrer_host=localhost:5173&expand[0]=payment_method_preference.payment_intent.payment_method&stripe_js_id=bb0bb448-9ebf-46c9-b6e5-77e60c7f4016client_secret=pi_3QWcxADArWfcz7re023mkEqp_secret_mHQ6ErNxsy61qqAAp57FD1rITkey=pk_test_69buoGS6vl82TpptRDix1WEr00LnbLWpxw

Here is the error response from stripe:

{"error": {"message": "The client_secret provided does not match any associated PaymentIntent on this account. Ensure the publishable key used belongs to the same account that created the PaymentIntent.","param": "client_secret","request_log_url": "https://dashboard.stripe.com/test/logs/req_Gf29tN9FjPAYJe?t=1734350353","type": "invalid_request_error"  }}

Checking the Stripe logs, you can see the failed request, but not the request to create the client secret.

stripe logs

Update

I removed the "stripeAccount" from the paymentIntent creation and it now doesn't show the error however it now doesn't work as a connected payment so I'm assuming i have to use the secret and public of the connected stripe account?


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>