#ruul_code
1 messages · Page 1 of 1 (latest)
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- ruul_code, 6 days ago, 25 messages
👋 Welcome to your new thread!
⏲️ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can 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/1260187363079098438
📝 Have more to share? Add details, code, screenshots, videos, etc. below.
(also a seperate question I hope this is ok, when a coupon is deleted do promo codes referring to that coupon also get deleted? I need this for stripe flow tests)
is it legal?
Depends on the terms/conditions of your subscription/service really. Nothing we'd know anything about
will it work as intended (will it switch them to the new pricing after the current period end)?
Yes, you can upgrade at a specific time: https://docs.stripe.com/billing/subscriptions/subscription-schedules/use-cases#upgrading-subscriptions
I don't believe they're deleted no, they'd just be marked as inactive: https://docs.stripe.com/api/promotion_codes/object#promotion_code_object-active
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
in several tests I create a coupon & a promo code for them
but when I rerun the tests
An active promotion code with code: VALIDPROMO1 already exist
do I need to mark them inactive instead ?
What tests are you running? What do the tests do?
for example
await insertSubscriptionTypes();
const userId = await createSocialUserTest({
email: "useremail@domain.com",
firstName: "John",
lastName: "Doe",
googleId: "1234567890",
});
const testClock = await createTestClock();
const customer = await createTestCustomer(testClock);
await teamsCollection.updateOne(
{ ownerId: userId },
{ $set: { stripeCustomerId: customer.id } }
);
const paymentMethods = await userPaymentService.getCards({}, userId);
const paymentMethodId = paymentMethods.cards[0].id;
const coupon = await paymentService.stripe.coupons.create({
duration: 'once',
percent_off: 50,
metadata: {
test: "test"
},
});
const promoCode = await paymentService.stripe.promotionCodes.create({
coupon: coupon.id,
code: "VALIDPROMOTEST",
metadata: {
test: "test"
},
});
expect(promoCode.active).toBe(true);
const subscriptionType = await subscriptionTypesCollection.findOne({
title: SubscriptionTypeTitle.BASIC,
});
await userPaymentService.purchaseSubscription(
{ paymentMethodId, subscriptionTypeId: subscriptionType._id, promocode: promoCode.code },
userId
);
const team = await teamsCollection.findOne({ ownerId: userId });
expect(team.stripeSubscriptionId).toBeTruthy();
const subscription = await paymentService.retrieveSubscription(
team.stripeSubscriptionId
);
expect(subscription.items.data[0].price.id).toBe(subscriptionType.stripePriceId);
const latestInvoice = await paymentService.stripe.invoices.retrieve(subscription.latest_invoice as string);
expect(latestInvoice.discount.coupon.id).toBe(coupon.id);
const updatedPromoCode = await paymentService.stripe.promotionCodes.retrieve(promoCode.id);
expect(updatedPromoCode.active).toBe(false);
await paymentService.stripe.coupons.del(coupon.id);
});```
hmm we are already setting it inactive after its use
but we can't recreate it with the same code
What's the actual error you get back from the API?
An active promotion code with `code: VALIDPROMO1` already exists.
at Function.generate (node_modules/stripe/cjs/Error.js:10:20)
at res.toJSON.then.Error_js_1.StripeAPIError.message (node_modules/stripe/cjs/RequestSender.js:105:54)```
it was VALIDPROMO1 before
I just changed it but didn't run the tests since I know it'll work once & won't work after that
I suspect you'll need to delete then yes
But how there’s no endpoint to delete them
Did you try updating and passing active: false?
yup
expect(updatedPromoCode.active).toBe(false); it's tested on this line
const info = await this.paymentService.getCouponIdFromPromoCode(promocode);
couponId = info.couponId;
promocodeId = info.promoCodeId;
}
const subscription = await this.paymentService.purchaseSubscriptionWithPaymentMethodPresent({
customer: team.stripeCustomerId,
price: subscriptionType.stripePriceId,
paymentMethodId,
quantity: 1,
coupon: couponId
});
if (promocodeId) {
await this.paymentService.setPromoCodeInactive(promocodeId);
}
for example
* Deactivates a promo code
* @param promoCodeId code id
* @returns promo code object
*/
public async setPromoCodeInactive(promoCodeId: string) {
return this.stripe.promotionCodes.update(promoCodeId, {
active: false,
});
}```
Then I guess what your test is trying to do isn't supported. You'll need to workaround that