#nicolas-m_api

1 messages ¡ Page 1 of 1 (latest)

knotty groveBOT
#

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

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

blissful fern
#

Hi there

lapis forge
#

hello

blissful fern
#

Not quite sure I follow. So you have a Customer and a Charge, and you want to find Price/Plan details from that Charge? Do you have an example Charge ID?

lapis forge
#

yes! for example, someone buys something, then there is a plan, which hypothetically is "Premium Plan", I want to find that name in the charge object, in the charges endpoint, and it has that description, which gives me that name, but with what other information I don't need, like (at {somevalue} / every x months)

#

i have this chargeId: ch_3Qm1FSCncruDcoif0RKTSf8W

#

"description": "1 × Plano Tipster (at R$ 220.00 / every 3 months)", as you can see, there is other information in the description (I assume this information is not in the actual name of the plan)

blissful fern
#

So neither the Charge nor the PaymentIntent will contain the Price details. You'll need to inspect the relevant Invoice object instead

lapis forge
#

yes, im already doing this, but the price object dont give me this information (the name)

#

"price": {
"id": "price_1NxeeZCncruDcoifcnxY6djX",
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1696462735,
"currency": "brl",
"custom_unit_amount": null,
"livemode": true,
"lookup_key": null,
"metadata": {},
"nickname": null,
"product": "prod_O7LoGL8x5NiPws",
"recurring": {
"aggregate_usage": null,
"interval": "month",
"interval_count": 3,
"meter": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"tax_behavior": "unspecified",
"tiers_mode": null,
"transform_quantity": null,
"type": "recurring",
"unit_amount": 22000,
"unit_amount_decimal": "22000"
},

#

(using this object as example)

blissful fern
#

Ah gotcha

#

The name is tied to the Product so you'll need to expand product

lapis forge
#

&expand[]=data.product like doing this?

blissful fern
#

If you're using Node, it'd be something like expand: ['lines.data[0].price.product'] if you're retrieving an Invoice but I might have the syntax wrong

lapis forge
#

this is the url im using rn

#

but I don't think it works, as the object is not expanded

blissful fern
#

Expansion isn't a query param but a body param

#

What server side language are you using?

lapis forge
#

im just making the request on postman

#

nothing on the body

blissful fern
#

Ah hmm, looks like I was wrong and Postman sends as query params

lapis forge
#

so, am i using right?

blissful fern
#

Not exactly. It'd be something like v1/charges?expand[0]=data.invoice.lines but you're going to run into a different issue

#

and you need data.invoice.lines.data.price.product so you'll get an error

#

Let me take a step back. If your goal is to retrieve Product name information associated with a specific Charge, why are you using the List Charges endpoint instead of retrieving the specific Charge?

lapis forge
#

because I need this information for my product, I have an analytics that shows metrics like MRR, and I want to see which customers paid in a month, so I need the charges with the customer's name, the amount, due date and the name of the plan

blissful fern
#

Got it. In that case, you won't be able to do this in one request. That said, I think a better solution to this is to keep some mapping in your database that maps Prices, Products, and Product names. Then, once you get from Charge to Invoice to Prices on that Invoice, you can look up the relevant names