#Suzz
1 messages · Page 1 of 1 (latest)
👋 happy to help
i've created a checkout form by follwing this example
https://github.com/stripe-samples/checkout-single-subscription/tree/main
would like to setup autopayment which follows this.
Do you mean a recurring payment?
yes
Just create a price on your product with as a recurring price
both recurring payment and the subscription are different?
so if i created like this, will the amount deducted from account automatically? will this do by the stripe?
you need your customer payment method before charge them automatically.
second recuring payment on which you can create subscription. the user will be charged agaisnt that subscription which is automatically charged.
i've created a product with two prices
like this
excellent now create subscription agaianst these prices. in checkout session
both the prices are recurring and bill will generate monthly
in backend i've done like this
[HttpPost("create-checkout")] [Consumes("application/json")] public async Task<IActionResult> CreateCheckoutSession(PaymentRequest paymentRequest) { var _baseUrl = $"{Request.Scheme}://{Request.Host}"; SessionCreateOptions options = new SessionCreateOptions { 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 service = new SessionService(_client); try { var session = await service.CreateAsync(options); Response.Headers.Add("Location", session.Url); return new StatusCodeResult(303); } catch (StripeException e) { Console.WriteLine(e.StripeError.Message); return BadRequest(new ErrorResponse { ErrorMessage = new ErrorMessage { Message = e.StripeError.Message, } }); } }
Please add those in ` x3
this is the subscription you meant right @timid summit
which means?
sorry, i didnt get that
You can do
``
``
Next is just to let the customer go through the checkout, and then you'll have a subscription connected to that price and customer
all these are enough, will the stripe debit the amount on the next month once i successfully finish the checkout?
Go through you Stripe settings, but yes, I belive the default is automatically charge each month
ok
and then you can define when you want to send out notifications etc
lemme share code example with you. that might helo you
ok, thankyou @timid summit
how can i do that?
in Stripe dashboard
try this
to create subscription on checkout
and sedn thsi checkout link to user . subscription will be start and user will be chagres automaticlalu
Hey, taking over here. Let me know if there's any follow-up Qs I can answer!
this can be done on test mode data right?
Not sure if you're able to send out notifications in test mode
ok
how will we get the subscription metadata?
That's for adding metadata. You can get the sub metadata when you retrieve a subscription
i should do that on the checkout api right? retrieve the subscription details and pass to the checkoutsession
so how will i get the details to get the subscription details in this api
@woven holly @timid summit
I recommend using a webhook for listening to subscriptions being created/updated
if (event.type === 'customer.subscription.created') {
const subscription = event.data.object as Stripe.Subscription;
const productId = subscription.items.data[0].plan.product;
const product = await stripe.products.retrieve(productId as string);
await enableToken(subscription.metadata.userId, product.name as SubscriptionPlan);
}
for example like this
yes i've setup the webhook, will update like this
can you explain more i wdint get it
but if i update the webhook, how will i get the details in the checkout api @woven holly ?
yes
webhook is the next step. first you need to chagre rightly your customer
@timid summit the code you shared have the subscription data. how will i get it to pass to the checkout api
i've added the webhook
Not sure what you mean, but the flow looks like this
Checkout with data > sub is created > listen to event > get subscription > do something
you dont need to get the subscription data. you only need to pass the priceId( recurring price) and set the mode = subscription while createing checkout .
and metadata i just a dictionary which is just any thing youwant to stroe in the object
in this attachment you just need to add priceID which is recurring price basically and create checkout just
you need to add "invoice.paid" event in the weebhook to lsitent
this is my webhook
yeah, i already added
SessionCreateOptions options = new SessionCreateOptions { 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, }, }, }; };
we listen to the webhook, is just to know what all actions are triggering right?
we listen to webhook to make changes in our system after succesfull payment.
to acuatally make all changes in our system after succesful payment we listen to webhook.
this is all ok. now what you need next br0?
what kind of changes can you please expalin a bit?
sure
for example offering a course A. you got the link of my course A. but you dont have any access to the course meterail it just a view for you.
now after you purchased my course and pay through stripe a webhook will triger and i will listen the webhook accoringly and check if the payment status is succeeded then i will add that user data in my database and in my system upon which he will be able to view the course and unlock all the meterial.
ok, got it
assume there is a flag (isPurchased) for that particular course . if user dont pay for it so will not able t access the course. after payment and i will listen the event in webhook and then set the (isPurchased) flag to true for the user. now on front end on the base of flag value i will show the content of locked course to my user
now clear brother?
sure i will