#_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1300907875077722142
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
I don't think you can add negative amount line items in a checkout session ๐ค
Let me see if there's a workaround
thank you. so far, we have this whole process without importing all our product to stripe. we set up the cart on the fly per transaction.
We have implemented most of this :
just coupons and gift certificates now. which really, just need a place to apply and show the discounted amount, with a reference to the code used sent back to us
Gotcha. Unfortunately, there's no workaround to pass negative items to the checkout session.
The only way to provide discounts using Checkout Sessions is to use promo codes/coupons created on Stripe
is there a beta feature or something ? i was looking at this thing
not sure if it would apply
I don't think there's beta that works for this. One approach you could take is, when the customer applies a coupon/certificate on your site, you can call Stripe API to create a coupon/promo code on Stripe - https://docs.stripe.com/api/coupons/create | https://docs.stripe.com/api/promotion_codes/create
and then prefill/pre-apply it on checkout creation by passing them through discounts - https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-discounts
hmm. so like a pre-created coupon of fixed amount ?
correct
that could work. is there a way to ensure they can only be applied via the api ?
(eg, don't want a bunch of coupons created, then someone come along and use one)
You can create coupons that are single use - https://docs.stripe.com/api/coupons/create
or set a redeem_by date - https://docs.stripe.com/api/coupons/create#create_coupon-redeem_by
This is the hashing I am using for creating a line item (roughly, this shows an attempt for coupon code entry at 0$)
// create a line item for stripe checkout
formParams["line_items[#itemIndex#][price_data][currency]"] = "usd";
formParams["line_items[#itemIndex#][price_data][product_data][name]"] = "COUPON: #discountCode#";
formParams["line_items[#itemIndex#][price_data][unit_amount]"] = 0;
formParams["line_items[#itemIndex#][quantity]"] = 1;
Or create a promo code that can only be used by that specific customer - https://docs.stripe.com/api/promotion_codes/create
we have to do everything manually since coldfusion is not really supported.
single use isn't the problem, it is if the user aborts the cart. my concern here, is user creates a cart, and aborts --- and ends up with dozens of coupons since the amounts will be different.
One option would be to delete the coupon if the cart is abandoned
that specific customer doesn't exist in your system yet
ok, if the coupon can not be applied by typing a code in stripe, then it should be fine.
๐
could you provide an example like this on how I would set a stripe coupon to our cart -- not on an item
// create a line item for stripe checkout
line_items[0][price_data][currency] = "usd";
line_items[0][price_data][product_data][name] = "COUPON: #discountCode#";
line_items[0][price_data][unit_amount] = 0;
line_items[0][quantity] = 1;
My test request was in stripe-node with following body:
options = ({
line_items: [
{
price_data: {
unit_amount: 10000,
currency: 'usd',
product_data: {
name: 'test'
},
},
quantity: 1
}
],
discounts: [
{
coupon: 'me9ftfRt'
}
],
success_url: url,
mode: 'payment'
})
so it's a separate thing
so discounts would look like
discounts[0][coupon]="xxxx"
^ ya. thank you
thank you so much ๐
We have step by step guides in case you need it later - https://docs.stripe.com/payments/checkout/discounts?lang=curl
last question, a bit unrelated.
Sure
would you happen to know a rough eta on when google pay/apple pay/link/etc one-click checkouts will be enabled for the beta feature for custom shipping
Unfortunately, not. My team doesn't familiarize much beta features so we don't keep upto date on that. I would suggest you reach out to our support about that
https://support.stripe.com/?contact=true