Shopify REST API: Paid+Fulfilled and fully Refunded orders not retrievable by filter (but can be by ID) - shopify-api

The requirement is to periodically download all newly fulfilled or refunded orders from Shopify using the REST API. This has been attempted using parameters for modified date and status. This is the endpoint, and documentation is here.
/admin/api/{{api_version}}/orders.json
However, orders which are in either of the following states seem to always be excluded from the results:
Payment Status=Paid & FulfillmentStatus=Fulfilled
Payment Status=Refunded
In the Shopify admin UI, these appear greyed out in the order list.
I don't think these orders have become archived because even very recent (today's) orders are excluded, and also they can be retrieved by order ID using this endpoint:
/admin/api/{{api_version}}/orders/{{order_id}}.json
Is there any way to incrementally query for orders in these states, i.e. without knowing the IDs?
How the inaccessible orders appear in the UI:

This is the answer: orders in the above 2 states have an overall status of "closed" (as opposed to "open" or "cancelled"). Closed orders appear greyed out in the UI.
When querying for orders via the List endpoint, you can specify a status parameter, but if you do not Shopify applies a default of "open", so closed orders are excluded. Specify status="closed" to access closed orders only, or status="any" to access all statuses.

Related

What's the best practice for handling bill details with Stripe?

In my mobile app when the user has selected some items, I would like them to be able to review their order and see a preview of their bill (the price of each item, subtotal, taxes and total). However I would not want them to pay immediately. Once they place the order, they will not be charged until the order is accepted.
Do I calculate the user's subtotal, tax and total on my server or does stripe provide an api to handle these?
I've read the docs on invoicing and checkout, and checkout seems to be the api for my situation but I'm not 100% sure.
It depends on how you define "place the order" and "order is accepted". Normally when the Stripe's Checkout Session page is displayed to your customer and they push the "Pay" button, the transaction will be executed immediately (they paid), then the customer can be redirected back to your page or app.
If you want to somehow delay the payment until a specific timing (that you want to review or execute some logic, before eventually "accept" the order), you can consider using Checkout with Setup Intent.

Get purchased product from PaymentIntent

in my app i want to list past purchases for a stripe customer. So I was looking at the relevant API objects like PaymentIntents, Sessions or Charges. But they all do not seem to contain any reference to Product or Price, which I would need to list the purchased products.
Subscriptions contain a list of items that are contained in that subscription, so I was expecting PaymentIntents to have something like that too.
Does anyone has an idea how to archive my list of past purchases? Thanks!
I did some digging through the Stripe API docs[1] and, out of the three objects you referrenced (PaymentIntent, Session, Charges), the only one that I can see being able to trace back to a product is the Session.
Session objects have a line_items property[2] which can be followed all the way down to line_items.data.price.product[3]. To access this you’ll need to inlcude the expand=["data.line_items"] parameter to your call to list Checkout Sessions. You can read more about expanding API responses here[4]
So for all the charges to your customers that were done using Checkout Sessions, you could list them all, use the customer property to associate earch session with a customer in your application, traverse the the returned data, and then query the API for the product details. If you have a lot of customers & products these API calls will add up fast so I would store this data in your back-end to avoid hitting rate limits[5].
Alternatively, you could just save the product ID (either Stripe or your local version) as metadata[6] for any of the above Stripe payment objects listed. That would allow you to link any payment object you wish to a product.
https://stripe.com/docs/api
https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items
https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items-data-price-product
https://stripe.com/docs/expand
https://stripe.com/docs/rate-limits
https://stripe.com/docs/api/metadata
I had the same question I found a way to retrieve the products related to a specific PaymentIntent.
You need to get the sessions that was linked to PaymentIntent when the Checkout process was made.
I will give you the code (in PHP) that I use to to this.
\Stripe\Stripe::setApiKey(STRIPE_API_SECRET);
// Find the Session for that PaymentIntent
$sessions = \Stripe\Checkout\Session::all([
'payment_intent' => "pi_xxxxxxxxxx",
'expand' => ['data.line_items'],
]);
You will then have an key line_items that contain the products linked.
Enjoy

How do I prevent multiple paypal payments in nodeJs?

I am really new to node js and trying to integrate Paypal's Payment Gateway into my application.
Upon the success of the payment, the user is redirected to http://localhost:3000/success?paymentId=PAYID-M8MU148234F&token=EC-2111Y&PayerID=YX82JX6Q where our code executes the order and return a payment object (contains order details).
On this page, I want to display the order details to the user.
I want to store the payment object as a JSON.stringify into my Mongoose database for future reference. The issue is that if the user keeps on reloading this page, the code inside app.get('/success'..) will keep on adding the same columns to the mongoose database repeatedly. I am not sure how to prevent that.
Since the payment is actually executed only when this URL is visited by the user, multiple reloads by the user blocks me from Paypal API and gives me the following error:
response: {
name: 'MAX_NUMBER_OF_PAYMENT_ATTEMPTS_EXCEEDED',
message: 'You have exceeded the maximum number of 20 payment attempts.',
information_link: 'https://developer.paypal.com/docs/api/payments/#errors',..........
The only solution I can think of right now is that somehow my /success route executes the payment and stores the data onto the database and then redirects the user to maybe /someOtherPage/ page with the order details as headers. I am not sure how to make this redirect happen and also pass some context (the payment object) at the same time.
You are using a deprecated v1/payments API and/or PayPal-Node-SDK. You should change your integration to the current v2/checkout/orders and Checkout-NodeJS-SDK.
Make two routes on your server, one for 'Create Order' and one for 'Capture Order', documented here. These routes should return only JSON data (no HTML or text). The latter one should (on success) store the payment details in your database before it does the return (particularly purchase_units[0].payments.captures[0].id, the PayPal transaction ID)
Pair those two routes with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server
The above mostly takes care of this issue and is the recommended solution, as it does not rely on redirects and gives an improved user experience that increases buyer confidence by keeping your site loaded in the background. But to more directly address the issue posed here: when doing an execute or capture API call, set the PayPal-Request-Id HTTP header to something that will persist across retries that are not expected to result in new actions/transactions -- for example simply set this header to the PAYID or OrderId being acted on. This will give idempotent behavior (see API idempotency)

Stripe: Get total successfully paid invoices count

I'm using stripe for subscription. Where i need to fire an event after 3 successfully charges.
For this i am using invoice.payment_succeeded webhook.
But there is no key which specify the number of this recurring payment means whether it is first or second or nth charge. So how could i get the number of successfully payment made on a subscription.
You can call the https://api.stripe.com/v1/invoices API endpoint with the customer's ID, the status parameter set to paid and optionally, the subscription parameter and then count how many invoices were returned.
There are some other parameters, like limit, starting_after, etc. that you can send it too.
The invoice.payment_succeeded webhook sends the invoice object in the data.object field so you should be able to get the customer and subscription values from it.
I'd recommend doing the invoices call asynchronously to ensure that the webhook call doesn't time out.
FYI there is an expand to it, like with the current node api;
const ret = await stripe.invoices.list(
{
expand: ["total_count"],
limit: 0,
});
console.log(ret.total_count)
It can be called with ${url}?expand[]=total_count&limit=0 too, if you need to write it by hand.
I did not found this in the documentation, but some libs using it, and it is indeed works. (But be careful, if it is not documented it could stop working too.)
Here is the docs; https://stripe.com/docs/api/pagination/search#search_pagination-total_count
Yes, as it is stated in the answer by D Malan, you can use the https://api.stripe.com/v1/invoices endpoint.
Though there is one thing to keep in mind when retrieving data from Stripe.
You can only get 100 items per call. Therefore, if you had recurring payment that generates more than 100 invoices after some time, you wouldn't be able to get the total count in one call. I suggest storing invoices/payment intents to your database and then using your DB engine to count the results.
Keep in mind that you should listen to invoice.payment_succeeded event in order to keep your database in sync, if you store the invoice or payment intent beforehand, while its status is not paid or succeeded, respectively.

Level 3 data with Stripe Payments

I'm working on a SAAS system that allows purchases to be made through a clients own payment gateway. We have one client that wants to use Stripe as their gateway, however as they are using Corporate Purchase Cards (CPC), it is necessary to pass Level 3 transaction details through. I've been trying to get details from Stripe on how we ensure that Level 3 data can be passed through successfully, however I'm not really getting anywhere with this in terms of getting any definitive information we can work with.
Stripe say that their system supports level 3 data, we just need to provide the data in the first place, however there is nothing in their documentation about this and the example we have been provided only allows for a single item to be listed - we will need to support a basket of different items.
We are using the Payment Intents process and already support adding in Metadata to the transaction. We've been told that adding metadata for SKU, Unit of Measure, Unit Price and Extended Price will allow level 3 processing, however this does seem to fall short of the information list on other sources (not to mention does not allow listing multiple items in the order due to the metadata keys needing to be unique)
Baed on that, our Metadata population looks like this (values hard coded to example purposes)
Dictionary<string, string> nRetVar = new Dictionary<string, string>();
nRetVar.Add("Customer", "John Smith");
nRetVar.Add("Email", "John.Smith#example.com");
nRetVar.Add("Order Number", "12345");
nRetVar.Add("Order Date", "2020-02-06");
nRetVar.Add("SKU", "ABCD1234");
nRetVar.Add("Unit of Measure", "1 Pack");
nRetVar.Add("Unit Price", "$10.00");
nRetVar.Add("Extended Price", "$15.00");
Stripe support never seem to directly answer any of the questions we have been asking about this, so it's proving very hard to get any progress on this - does anyone have enough experience with this to confirm if this metadata is enough to class as level 3, or is there more that we need to be adding?
Stripe supports Level 3 data in their API on both Charge and PaymentIntent. This feature though is currently "gated" which means you need to get access to the feature on your specific account. It's a bit similar to a long running beta. You should contact their support team again and ask for them to enable Level 3 data on PaymentIntent for your account.
The fields they are expecting as specific to that feature. This does not go inside metadata. The documentation is also gated which means you can only see it once you get access to the feature, to avoid confusion for other developers who don't have access.
You can see what the shape looks like in stripe-java for example on Charge here. The feature is not directly supported on PaymentIntent in the library though as this is still private.

Resources