#zee_code
1 messages ยท Page 1 of 1 (latest)
๐ 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/1304180668841857156
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- zee_code, 16 hours ago, 27 messages
var domain = "https://localhost:7186";
var options = new SessionCreateOptions
{
PaymentMethodTypes = new List<string> { "card" },
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
PriceData = new SessionLineItemPriceDataOptions
{
Currency = model.Currency,
ProductData = new SessionLineItemPriceDataProductDataOptions
{
Name = model.ProductName,
Description = model.ProductDescription,
},
UnitAmount = model.Amount,
},
Quantity = 1,
},
},
Mode = "payment",
SuccessUrl = domain + "/success.html",
CancelUrl = domain + "/cancel.html",
};
var service = new SessionService();
Session session = service.Create(options);
Response.Headers.Add("Location", session.Url);
return new StatusCodeResult(303);
private async void ProceedToPaymentButton_Click(object sender, RoutedEventArgs e)
{
try
{
using var client = new HttpClient();
client.BaseAddress = new Uri("https://localhost:7186"); // Adjust port as necessary
// Create the payment request object
var paymentRequest = new PaymentRequest
{
Currency = "usd", // Replace with dynamic value if needed
ProductName = $"Flight {FlightOffer.FlightNumber}",
ProductDescription = "Economy class flight ticket",
Amount = (long)Convert.ToDouble(FlightOffer.Price)*100 // Convert price to cents
};
// Serialize the request body as JSON
var content = new StringContent(
Newtonsoft.Json.JsonConvert.SerializeObject(paymentRequest),
Encoding.UTF8,
"application/json"
);
// Send the POST request
var response = await client.PostAsync("/create-checkout-session", content);
if (response.StatusCode == System.Net.HttpStatusCode.SeeOther)
{
// Get the redirect URL from the Location header
var sessionUrl = response.Headers.Location?.ToString();
if (!string.IsNullOrEmpty(sessionUrl))
{
// Open the Stripe checkout page in the default browser
Process.Start(new ProcessStartInfo
{
FileName = sessionUrl,
UseShellExecute = true
});
}
else
{
MessageBox.Show("Failed to retrieve the Stripe session URL.");
}
}
else
{
MessageBox.Show($"Payment initiation failed: {response.StatusCode}");
}
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred: {ex.Message}");
}
}
https://docs.stripe.com/checkout/quickstart
this was the code I followed
Hi there ๐ can you tell me more about the error you're encountering? If it's the one in your sceenshot, that seems to be getting thrown by your code that you shared.
yeah its the error in my screenshot
Yeah, that seems to be getting thrown by your code:
{
MessageBox.Show($"Payment initiation failed: {response.StatusCode}");
}```
Do you see any logs about the request you're making to your backend that may provide insight on what is going on there?
nope sorry
when I run it in swagger I get this message
sorry that was wrong I did not set the currency
I will try again now
I'd suggest adding logging to get those details then. Right now it seems like the request from your frontend to your backend isn't completing as expected. Without more insight into why I'm not too sure what to suggest.