#Suzz
1 messages · Page 1 of 1 (latest)
i'm using a custom pricing table view suing the react fe and using a checkout asp.net api. in that i'm creating the checkout session
var options = new SessionCreateOptions
{
PaymentMethodTypes = new List<string> { "card" },
SuccessUrl = $"{_baseUrl}/success.html?session_id={{CHECKOUT_SESSION_ID}}",
CancelUrl = $"{_baseUrl}/canceled.html",
Mode = "subscription",
LineItems = new List<SessionLineItemOptions>
{
new()
{
Price = paymentRequest.PriceId,
Quantity = 1
}
}
};
var session = await service.CreateAsync(options);
Great, thanks!
on the success of the message i'm using another api to go to customer-portal
var options = new Stripe.BillingPortal.SessionCreateOptions
{
Customer = checkoutSession.CustomerId,
ReturnUrl = _baseUrl
};
var service = new Stripe.BillingPortal.SessionService(_client);
var session = await service.CreateAsync(options);
So let me get this straight. You only want a single Subscription for a Customer record?
So do you know who the Customer is at the time you generate the Checkout Session?
Do you have any sort of authentication system that identifies who your user is when they are on your site?
Before you create the checkout session
var list = await new CustomerService().ListAsync(new CustomerListOptions
{
Email = user.Email
});
var options = new SessionCreateOptions
{
PaymentMethodTypes = new List<string> { "card" },
SuccessUrl = $"{_baseUrl}/success.html?session_id={{CHECKOUT_SESSION_ID}}",
CancelUrl = $"{_baseUrl}/canceled.html",
Mode = "subscription",
LineItems = new List<SessionLineItemOptions>
{
new()
{
Price = paymentRequest.PriceId,
Quantity = 1
}
}
};
if (!list.Any())
options.CustomerEmail = user.Email;
else
options.Customer = list.First().Id;
var service = new SessionService(_client);
var session = await service.CreateAsync(options);
Console.WriteLine(session.Url);
this is the complete code
i've setup jwt bearer token
The idea is that you would check wether a Subscription already exists before you create a new Subscription
yes, i already configured it
the code
And why is that not doing what you want?
once the user subscribed how will i know?
At what point?
are there any apis to get the subscribed user?
Sure there are webhook events
on the second login or right after the subscription
my webhook
You can listen to the customer.subscription.created event
ok
But I'm still unclear on why you can't first look up whether a Customer has an active Subscription before you create the checkout session
https://stripe.com/docs/api/subscriptions/list#list_subscriptions-customer
The error message says you are using an expired API key. You should update your API key