#zee_code

1 messages ยท Page 1 of 1 (latest)

sick boughBOT
#

๐Ÿ‘‹ 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.

hybrid mango
#

            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}");
      }

  }
void trailBOT
hybrid mango
autumn nymph
#

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.

hybrid mango
#

yeah its the error in my screenshot

autumn nymph
#

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?

hybrid mango
#

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

autumn nymph
#

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.

hybrid mango
#

it gave this

autumn nymph
#

I'm not sure what you're showing me.

#

But a response code of 200 doesn't seem to be what your frontend code is expecting.

#

Though I'm not sure if the Responses or Server response section indicates how your server responded.