Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Stripe test token not working in test environment

I am trying to test my Stripe API code that confirms a PaymentIntent immediately. I verified that my stripe account is in Test Mode, that I am using the Test Key, and that I am using the test tokens specified by the stripe docs. However, no matter which test token I try I get an error message saying "No such confirmationtoken: ‘tok_visa’".

Here is the method I am testing

StripeConfiguration.ApiKey = apiKey;

var paymentIntentService = new PaymentIntentService();
paymentIntent = await paymentIntentService.CreateAsync(new PaymentIntentCreateOptions
{
    Confirm = true,
    ConfirmationToken = "tok_visa",
    Amount = 1200,
    Currency = "usd",
    AutomaticPaymentMethods = new PaymentIntentAutomaticPaymentMethodsOptions
    {
        Enabled = true,
        AllowRedirects = "never"
    },
});

Am I missing something here? I have re-read the docs and can’t find any reason why the code above shouldn’t work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The test value you’re trying to use (tok_visa) is a legacy test Token which represents a Visa test card. You should not be using this legacy value, as using Tokens and creating Charges directly has been deprecated.

The modern equivalent would be pm_card_visa, which represents a test Visa Payment Method.

However, there’s another issue: you’re trying to use tok_visa as a Confirmation Token, which is an entirely different concept/object. There are no special test mode values for Confirmation Tokens.

It sounds like you’re doing an entirely server-side operation with no client involved, so using a Confirmation Token doesn’t make sense. Instead, try setting the payment_method property on the Payment Intent to to pm_card_visa and see if that works as expected.

If there is a client involved, have a look at Stripe’s guide for finalizing payments on your server, which does involve Confirmation Tokens, but requires you to create them client-side before you confirm server-side.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading