#Ninja man-coupons
1 messages ยท Page 1 of 1 (latest)
Through the API you can set applies_to.products when you create a Coupon (https://stripe.com/docs/api/coupons/create?event_types-payment_intent.payment_failed#create_coupon-applies_to-products) which allows you to specify which products a coupon applies to.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Hmm well i just want to add products, and if there is 3 products, then apply a 10% discount to the total price etc
You understand what i mean
Are you asking how to guarantee that a certain price is always discounted 10%? What are you using to collect payments? Checkout?
No, i want to be able to add like a field to the checkout, like discount: 10% . So when i call this i would just want to specify a discount on the whole price
Ahhh gotcha - you just want to be able to discount the full cost of a Checkout Session by 10%?
Yep
And do you want this to be like a Promotion code that your customers will enter in the Checkout Session UI, or is this something you want to set when the checkout session is created?
So basically it will work like this:
You add 2 products, then it says, "add 1 more to get a 10% discount on everything" So i want to be able to just set a discount value dynamically.
And if they add 10 products, then they would get 30% discount on everything.
Yeah you get it..
perfect - so you can control this by setting discounts.coupon when you create the Checkout Session, and you can see the APi reference for creating a coupon here (https://stripe.com/docs/api/coupons/create)
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Ahhhh cool! So: I make request to my server, i create that coupon, and then i start the checkout session, and i should pass the coupon, but where do i get the coupon from after i created it?
It depends on your integration - if you only need a couple of coupons, then your server could have logic to check how many items are going to be added to the session and hardcode which coupon IDs correspond to the number of items
Alright, is it some way to pre make coupons in the dashboard, and then check in the code like (if 3 items then use this coupon) etc?
Hi there ๐ taking over for @grizzled sequoia
You can create coupons in the dashboard here: https://dashboard.stripe.com/test/coupons
As for the logic required to check for the items, you would need to perform the check before the API call and then either apply the coupon or not. That should be totally doable
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Yeah so what about this: I send up all product ids the customer have added to the cart and then the server counts them, and then grab the coupon that is for x amount of products?
That seems like a reasonable way to go. You would want to make sure to store something in your coupon (either via metadata or as a naming convention) in order to make sure you're applying the correct coupon.
For example metadata: {product_total: 1} for the coupon that will only apply to single product orders, then metadata: {product_total: 2} for the coupon that will only apply to 2-product orders, etc.
Ahhh okay perfect. And just to make sure, the coupon stuff works for subscriptions right?
Yup!
Ohh great! I think I will write a few articles about all this once I have made it to help others that wanna implement something similar!