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.
>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.