#cryptitis-promo-codes

1 messages ยท Page 1 of 1 (latest)

steep spire
digital yacht
#

Hello! I should also mention, the free trial subscription is added via the API after the stripe customer is first created

steep spire
#

Do you have a specific example of the code not working?

digital yacht
#

It's not code that is failing. I can show you screens

steep spire
#

Yeah screenshots would be great!

digital yacht
#

Ok, so here is the Coupon

#

And then when I try redeeming the coupon

#

I'm confused as to what is invalid about that order

steep spire
#

Do you mind sharing the promo code ID with me?

digital yacht
#

oh wait, sorry wrong one

#

This is correct promo_1KFQoJJpG0A5M9U9npe9V6pn

steep spire
#

Looking now!

digital yacht
#

TY!

digital yacht
#

This is the coupon. idk if it would help 0gJq77cG

steep spire
#

Sorry a bunch of people hopped on at once so juggling a few too many things - do you also have the Subscription ID that you tried to apply it to?

digital yacht
#

prod_KvDrZboh68iDNY this is the product ID

#

And no worries!

#

It shows the products being applied to the coupon

#

Unless you mean the actual active subscription object for the customer

#

?

steep spire
#

Yeah I mean the specific sub_xxx ID

digital yacht
#

Well it doesn't exist yet because the user starts with a free trial of the $15/month tier, isn't it a new subscription object if they switch to annual billing?

steep spire
#

No, it wouldn't be a new subscription - it would the same subscription that we update to the new price

digital yacht
#

Ahh I see, ok so here is a sub ID for a free trial user I just setup sub_1KGpfIJpG0A5M9U9KSmiKxUI

#

I want to be able to offer a promo code that only works one time when the user switches to annual billing

#

Is the coupon not working because the subscription is already active and it's not a NEW subscription?

#

The coupons seem to work though when the minimum amount is set to $0

steep spire
#

Is the coupon not working because the subscription is already active and it's not a NEW subscription?
Yes, my guess would be that specifying " first-time transactions" is not working because they are already on a trial at that point - I'm not sure why it's not working if you have a higher minimum values though, still checking on that

steep spire
#

Ah, I think I'm seeing the issue - still testing some things out

#

Your flow is that you want customers to be able to do this with the customer portal, right?

digital yacht
#

Yes, if possible. This is the code I use to setup a new customer and add subscription

#
    /**
     * Create stripe customer for app user
     * @param user
     * @return the stripe customer object
     */
    async createCustomer({email, first_name, last_name}: CreateStripeCustomerParams): Promise<Stripe.Customer> {
        const metadata: StripeCustomerMetadata = {
            environment: String(process.env.NODE_ENV)
        }

        return await this._client.customers.create({
            email,
            name: first_name + " " + last_name,
            metadata
        })
    }

    /**
     * Created a new subscription for the stripe customer ID with passed price ID
     * @param stripeCustomerId
     * @param priceId
     * @param options
     */
    async createSubscription({ stripeCustomerId, priceId, options }: CreateStripeSubscriptionParams): Promise<any> {
        return await this._client.subscriptions.create({
            ...options,
            customer: stripeCustomerId,
            items: [{
                price: priceId, // This will be the price ID of $15/month price
            }]
        })
    }
#

This is the code for retrieving the session

#
    /**
     * 
     * @param stripeCustomerId
     */
    async createBillingPortalSession(stripeCustomerId: string) {
        // Create new billing portal session and return.
        return await this._client.billingPortal.sessions.create({
            customer: stripeCustomerId,
            return_url: getAccountSubscriptionURL(),
        });
    }
#

I'm trying another route now of applying the discount directly and sending the user to a checkout session after clicking a button or w/e

    /**
     *
     * @param stripeCustomerId
     * @param priceId
     * @param coupon
     */
    async createCheckoutSession({ stripeCustomerId, priceId, coupon }: CreateStripeCheckoutSessionParams) {
        const discounts: Stripe.Checkout.SessionCreateParams.Discount[] = []
        if (coupon) discounts.push({ coupon })

        // Create new checkout session and apply the discount.
        return await this._client.checkout.sessions.create({
            customer: stripeCustomerId,
            line_items: [{
                price: priceId,
            }],
            discounts,
            success_url: getAccountSubscriptionURL(),
            cancel_url: getAccountSubscriptionURL(),
        });
    }
steep spire
#

Let me give a bit of context on why the promotion code is not working:

  • the customer portal currently doesn't work for promotion codes w/ a minimum order amount that are applied to subscription updates (which explains why it only works when you have a mininum order of 0)
  • i'm guessing the first time restriction is also not working correctly because we consider the first trialing invoice to be a "successful" charge
digital yacht
#

Ok, that makes sense from what I've observed.

#

I suppose I can write a little logic to detect if the user is still on their Trial and give them a checkout button to claim that discount

#

@steep spire so that worked, and I was able to add a subscription and discount it, however now I have two subscriptions. One for the trial with a month left and one for the paid annual one. Is there anyway to modify the existing subscription or do I need to delete it after the other one is successful?

steep spire
#

Give me one minute

echo finch
#

hey there, just stepping in for karbi who needs to step away (shortly), reading while you two chat ๐Ÿ™‚

steep spire
#

Just thinking through some options for how you can achieve what you want -

  • You could generate promotion codes (where the coupon still has the same product limitation) with max_redemption: 1 and create one for each customer.
  • when you redirect to the customer portal, you could introduce some extra code there to check on the customer's existing subscription to see whether or not they should be allowed to use a promotion code. If they are not, you can change the customer portal configuration (see https://stripe.com/docs/api/customer_portal/configurations/create#create_portal_configuration-features-subscription_update-default_allowed_updates) to not allow for promotion code updates in that session.
  • You technically could continue on with Checkout Sessions (which you just mentioned) - but as you noticed, it creates a whole new Subscription since Checkout Sessions don't cover Subscription updates. I wouldn't really suggest this flow since it'll result in the new subscription
digital yacht
#

Hmm ok, thank you @steep spire and hello @echo finch !

#

I will try that out. I'm also thinking I could try making another price point that is also $0 that is the "Trial" plan of the paid tier. Maybe that would not trigger the "existing subscriber" logic within the portal when trying to switch to a different price...

#

Or just have a separate product for each price (FREE, $15/month, $150/year). Is there any technical down the road I'd not want to do that other than need to know that the $15/mo and $150/yr are actually the same product?

steep spire
#

I believe the $0 price would still trigger the "existing subscriber" login within the portal since it would also create a $0 invoice

digital yacht
steep spire
#

Yeah that would be a great option if you want the coupon to only apply to one specific price

digital yacht
echo finch
#

Not really, since we recommend using separate products for different service tiers (eg Gold vs Silver plans), you're effectively considering your annual plan a distinct service.

digital yacht
#

That makes sense then and seems like a safe path

#

I will try that then. Thank you very much @steep spire and @echo finch for your help!

echo finch
#

Glad we were able to help! (Mostly @steep spire ๐ŸŽ‰ )