I cant seem to solve this error
Credit.cshtml
<form action="@Url.Action("Charge", "Home")" method="POST">
<article>
<label>Amount: $5.00</label>
</article>
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_6pRNASCoBOKtIshFeQd4XMUh"
data-amount="1000"
data-name="My Project Name"
data-description="Premium Account (€10)"
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-locale="auto"
data-zip-code="true"
data-currency="eur">
</script>
</form>
HomeController
[HttpPost]
//Parameters can contain stripeToken, stripeEmail, stripeName, stripeAddress submitted from Credit.cshtml form
public ActionResult Charge(string stripeToken, string stripeEmail)
{
Debug.WriteLine("stripe token is " + stripeToken);
Debug.WriteLine("stripe email is " + stripeEmail);
StripeConfiguration.SetApiKey("<!-- my secret key -->");
//Take the token submitted by the form
var token = stripeToken;
//Charge to the user card
var charges = new StripeChargeService();
var charge = charges.Create(new StripeChargeCreateOptions
{
Amount = 1000,
Currency = "sgd",
Description = "Example charge",
SourceTokenOrExistingSourceId = token
});
return View();
}
An exception of type 'Stripe.StripeException' occurred in Stripe.net.dll but was not handled in user code No such token: tok_1BYf3F2eZvKYlo2C0MJgUKKD
What is happening? Some help pleasee thankss
A "no such token" error generally happens when the token you are trying to charge does not match the account you are making the API call on.
I'd recommend double checking the API keys that you're using, make sure the publishable key on your front-end and secret key in your back-end belong to the same account.
If switching up API Keys doesn't resolve it, you'd want to get in touch with Stripe, their support can look up the token id and tell you why it's not working!