Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The PaymentIntent requires a payment method #644

Open
raysefo opened this issue May 29, 2024 · 0 comments
Open

The PaymentIntent requires a payment method #644

raysefo opened this issue May 29, 2024 · 0 comments

Comments

@raysefo
Copy link

raysefo commented May 29, 2024

Bug report

I am trying to use stripe hosted page in my Blazor WASM application. I have a test account.

Describe the bug

The problem is I am getting this error and can't reach the stripe-hosted page. There is no error on the browser console.

Firefox_Screenshot_2024-05-29T12-43-29 042Z

To Reproduce

Here is the code I am using;

[HttpPost]
[Authorize]
[ActionName("Create")]
public async Task<IActionResult> Create([FromBody] StripePaymentDTO paymentDTO)
{
    try
    {

        var domain = _configuration.GetValue<string>("Client_URL");

        var options = new SessionCreateOptions
        {
            SuccessUrl = domain+paymentDTO.SuccessUrl,
            CancelUrl = domain+paymentDTO.CancelUrl,
            LineItems = new List<SessionLineItemOptions>(),
            Mode = "payment",
            PaymentMethodTypes = new List<string> { "card" }
        };


        foreach (var item in paymentDTO.Order.OrderDetails)
        {
            var sessionLineItem = new SessionLineItemOptions
            {
                PriceData = new SessionLineItemPriceDataOptions
                {
                    UnitAmount = (long)(item.Price*100), //20.00 -> 2000
                    Currency="usd",
                    ProductData= new SessionLineItemPriceDataProductDataOptions
                    {
                        Name= item.Product.Name
                    }
                },
                Quantity= item.Count
            };
            options.LineItems.Add(sessionLineItem);
        }

        var service = new SessionService();
        Session session = service.Create(options);
        return Ok(new SuccessModelDTO()
        {
            Data = session.Id+";"+session.PaymentIntentId
        }) ;
    }
    catch (Exception ex)
    {
        return BadRequest(new ErrorModelDTO()
        {
            ErrorMessage = ex.Message
        });
    }
}

And here is how I am calling the API:

public async Task<SuccessModelDTO> Checkout(StripePaymentDTO model)
{
    try
    {
        var content = JsonConvert.SerializeObject(model);
        var bodyContent = new StringContent(content, Encoding.UTF8, "application/json");
        var response = await _httpClient.PostAsync("api/stripepayment/create", bodyContent);
        string responseResult = response.Content.ReadAsStringAsync().Result;
        if (response.IsSuccessStatusCode)
        {
            var result = JsonConvert.DeserializeObject<SuccessModelDTO>(responseResult);
            return result;
        }
        else
        {
            var errorModel = JsonConvert.DeserializeObject<ErrorModelDTO>(responseResult);
            throw new Exception(errorModel.ErrorMessage);
        }
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
}

I tried with the latest Stripe version and an older one but I am getting the same error. I also created a new test account and used the secret and publishable keys but no luck!

Expected behavior

Supposed to get the stripe-hosted page like the one below but unfortunately, I am getting the error I mentioned.

stripe succedd

System information

  • OS: Windows 10
  • Browser (if applies) [FF 118, Edge 125]
  • Server environment [.net core Blazor]

Here is the Stripe dashboard:
requires payment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant