#meldin-checkout-coupon

1 messages · Page 1 of 1 (latest)

muted havenBOT
nova canyon
#

What are you expecting to happen, exactly, since only one discount can be used? Can you share a concrete test mode example we can look at, and explain what you'd expect to happen vs what you see actually happening?

vagrant prairie
#

Thank you for your response! I apologize for any confusion caused. Let me provide more clarity on the issue. Currently, when a user adds multiple products to their cart, each product has its own unique coupon discount associated with it. Ideally, during the checkout process, I would expect the system to apply the respective coupon discounts to the total price of each product, rather than just the subtotal price.

Here's a concrete test mode example: Let's say the user adds Product A with a coupon discount of 10% and Product B with a coupon discount of $5. When they proceed to the checkout page, I would expect the system to calculate the total price for each product, apply the relevant coupon discount, and then sum up the discounted prices to generate the final total price for the entire order.

However, the current behavior is that only the coupon discount from the last added product is being applied to the subtotal price, ignoring the discounts for other products. As a result, the final total price reflects only the discount from the last added product, rather than considering the discounts for all products in the order.

I hope this explanation clarifies the issue. If there are any further details or examples needed to help address the problem, please let me know. I greatly appreciate your assistance!

nova canyon
vagrant prairie
#

"I have discounts = [{coupon: coupon_id}] on the backend And I know that only one coupon can be added on the checkout page

nova canyon
#

Ok, so what are you look at specifically where you see the unexpected result then?

vagrant prairie
#

The problem I'm trying to solve involves different discounts for each item in the cart. Let's consider the following scenario:

Headphones are priced at $10 with a 10% discount.
Earphones are priced at $20 with a 20% discount.
Speakers are priced at $100 with a 50% discount.
Ideally, on the checkout page, I want the discounts to be applied correctly to each item, resulting in the following prices:

Headphones: $10 - 10% discount = $9
Earphones: $20 - 20% discount = $18
Speakers: $100 - 50% discount = $50
The total price of all items combined would then be $9 + $18 + $50 = $77.

However, in the current implementation, only the discount of the last added item (in this case, the speakers) is applied to the subtotal. Consequently, the subtotal is $130 (the sum of all item prices) minus a 50% discount, resulting in $65.

nova canyon
#

Ok but I mean, can you share an actual Stripe object you're inspecting where you expect one result but get another?

vagrant prairie
#

// Check if the coupon exists and is valid
const discounts = [];
if (productDiscount) {
try {
const coupon = await stripe.coupons.retrieve(productDiscount);
console.log("Retrieved coupon:", coupon); // Log the coupon object for inspection

if (coupon.valid) {
  discounts.push({ coupon: coupon.id });
} else {
  discounts.length = 0;
  productDiscount = "";
}

} catch (error) {
console.log("Coupon retrieval error:", error);
discounts.length = 0;
}
}

nova canyon
#

And what is the result you see?

vagrant prairie
#

I see only one coupon of the last product added to the checout page applied to the subtotal price

nova canyon
#

Can you show me a specific Stripe object you're looking at? Payment Intent ID? Checkout Session ID? An invoice?

vagrant prairie
#

const checkoutSession =
await stripe.checkout.sessions.create(
params,
);

#

in params there is discounts = [{coupon:coupon_id}]

muted havenBOT
vagrant prairie
#

I belive ther should be something else to retrive discounts here insted of coupons: const coupon = await stripe.coupons.retrieve(productDiscount);

nova canyon
#

What is the checkout session ID you're looking at as an example here? eg cs_test_123

#

If you're trying to apply multiple discounts when creating the session, that's not supported

#

Is that the misunderstanding or mismatched expectation here?

strong field
#

meldin-checkout-coupon

vagrant prairie
#

I agree that ionly one coupon can be applied. Do you have any suggestion how to solve the problem

#

After creating the checout session then I am just sending checkout session url