How to get Order Object when I only have payment session?

How to get Order Object when I only have payment session?

WilliamATM
Shopify Partner
32 0 4

I have this payment session gid.

 

gid://shopify/PaymentSession/tRCNXWfcku6QrTIunAx6jKJk
 
Is there a way to get the order object?
Replies 10 (10)

WilliamATM
Shopify Partner
32 0 4

Bump

WilliamATM
Shopify Partner
32 0 4

Bump

WilliamATM
Shopify Partner
32 0 4

Bump

WilliamATM
Shopify Partner
32 0 4

Bump

WilliamATM
Shopify Partner
32 0 4

Bumping to new, anyone has tried this?

WilliamATM
Shopify Partner
32 0 4

Bump, asking for help.

TJ_Biddle
Explorer
39 1 17

Also interested in this. I'm using a 3rd party app that is only returning me this PaymentSession object as a reference and I'm unable to tie it to an order. 

jason-martin
Shopify Partner
4 0 3

William,

 

This one is hard, I just started exploring it today because we have a need to use this id as our primary id on payments as opposed to what we used to use which was the x_url_cancel, since it contained the checkout_token to cross reference.

 

The reason we are moving off of this is because Shopify has been recently changing the formatting of the URL, since it's requirement isn't to contain the checkout_token, but to perform it's action, so they do not see it as a breaking change as we do.

 

We are seeing three different URLs from Shopify at the time of this post:

https://{store}.myshopify.com/{store_id}/checkouts/{checkout_token}

https://{store}.myshopify.com/checkouts/c/{cart_token}/processing

https://{store}.myshopify.com/checkouts/ac/{abandoned_cart_token}/processing

 

So I'm not sure why you are asking the question, but we got the question from on of our Merchants who is using us as their Alternative Payment Provider for Authorize.net.

 

So I am looking at this issue as that of a Payment App. Unfortunately, when Shopify posts the data for use to process they do not pass us any ids outside the this payment session gid; and indirectly the checkout token through the cancel URL which is now not a reliable method for matching up transactions.

 

So this is how I've found the Payment Session ID in both the beginning and at the end:

 

DATA RECEIVED FROM SHOPIFY BY PAYMENT APP

As noted above, don't blame the Payment App, we are limited by what we are sent.

 

x_payment_gid=gid://shopify/PaymentSession/n867gqMOeV3agTaTx0m7jtjKN

n867gqMOeV3agTaTx0m7jtjKN is our ID and we want to find this via the API after everything is said and done


x_url_cancel=https://store.myshopify.com/51959267492/checkouts/9d11bd00d9f85d7eb82f20c33303a053 
We do not want to use this, because it does not stay consistent 

 

DATA ON ORDER CONFIRMATION PAGE
Nothing special here, we are at the Order confirmation page and recording this data to match it up with the payment session later.

 

https://store.myshopify.com/51959267492/checkouts/9d11bd00d9f85d7eb82f20c33303a053/thank_you 
Created Order Order #1133

 

DATA FROM BACKOFFICE

If we look up the order id 1133 in our back office an review the URL we will find the order id to make an API call to see if we can find the payment session id


https://store.myshopify.com/admin/orders/4785199874212 

 

DATA FROM GRAPHQL

I just learn Graph QL today, so I haven't mastered it, and I'm sure there are better queries and would love input from a GraphQL expert on making this better, but via my limited skills I found the Payment Session ID.

 

QUERY

 

{
  order(id: "gid://shopify/Order/4785199874212") {
    id
  	name,
    createdAt,
    closedAt,
    transactions {
      id,
      status,
      gateway,
      formattedGateway,
      receiptJson
    }
  }
}

 


RESPONSE

 

{
  "data": {
    "order": {
      "id": "gid://shopify/Order/4785199874212",
      "name": "#1133",
      "createdAt": "2022-10-01T20:08:27Z",
      "closedAt": null,
      "transactions": [
        {
          "id": "gid://shopify/OrderTransaction/5889093533860",
          "status": "SUCCESS",
          "gateway": "OpenPath Payments",
          "formattedGateway": "Open Path Payments (Ngrok Opec Payments)",
          "receiptJson": "{\"payment_id\":\"n867gqMOeV3agTaTx0m7jtjKN\"}"
        }
      ]
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 2,
      "actualQueryCost": 2,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 998,
        "restoreRate": 50
      }
    }
  }
}

 

 

Who would have taught, there it is under order.transaction[].receiptJson.

 

So now we have been able to match from front to back.

 

WHAT NEXT?

Using this as a starting point, hopefully we can get some support on closing this question out; however, my information does not actually answer the question.

The original statement is how to get an Order from the Payment Session ID only and with the given information above I think you could achieve this by looping through an array of orders and those orders transactions finding the id in the receiptJson. (I would think that there might be a way through GraphQL, but not my area)

Also, there is a good chance if you got the payment session id you have a timestamp as well, this could reduce your search down to just a handful of orders, especially if you can use other attributes such as customer details.

Anyways, that is my two cents, still review, but thought I would share my findings.

jason-martin
Shopify Partner
4 0 3

WOOT!

 

{
  orders(first: 1, query: "payment_id:n867gqMOeV3agTaTx0m7jtjKN") {
		nodes {
		  id,
      name,
      lineItems(first:20) {
        edges {
          node {
            id,
            name
          }
        }
      }
		}
  }
}


...add parameters as needed!

TJ_Biddle
Explorer
39 1 17

Awesome! Thank you @jason-martin 

 

I can't test 100% as I haven't had orders come through with the problem payment processor that caused me to have this question to start, but I found some old orders that *did* run through it - and in the Shopify timeline I saw a "Payment ID" reference on the authorization and captures.

 

This "Payment ID" is 25 characters, just like the ID in the gid:// - So I'm making an assumption here that it's the same thing.

 

Taking that knowledge, it's a drop-in replacement for the `payment_id` mentioned in @jason-martin 's code there. So just need to strip out the gid://

 

I think this solved it @WilliamATM 

 

Thanks again for the diligent research and easy solution @jason-martin !