Skip to content

The PaymentIntent requires a payment method #644

@raysefo

Description

@raysefo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions