stripe-node
stripe-node copied to clipboard
Payment intent search by customer not working
Describe the bug
Payment intent search using query for customer is not working. It doesn't return valid response object for a specific customer. This happens only if the query parameter has dynamically set customer value in the search
function of the paymentIntents. Otherwise it works if I use query parameter with a static value in the customer field.
To Reproduce
- Use the search function of the paymentIntent method
- Query by customer field with dynamic value i.e. by variable
- See error
Expected behavior
Should be working as of it works when passing customer field value as static in the inline code.
Code snippets
// Works
const customer = 'cus_2332';
const paymentIntent = await stripe.paymentIntents.search({query:`customer:'${customer}'`})
// Doesn't work
const getPaymentIntent = async (customer:string) => {
const paymentIntent = await stripe.paymentIntents.search({query:`customer:'${customer}'`})
};
And this function is a firebase function so it is called from client app where it returns:
{
object: 'search_result',
data: [],
has_more: false,
next_page: null,
url: '/v1/payment_intents/search'
}
OS
macOS, windows
Node version
16.13.1
Library version
stripe-node v9.6.0
API version
2020-08-27
Additional context
No response
To add more details, fields which are token typed are not basically working in the query. Tried with metadata['key']:'value' too - didn't work either. https://stripe.com/docs/search#query-fields-for-payment-intents
What is this token type? Is this different from the string
type? Am I missing any configurations?
@raviSussol I have tried your exact code but it works fine for me. Can you try running the exact code below with the same key and customer id?
const stripe = require('stripe')(
'sk_test_4eC39HqLyjWDarjtT1zdp7dc',
{
apiVersion: '2022-08-01',
}
);
const getPaymentIntents = async (customer:string) => {
console.log("Looking for all PaymentIntents for ", customer);
const paymentIntents = await stripe.paymentIntents.search({query:`customer:'${customer}'`})
console.log("Number of PaymentIntents found: ", paymentIntents.data.length);
};
(async () => {
var customerId = 'cus_ABCDEF';
getPaymentIntents(customerId);
})();
Can you share the output you get back?
Thanks for looking at this @remi-stripe. This is the output I get with your above codes:
> Looking for all PaymentIntents for cus_ABCDEF
> Number of PaymentIntents found: 0
@raviSussol okay now try the exact same code but change the customer id for cus_Hm0J0lNvSV1HmR
const stripe = require('stripe')(
'sk_test_4eC39HqLyjWDarjtT1zdp7dc',
{
apiVersion: '2022-08-01',
}
);
const getPaymentIntents = async (customer:string) => {
console.log("Looking for all PaymentIntents for ", customer);
const paymentIntents = await stripe.paymentIntents.search({query:`customer:'${customer}'`})
console.log("Number of PaymentIntents found: ", paymentIntents.data.length);
};
(async () => {
var customerId = 'cus_Hm0J0lNvSV1HmR';
getPaymentIntents(customerId);
})();
What do you get back when you run that code?
@remi-stripe I get this
> Looking for all PaymentIntents for cus_Hm0J0lNvSV1HmR
> Number of PaymentIntents found: 10
Okay so that proves the code is working fine and is mostly identical to what you had in your original report right? So right now I think the issue is more with how you run your original code and whether the customer id is properly defined, without any leading/trailing space or being a null string or something.
@remi-stripe Yeah I had figured that the code works for a static value or when you predefined the customer at the search code. And then I thought the customer coming from my client app might have ambiguous value in it (like you said). But after logging its value in the server side code (before the search function call) and its typeof
- it was receiving the correct string typed value but still didn't work. Furthermore, I discovered that all token
typed fields are basically not working for me (e.g. metadata['somekey']:'value') was also not working. Thats why I asked in my https://github.com/stripe/stripe-node/issues/1508#issuecomment-1211685075 above.
I understand but I literally took your code that you said doesn't work. I didn't hardcode a customer id in the search, I passed it as a parameter here and it still works. I'm dubious there's anything wrong with the library itself right now after you ran the code I mentioned. I'm not saying it's impossible, but we would need a lot more specific details and an exact way to reproduce your issue, with logs proving exactly what you are passing in the API itself
@remi-stripe Nevermind! I got around this using stripe.paymentIntents.retrieve
function to validate payment in the Stripe. Though its strange that this issue only happening to me... For now I'll close it. Thanks much for the heads up on this 🙏