Get information from draft order payment request

wallee-s
New Member
2 0 0

Hi

We ran into an issue regarding your API that you might be able to help us with.

Usually, if a customer places an order in the online store, our payment gateway receives the ID of the checkout in the payment request, which allows us to fetch further information like the exact line items through the Shopify REST API. However, if the customer places the order via a draft order checkout link which he received by email, we do get a checkout ID in the payment request, but we cannot find the matching checkout through the API. Also, we cannot fetch the corresponding draft order, as we do not get its ID. Can you tell us, whether it is possible and if yes, how we can fetch further information like the line items about an order like that?

Thank you for your help.

0 Likes
_JB
Shopify Staff
Shopify Staff
750 86 163

Hey @wallee-s,

 

The best way is using GraphQL. You can pass the checkout token as a query, which will return just the order you want with your specified fields. Here's an example of what your query could look like:

 

 

{
  orders (first: 1 query:"checkout_token:###") {
    edges {
      node {
        id
        createdAt
        lineItems (first: 10) {
          pageInfo {
            hasNextPage
            hasPreviousPage
          }
          edges {
            cursor
            node {
              id
              title
              quantity
              sku
            }}}}}}}

 

 

Another option is webhooks, if you subscribe to the orders#create topic, the payload of that webhook with contain the checkout_id and line items on the order. Otherwise with the REST API you can run a job every X minutes that checks for new orders, and match on any checkout_id that hasn't been associated to an order yet. 

JB | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
wallee-s
New Member
2 0 0

Hi @_JB 

 

Thanks for your help. This would work if the order already existed which unfortunately is not the case. After the customer submitted the checkout, he is redirected to our payment gateway. That is when we need to fetch the line items with only having the data in the Hosted Payment SDK request (https://shopify.dev/docs/hosted-payment-sdk/reference/request-values). The order will only get created after the payment is processed by our gateway.

That is why we need to have a way to fetch the draft order by only having the information we receive in the payment request. If I am not mistaken, this cannot be done with GraphQL either.

How can this be done?

0 Likes
thomashunziker
New Member
4 0 0

Hi JB,

 

Have you any update on this issue?

 

Regards,
Thomas

0 Likes
_JB
Shopify Staff
Shopify Staff
750 86 163

Hi @thomashunziker @wallee-s,

 

Another option is checkout webhooks. The payload contains the checkout_id, token, and all line_items. You can subscribe to checkout#create and checkout#update, and reference the last webhook received to get the line items.

 

I also wanted to ask, is there a reason you need the line item details before responding to Shopify?

JB | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
thomashunziker
New Member
4 0 0

Dear _JB,

 

Thank you for your response. 

 

We need the line items to calculate the tax amount included in the order and to generate the invoice document along the way. We need to do this before we can create the order as the payment method requires these information before they give the confirmation that the payment is okay and the order can be confirmed. As a consequence we cannot really use the webhook as it might be sent delayed and we would have to wait for the webhook to arrive before we continue which is hard to implement correctly. Especially when Shopify might have some delays in delivering the webhook.

 

Is there really no way to fetch the line items?

 

Regards,

Thomas

0 Likes
thomashunziker
New Member
4 0 0

Dear @_JB,

 

Had you the chance to look into this?

 

Your help is very appreciated.

 

Regards,

Thomas

0 Likes
thomashunziker
New Member
4 0 0

Dear @_JB ,

 

It would help us here a lot if you can provide an alternative way.

 

Your help is very appreciated.

 

Regards,

Thomas

0 Likes