#quantum1125 - Node Listing Payment Intents
1 messages ยท Page 1 of 1 (latest)
Hello! I believe require() needs to be called outside of a function. If you move that line outside the function, then pass in stripe as an argument to the function instead does it work as expected?
no difference, same stripe error
Can you share the code you're using?
const stripe = require('stripe')('sk_test_');
async function getPaymentIntents() {
const paymentIntents = await stripe.paymentIntents.list({
limit: 3,
});
console.log('paymentIntents',paymentIntents)
return paymentIntents
}
getPaymentIntents();
```javascript
Is it still throwing the error Error: Cannot find module 'stripe' or a different one?
same error, Cannot find module 'stripe'
Did you install the Stripe Node library using NPM?
oh my, you're right. I was using the stripe-search-beta library, which i assumed included the regular stripe node library
๐
A quick npm install stripe --save should sort out that error. ๐
And, actually, you can probably put it back in the function.
If you leave it out of the function you may need to modify both getPaymentIntents() bits to be getPaymentIntents(stripe)
Ok i got an output working, but I'm curious how to correctly iterate through the result of
await stripe.paymentIntents.list();
I'm getting an error that paymentIntents.forEach is not a function even though stripe returns a list
here's my code:
let orders = []
async function getPaymentIntents() {
const paymentIntents = await stripe.paymentIntents.list();
paymentIntents.forEach(paymentIntent => {
if (paymentIntent["status"] =='succeeded') {
orders.push(paymentIntent)
}
});
return orders
}
getPaymentIntents();
```javascript
I recommend you use auto-pagination as described here: https://stripe.com/docs/api/pagination/auto
when i try auto-pagination, i get an error saying TypeError: paymentIntents.autoPagingEach is not a function
let orders = []
async function getPaymentIntents() {
const paymentIntents = await stripe.paymentIntents.list();
paymentIntents.autoPagingEach((paymentIntent) => {
if (paymentIntent["status"] =='succeeded') {
orders.push(paymentIntent)
}
})
return orders
}
getPaymentIntents();```
What version of Node are you using?
v16.9.0, you want me to use
for await (const customer of stripe.customers.list({limit: 3})) {
// Do something with customer
}
Yeah, that's what you need to use since you're on Node 10+.
because the syntax of auto-pagination for stripe search beta is what i did above
Not sure what you mean, can you provide more details?
If you look at auto-pagination syntax here, it shows the syntax i originally used https://stripe.com/docs/search-api#examples
The search API is in beta and may work differently, I'm not honestly sure. Does the Node 10+ syntax work as expected?
i believe this syntax works, but it does take longer than expected to filter out.
Try using a higher limit.
The limit applies to each individual request behind the scenes. For example, if you specify a limit of 10 and you have 100 total items to list that will require 10 API requests. If you specify a limit of 50 you'll only need two.
Interesting, the documentation reads as if it is limiting the number of items returned, similar to how SQL works https://stripe.com/docs/api/payment_intents/list?lang=node#list_payment_intents-limit
It does limit it for each individual API call, but when using auto-pagination the library will make as many API calls as needed to give you the full list.
so it seems like I should always opt for limit:100 if i am returning more than 100 items in a list?
No, depending on what you're listing a high limit might make the request time out. I recommend using a limit of around 50 to start with, then adjust up or down from there depending on your specific use case.
Also note that specifying a limit greater than the number of results is fine.
i thought it would only depend on the number of items expected to be returned?
If your account has 10 Customers you can ask the API to list all Customers with limit set to 100 and it will work just fine. The limit defines the maximum amount of results per API request, but you may get back fewer.
On the other hand, if your account has 1,000 Customers and you have limit set to 100 you'll get 100 back with a single, non-auto-paginating list request or all 1,000 if you use auto-pagination.
Does that make sense?
yes that does make sense.
another question, for https://stripe.com/docs/api/payment_intents/list?lang=node, in the response, is the customer attribute supposed to be a name? and does stripe try to create this name based on CC info?
No, the customer property there is supposed to be a Customer ID (typically something like cus_123).
ok if i wanted to find out which customer that belongs to, i'd have to use that ID in my retrieval using this API? https://stripe.com/docs/api/customers?lang=node
Yeah, if you want to fetch the details of the Customer based on their ID. Specifically this: https://stripe.com/docs/api/customers/retrieve
got it, and auto-pagination is suppose to work across all supported Stripe APIs, including Customer?
Yeah, auto-pagination works for any list endpoint.
hmm why is customerID null so often? make it impossible to look up the customer name. shouldn't generate a new customer id per paymentIntent if customer doesn't exist?
Where are you seeing it be null?
On the customer property on a Payment Intent?
Payment Intents can exist on their own without being associated with a Customer.
yeah i am seeing it on Payment Intent. got an error that my customer api call was not working and it was because it was being passed null, which i pulled from the payment Intent
That's normal. You should check for null values before passing them back to the API.
i know to check now, but i am wondering how stripe assigns customer id in paymentIntent
In what scenario?
Payment Intents can be created directly via the API, or they can be created by other things (like Checkout or Invoices). Can you give me more details about what you're trying to do so I can help unblock you?
my goal is pull 3 pieces of info from stripe via your endpoints: description (via paymentIntent), customer name (via customer via paymentIntent), and order amount (via paymentIntent)
A Payment Intent may not have a Customer associated with it, and thus there will be no name.
Even if there is a Customer associated that Customer may not have a name set.
i am wondering how sometimes during checkout (where i believe our paymentIntents are created) a customer ID is associated and sometimes not. Seems mostly random.
Can you give me an example Payment Intent ID without a Customer associated?
pi_3JvKp2BEzuI4g3Px1s6t9uSL
Looking...
That Payment Intent was created directly (not via Checkout) using the API in this request: https://dashboard.stripe.com/test/logs/req_nuttemPZwSjIXb
No Customer was associated.
interesting, what about this payment Intent? can you tell how it was created? pi_3JYD4pBEzuI4g3Px1b2ecGav
this has an associated customer
I can, but let me teach you how to find out yourself. ๐
i'm currently unable to access my stripe account which is why i ask
If you open the Payment Intent in your Dashboard you can scroll down to the Events and Logs section at the bottom, then look at the stuff at the bottom of the timeline shown there: https://dashboard.stripe.com/test/payments/pi_3JYD4pBEzuI4g3Px1b2ecGav
Ah, okay.
That one was created by the API as well, but this time a Customer was specified. Checkout was again not involved.
You should try to get your Dashboard access sorted out, as that will help you investigate and debug.
I have access to another stripe account that i'm looking at to see where you are referencing the origin of the paymentIntent, but I do not see it
What do you mean?
where do you see that any of these requests originated via API vs Checkout?
this is an old stripe account btw
Click on one of those, then on the right you should see detail about the request. The Source will indicate where the request came from.
Source gives the device info
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36