stripe-node icon indicating copy to clipboard operation
stripe-node copied to clipboard

Payment intent search by customer not working

Open raviSussol opened this issue 2 years ago • 9 comments

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

  1. Use the search function of the paymentIntent method
  2. Query by customer field with dynamic value i.e. by variable
  3. 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

raviSussol avatar Aug 11 '22 06:08 raviSussol

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

raviSussol avatar Aug 11 '22 08:08 raviSussol

What is this token type? Is this different from the string type? Am I missing any configurations?

raviSussol avatar Aug 11 '22 08:08 raviSussol

@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?

remi-stripe avatar Aug 11 '22 14:08 remi-stripe

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 avatar Aug 12 '22 01:08 raviSussol

@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 avatar Aug 12 '22 02:08 remi-stripe

@remi-stripe I get this

>  Looking for all PaymentIntents for  cus_Hm0J0lNvSV1HmR
>  Number of PaymentIntents found:  10

raviSussol avatar Aug 12 '22 04:08 raviSussol

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 avatar Aug 12 '22 05:08 remi-stripe

@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.

raviSussol avatar Aug 12 '22 05:08 raviSussol

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 avatar Aug 12 '22 05:08 remi-stripe

@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 🙏

raviSussol avatar Aug 30 '22 11:08 raviSussol