#abidcastaneda-invoices-retrieve
1 messages · Page 1 of 1 (latest)
Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- abidcastaneda, 6 days ago, 44 messages
Are you attempting to work with a livemode object? Or a test mode one?
Sorry, was looking over the documents
A live mode object
the cusomter is in live mode
and what command were you attempting that gave you the error?
This one: stripe customers balance_transactions cus_LwDDvcCklDLOpc --limit="3"
You need to add --live to the end of your command.
Like this: stripe customers balance_transactions cus_LwDDvcCklDLOpc --limit=3 --live
Oh wow, thanks, didn't see that one comming
Um, and by the way,
what i'm trying to do is to get the last invoice payment status
could you tell me or direct me to where I can find that?
for that customer
What I need to do is to write the php code to get if the invoice was payed or not so I can enable or disable their user login depending on that information
I need to do this in php
Another thing, when I write downs this code on stripe cli: stripe invoices search --query="customer:"cus_LwDDvcCklDLOpc" --live it only appears ">>" after it and I get nothing else
We show a quick snippet of how to retrieve the Invoice here: https://stripe.com/docs/api/invoices/retrieve?lang=php
Ok, thanks, but on that reference, you need to know the invoice number, but I need to get the last invoice
because the goal is to retrieve this automatically, I would want to enter my stripe dashboard each month to get the last invoice id
Also, that would get me an invoice depending on the invoice's ID, but I don't see where to get an invoice depending on the customer ID
I guess the correct way to ask is to query for a specified customer's last invoice payment status
and only the payment status, not all the information
Have you tried just listing all the Invoices for that Customer? Instead of using the Search API?
stripe invoices list -d customer=cus_LwDDvcCklDLOpc --live
I just did, and it works, but still, I don't see how to only get the info that I want
I don't need all the invoices
I just need to know if the customer payed the last invoice they were billed
The list API would give you the invoices in reverse chronological order - so if you only want to check if their latest invoice is billed you can just do the same command with limit 1
stripe invoices list -d customer=cus_LwDDvcCklDLOpc --limit=1 --live
abidcastaneda-invoices-cli
ok, sure, but how to retrieve only if the last invoice was payed?
I'm not sure what you mean by that - can you be more specific? Doesn't getting the most recent Invoice from the list API give you exactly what you want?
nope
ok, let me see if I can explain myself better with this
<?php
$invoice = stripe invoices list -d customer=cus_LwDDvcCklDLOpc --limit=1 --live
if ($invoice = payed ) {
header('Location: ' mystripeinvoicepaymenturl.com );
}
?>
So, at the end, is to retrieve the customer's last invoice only if the invoice is payed
A couple things here - why are you using the CLI in PHP code? Is that just meant as a placeholder?
I think you're really approaching this the wrong - there isn't really any way for you to know whether the latest invoice is paid without first retrieving it so no matter what you're going to need to retrieve it from Stripe
Sorry, and yes, it was meant as a place holder
What you can do is retrieve the Invoice, use code to check the status of the Invoice, and then do what you want based on that
I know how to retrieve data from mysql and the closest example I can think of is this (again, using place holders)
SELECT customer, invoice, status
CASE
WHEN status = payed THEN "Tthank you"
WHEN status = notpayed THEN "paymenturl.com"
END
FROM customersinvoices;
Yeah that's exactly what you'd do in PHP - you'd retrieve the Invoice from Stripe, add logic on your end to check the status, and if it's payed then you continue on what whatever logic you want
yes but what to use to check if the payment status is payed or not?
Ok, in php, I cannot just say, read response, or something like that
You should be able to - you get the full response from Stripe that inclues the whole Invoice. Why wouldn't you be able to read the reponse?
What I can do is put a query and return true if there's data on it or false if no data comes from it
so the query would be something like = get invoice where customer = "cust" and payment status = payed
If that pulls data then it's true
and if not then is false
but cannot ask something like get invoice where customer = "cust" and tell me if the field status says payed or not
maybe recover unpaid invoices?
Again, I'm not really sure why you wouldn't be able to read the response.
Assuming you're doing this client-side, you'd make a request to your own server which would make a request to Stripe to list the most recent Invoice for your Customer. Your server would return whatever you want in the response - and client-side you can read that response and add the approriate logic there to do what you want
That query lists the last invoice for a certain cusomter, but it will always list it, I need for it to either return data or not return it
maybe using: invoice.payment_failed
invoice.payment_succeeded
I just found this
if (stripeSubscription.Status == "unpaid")
{
var subscription = subscriptionService.GetSubscriptionByProviderId(stripeSubscription.Id);
subscription.Suspend();
subscriptionService.UpdateSubscription(subscription);
}
I need something like that in php
but get the subscription status for a customer
I think
Getting deep into the Stripe Subscription lifecycle, I explain what happens when subscription payments fail in Stripe and how you can handle this within your own applications.
That person is using a webhook - is that your plan as well?
I don't know, I'm new at this, so I don't actually know what to do
I have 3 days experience with stripe api or stripe cli
and I don't know how to implement the webhook on php
I just need to build a SAAS
How much coding experience do you have? If you're new to full stack development I'd really strongly suggest using one of our no-code solutions, or looking into a plugin
No, I have more than 10 years in coding with php, mysql, but no experience with API's
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
If you have experience with coding then you should be able to create your own PHP server that calls to Stripe's API and retrieve/list the Invoice. That's where I'd recommend you start. Once you've got the retrieval/listing working you can see the full response you get back from stripe and build logic based on what you get back from the response
how about this, but for my live customer
stripe subscriptions search --query="status:'active' AND metadata['order_id']:'6735'"
where can I get the order_id from?
You really shouldn't need the Search API at all for your user case - if you want to be checking the status of the latest invoice then the List Invoices API is really what you want
abidcastaneda-invoices-retrieve
I just ran this piece of code:
stripe subscriptions search --query="status:'active' AND metadata['id']:'sub_1LEKnkA5kJw9cqTjRdeT3miy'" --live and got nothing, and the subscription should be active
But then again, this will show the info, but cannot query only the last paid invoice, it will list the invoice and tha's it
Ok, got another though, what if I can insert the info from the list invoices api to a mysql database table, is that possible?
Again, you really don't need the Search API at all and you're using it incorrectly. Your query is searching for an active subscriptoin that has metadata[:id]: sub_1LEKnkA5kJw9cqTjRdeT3miy. Metadata is somethign that you have to specifically set when you create the Subscription, and most folks wouln'dt add the Subscription ID as metadata to itself.
And yes, you can insert all your invoices into your own mysql database table if you want!
Tha is great! Where can I get documentation as to how to insert the information to mysql database table?
We don't have specific documenattion on how to do that (since it really depends on the specifics of your integration/which database) but generally, you'd insert informatino to your database when you create the Invoice, and then you'd create a webhook for the invoice.updated event and would update the database evertime the invoice is changed
so I need to use a webhook for this, right?
yeah
Oh lord, ok then I'll read about webhooks and see what I can do, thanks, I still feel a little disoriented, but I guess reading some more might help