#mangeshsm_webhooks

1 messages ¡ Page 1 of 1 (latest)

soft tangleBOT
#

👋 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/1298658013086875659

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

woeful owl
#

There ?

heavy finch
#

Hello, yes I am here. I am not sure if our coupons support that but am looking in to it

woeful owl
#

There i have book printing functionality and i want for single book it get free as per created coupon and for more than one book have to apply 25 % discount

heavy finch
#

Unfortunately the coupons in our API do not have a way to do that. They can be for an amount or a percentage off, but they don't have a way of changing based on quantity https://docs.stripe.com/api/coupons/create

#

Can you tell me more about your current setup? Are you using Stripe Checkout and if so are you using the functionality that allows users to adjust the quantity within the checkout session?

woeful owl
#

The sales page has added a $99 price for the sale purpose. I am using a Stripe Checkout button, and on the sales page, I added the button so that after the payment is completed, a coupon is created and emailed to the user.

When a user purchases a book from the checkout page, if they have one book, they need to apply the coupon to get that book for free. If they select two books, the first book will be free, and the second book will receive a 25% discount.

#

Nothing did with session

#

#waitingforreply

#

#counterstill

heavy finch
#

I get the structure of what you are selling and the discount, I am curious about how you are currently selling things through Stripe as that effects what you can do here

#

Also no need to ping in threads, we get to them as quickly as we can, sometimes volume and getting pulled to other things can mean a couple minute delay

woeful owl
#

I have a website where users can initially create their story for free. However, they need to pay to publish it. For that purpose, I have set a default fee of $99 to cover all expenses.

Once a user pays this amount, they can get one book for free. If they want to publish more than one book, they will need to pay an additional amount, but I have decided to offer a 25% discount on those extra books.

heavy finch
#

Can you send me your current Stripe code for creating a checkout session or payment intent, or whatever else you may use to represent payments for these books?

woeful owl
#

My question is very simple does strip has any option over dashboard or over API to manage this structure

#

const stripe = require('stripe')('your-secret-key');

async function createCheckoutSession(bookCount, couponCode) {
let lineItems = [];
let totalAmount = 0;

// Calculate the total amount based on the number of books
if (bookCount === 1) {
    totalAmount = 0; // Free book, coupon applies
    lineItems.push({
        price_data: {
            currency: 'usd',
            product: 'prod_id', // Replace with your product ID
            unit_amount: totalAmount,
        },
        quantity: 1,
    });
} else {
    totalAmount = (bookCount - 1) * 99 * 0.75; // 25% off for additional books
    lineItems.push({
        price_data: {
            currency: 'usd',
            product: 'prod_id',
            unit_amount: 99,
        },
        quantity: 1, // First book is free
    });
    lineItems.push({
        price_data: {
            currency: 'usd',
            product: 'prod_id',
            unit_amount: 99 * 0.75, // 25% discount on subsequent books
        },
        quantity: bookCount - 1, // Count for the remaining books
    });
}

// Create a checkout session
const session = await stripe.checkout.sessions.create({
    payment_method_types: ['card'],
    line_items: lineItems,
    mode: 'payment',
    discounts: couponCode ? [{ coupon: couponCode }] : [],
    success_url: 'https://your-website.com/success',
    cancel_url: 'https://your-website.com/cancel',
});

return session.url; // Return the checkout session URL

}

#

Like this possible ?

heavy finch
#

Ah if you are collecting the coupon code your self first that could work. Stripe's coupons don't support this kind of behavior but you can definitely create Checkout Sessions for whatever price as you are showing in that code

woeful owl
#

Thanks for this.
Will ping if i requird any help.
Have a great day ahead.