#acronie_api

1 messages ยท Page 1 of 1 (latest)

tiny fernBOT
#

๐Ÿ‘‹ 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/1229811261206696008

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

torn pelican
#

Both of the user don't have payment method attached

half idolBOT
torn pelican
#

I hope this much info helps if anything more is required please let me know ๐Ÿ˜„

mellow vector
#

Hi there ๐Ÿ‘‹ did the customer have a value set for invoice_settings.default_payment_method when the request to create the Subscription was made?

torn pelican
#

invoice_settings.default_payment_method
No both of them have no payment method attached

torn pelican
mellow vector
#

That's the problem then. You can't create a Subscription unless there is a default payment method available. If there isn't one defined on the Customer object, then one needs to be provided to the Subscription creation request.

torn pelican
#

Just issued a 0$ invoice without any payment method

torn pelican
#

I thought this was a bug to begin with but

#

this is from my production just now

mellow vector
torn pelican
#

set the quantity to 0$ for a price

#
try {
      return ctx.prisma.$transaction(async (tx) => {
        const subscription = await stripe.subscriptions.create({
          customer: customer.id,
          items: [
            {
              price: process.env.STRIPE_PER_MONTH_SUBSCRIPTION_PRICE_ID,
              quantity: 0,
            },
          ],
          expand: ["latest_invoice.payment_intent"],
          off_session: true,
          payment_settings: {
            payment_method_types: ["card"],
          },
        });
        await tx.employer.update({
          where: {
            id: employer.id,
          },
          data: {
            subscriptionIdMonthly: subscription.id,
            subscriptionStatusMonthly:
              subscription.status === "active"
                ? SubscriptionStatus.ACTIVE
                : SubscriptionStatus.INACTIVE,
          },
        });
        return {
          message: "Subscribed successfully.",
        };
      });
    } catch (e) {
      throw new TRPCError({
        code: "INTERNAL_SERVER_ERROR",
        message: "couldn't add subscription for free'",
      });
    }
mellow vector
#

Sorry, I meant can you share the request you made? We aren't as familiar with the dashboard UIs, we primarily focus on helping with the API here, so I'm not able to follow those as easily.

torn pelican
#

Oh gotcha

torn pelican
#

(in prod too)

mellow vector
#

Things are more lax when there first payment is $0.

torn pelican
#

what does that mean?

mellow vector
#

Let's take a step back, what is your desired behavior here? Maybe I can help map what we offer to that.

torn pelican
#

oh got it

#

I just want to hand them things for free but still have an invoice for it

#

and don't want them to add their payment details at time but if they have that shouldn't be an issue either

#

(Do I make sense)

mellow vector
#

I think I understand what you're after, but isn't that also the behavior you're seeing? You encounter an error when creating a Subscription that requires payment, but don't encounter an error when creating a free Subscription? Sorry if I'm not parsing this right yet.

torn pelican
#

but don't encounter an error when creating a free Subscription
yea soooo

#

0$ invoice = free sub right? And no payment method required

#

req_MS0lKai5ayo45x have a look at this

#
{
  "expand": {
    "0": "latest_invoice.payment_intent"
  },
  "off_session": "true",
  "items": {
    "0": {
      "quantity": "0",
      "price": "price_1OvCLaSIyQodp0OwC3ybuAtW"
    }
  },
  "customer": "cus_Pw0JDpMtRxRgcP"
}```
#

0$ and should be free essentially but json "code": "resource_missing",

mellow vector
#

Looking

#

While I do, do you have the request where you were able to create a $0 Invoice without error that you can share as well?

torn pelican
#

Ohk

#

req_8Mqnnrs0p57dMA

mellow vector
#

Hm, I'm not readily spotting the difference here. Still looking.

torn pelican
#

sure you can ping me if you need my help ๐Ÿ˜„

mellow vector
torn pelican
#

cus_Pw5yMZaELFSmzm same happens with this tho

#

oh nvm it doesn't

#

strange is there anyway I can avoid it?

half idolBOT
torn pelican
mellow vector
#

I was just double checking whether you can create a Subscription and tell it to ignore pending Invoice Items, but am not seeing a way to do so. I believe you would need to either collect a Payment Method to be ready to handle the cost associated with the pending Invoice Item. Alternatively you might build logic to look for pending Invoice Items for a customer before creating a Subscription, deleting them, creating your Subscription, and then recreating any deleted Invoice Items you still need.

torn pelican
#

Alternatively you might build logic to look for pending Invoice Items for a customer before creating a Subscription, deleting them, creating your Subscription, and then recreating any deleted Invoice Items you still need.
yea something like that maybe

#

this is admin dashboard so I can just throw an errorr with "pending unpaid invoice" message too

#

Thanks for the help!