#Ekynos-invoice-search

1 messages ยท Page 1 of 1 (latest)

normal spire
#

Hi ๐Ÿ‘‹ happy to take a look, could you tell me what the concern is?

austere apex
#

Thank you

#

We (easyfeedback) use Stripe for subscriptions. But we don't use Stripe invoices by now. So we have invoices both in our system plus in Stripe. Now we need to add our invoice numbers to existing Stripe invoices. The idea is to use the API search to look for recently created invoices.

#

This works fine for searches containing the customer and and created date, but it stops working as soon as I add another AND condition with subscription:subscription ID

#

In the docs it says "subscription:"SUBS-123" which seems to be very strange, since the subscription IDs normally start with sub_

#

Using subscription:sub_ in the query as a third AND option returns no more results.

#

Where sub_ is the correct subscription ID of the invoice

#

For example: customer:"cus_LfsqFV0aGdfyJ1" AND created>1660658925 AND subscription:"sub_1LZxmXD9SvQvLcCosV97ZvxE"

#

(It's all test data)

lone sphinx
#

catching up here, one sec

normal spire
#

For your query, is the string that you shared the exact string that you're providing? Could you share the code snippet that you're using to execute the search?

austere apex
#

Yes, that's the exact string

#

The code snippet is a more complicated issue since it's relying on OOP plus the stripe/stripe-php lib

normal spire
#

Gotcha, I tried to reproduce the behavior you mentioned, but was not able to. When comparing my request to yours, the one thing that I'm noticing different is how the quotation marks in the string are being handled. Can you confirm whether you're escaping the quotation marks that occur in the middle of the string?

austere apex
#

In the values, the quotation marks get escaped with . I'm not sure what's happening after that since the query is handed over to the lib

#

$foundStripeInvoices = Invoice::search(['query' => $query]);

#

Which would call /v1/invoices/search

#

There's no problem when I'm using the customer, which already has quotes in it. The problem only occurs when I add a thrid AND parameter with subscriptions

#

Ah, Discord.... "get escaped with \"

normal spire
#

Here is the snippet that I was able to use successfully (I also switched to the same sdk version you're using to ensure it wasn't a version specific concern):

    'query' => 'customer:\'cus_M0C0BDrsM4AK8W\' AND created>1660658925 AND subscription:\'sub_1LW2hXAgEBCHsfP6lPhkZhDp\'',
]);```
If you use my query string, but with your values, does the search return the results you're expecting?
austere apex
#

Weird. Now that you hav mentioned it, trying the script with just the query works fine

normal spire
#

Ah, gotcha, interesting.

austere apex
#

Yes, since it's almost the same code ๐Ÿ™‚

#

StripeHelper::setupStripeAPI();
$foundStripeInvoices = Invoice::search(['query' => $query]);```
#

Works like a charm

#

So the only reason I can see is that the invoice doesn't exist at the time of the request.

normal spire
#

Oh, good catch, I didn't realize how close the creation time and search requests were made. Our search functionality runs off a replicated data source, so there is a bit of a delay between when objects are created and when they're discoverable by search (looking for the documentation on this to see if it gives an estimate of that delay).

austere apex
#

Ah, same here, since we have a lot of databases and the sync takes a while...

#

So when I did the requests with the customer ID plus created date only I have been lucky it seems

#

I will just add a short delay and try again. Thank you for your assistance.

normal spire
#

If you know the ID of the Customer and Subscription that you're looking for Invoices for, then our Invoice list endpoint will likely be a better fit.
https://stripe.com/docs/api/invoices/list

You can provide those IDs as filter values, and also use the created array to control how far back the list results will go. The list endpoint runs against the primary data source so will always have current and correct results.

austere apex
#

Yes, I use both customer ID and the subscription. That was when the results didn't show up any longer ๐Ÿ™‚ Thank you.