#neha_api

1 messages ¡ Page 1 of 1 (latest)

mild sonnetBOT
placid graniteBOT
#

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.

mild sonnetBOT
#

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

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

placid graniteBOT
umbral ocean
#

hi again

#

here's what i'm trying to do (this is my own custom ui)

#

i want pending_if_incomplete because i don't want to authorize the user till payment goes through

#

but i also want them to be able to pass in a promo code

#

i understand that i can check the "pending_update" of the updated subscription to ensure it went through

#

but when/how do i pass the promo code?

#
          subscriptionId,
          {
            items: [{ id: subscription.items.data[0].id, price: nextPriceId }],
            proration_behavior: "always_invoice",
            payment_behavior: "pending_if_incomplete",
            proration_date: subscription.current_period_start,
            promotion_code: promoCodeId,
          },
        );```
plush river
#

hello! like what the error message mentions, you can't use pending_if_incomplete with promotion_code. There are limited attributes that pending_update supports.

If the pending_update feature doesn't support that attribute, you will need to implement the feature on your own to save the current subscription "setting" and be ready to rollback if the payment fails

umbral ocean
#

well i use the following webhooks to provision access:

subscription.created, subscription.updated, invoice.paid

and the following to restrict access:

subscription.deleted, invoice.payment_failed

#

if i omit "pending if incomplete"

#

it's possible that these webhooks would be called as if the subscription payment went through ?

#

(also, how does the customer portal handle this?)

plush river
#

you can test things out and see how it works. At the very least, subscription.updated will be called

umbral ocean
#

is there anything i can do with the subscription.invoice after i update the subscription ^

plush river
#

I'm not sure I understand? You need to let me know what do you want to do with it. I wouldn't know what you would want to do with it

umbral ocean
#

i just want the promo code to be applied to the invoice

#

if it can be

plush river
#

what has that got to do with the event?

umbral ocean
#

like could i do

          subscriptionId,
          {
            items: [{ id: subscription.items.data[0].id, price: nextPriceId }],
            proration_behavior: "always_invoice",
            payment_behavior: "pending_if_incomplete",
            proration_date: subscription.current_period_start,
          },
        );```

const invoice = getInvoice(newSusbcription.latestInvoiceId); // psuedo code
invoice.addPromoCode(promoCode);

#

or

plush river
#

okay, so if you try running that, what do you get?

umbral ocean
#

one sec

#

trying this

        const newSubscription = await this.stripe.subscriptions.update(
          subscriptionId,
          {
            items: [{ id: subscription.items.data[0].id, price: nextPriceId }],
            proration_behavior: "always_invoice",
            payment_behavior: "pending_if_incomplete",
            proration_date: subscription.current_period_start,
          },
        );
        if (typeof newSubscription.latest_invoice === "string") {
          this.stripe.invoices.update(newSubscription.latest_invoice, {
            discounts: [{ discount: promoCodeId }],
          });
        }
#

nope didn't work

plush river
#

is there a reason why you can't apply the promotion code first, then apply the pending_update?

umbral ocean
#

what if the promo code applies to the new product but not the old product

#

does the customer portal use "pending_if_incomplete" or was it using "allow_if_incomplete"

#

Use allow_incomplete to transition the subscription to status=past_due if a payment is required but cannot be paid.

Use pending_if_incomplete to update the subscription using pending updates.

#

By default, updates are applied regardless of whether payment on the new invoice succeeds. If payment fails, rolling back the updates is a manual process. You need to create a new invoice, prorate items on the invoice, and then initiate payment again.

#

does this mean if i did allow_incomplete, the subscription would "update" but be "past_due"? in the event of a payment failure

#

whatever the customer portal's behavior was, i am fine with it

#

ok nvm

#

ignore all that

#

i just tried w/o pending updates and it's not what i want

#

maybe i can update the customer w/ the coupon

#

then process the sub update

#

then remove it from the customer?

#

If you provide a coupon code, the customer will have a discount applied on all recurring charges. Charges you create through the API will not have the discount.

plush river
#

you need to test it out, i won't be able to tell you off the top of my head if things will work as you expect

umbral ocean
#

ok

#

coupon
string
If you provide a coupon code, the customer will have a discount applied on all recurring charges. Charges you create through the API will not have the discount.

#

so this is the promo id? the coupon id?

#

the promo code? it's not very clear

plush river
#

with regards to the coupon, you can always restrict what products it applies to

#

where did you see that piece of info? can you share the corresponding URL?

umbral ocean
plush river
#

that's under the promotion_code parameter - in our API docs it says

The API ID of a promotion code to apply to the customer. The customer will have a discount applied on all recurring payments. Charges you create through the API will not have the discount.
umbral ocean
#

alright what you said worked

#

i can pre-update the sub w/ the coupon

#

if (typeof subscription.customer === "string") {
await this.stripe.subscriptions.update(subscriptionId, {
coupon: couponId,
});
}