Re: Order line items required for when payment request initiated.

Order line items required for when payment request initiated.

bhumika_dvb
Shopify Partner
3 0 0

Hi!
I've developed a payment app extension, when a payment request initiated from shopify checkout and land in to given redirect URL we need line item details to proceed. Shopify initiates an HTTP POST request to payment gateway that contains information about the customer and the order see sample request in this link https://shopify.dev/docs/apps/payments/implementation/process-a-payment/offsite


Obviously, no line items are included in the request, and that is what the payment gateway requires before it can redirect to the payment gateway page. How can I get the order line items?

Replies 3 (3)

dctechnolabs
Excursionist
11 2 3

Hi @bhumika_dvb,

When Shopify initiates a payment request and redirects to your payment gateway, it doesn't include order line items in the HTTP POST request by default. To solve this issue, you can retrieve the order details, including line items, through Shopify's API.

 

Here's how you can get the order line items:
1. Use Shopify’s Admin API: Once Shopify triggers the redirect to your payment gateway, you can use the Shopify Admin API to fetch the order details, including the line items.

You can make a GET request to the orders endpoint using the order ID that is included in the initial request from Shopify.

Example request:

GET /admin/api/2023-01/orders/{order_id}.json

This will return all the details of the order, including the line items. In the response, you'll find a line_items array with all the product details.

 

Example response:

{
  "order": {
    "id": 123456789,
    "line_items": [
      {
        "id": 987654321,
        "variant_id": 123456,
        "quantity": 2,
        "price": "19.99",
        "title": "Product Name",
        "sku": "ABC123"
      }
    ]
  }
}

Ensure You Have API Permissions: Make sure that your payment app has the necessary API permissions to access order details. You may need read_orders permissions to fetch order details.

 

Handle the Delay: Since there may be a short delay between when the payment request is initiated and when you fetch the order details, ensure that your payment app can handle this latency. You might want to check if the order exists and retry if necessary.

 

This approach should allow you to get the order line items after the payment request is initiated and send them to the payment gateway.

Let me know if you need more details or further help!

Ashish Ezhava | Founder & Business Development Manager
DC technolabs
Empowering businesses with cutting-edge technology solutions.
Visit us: dctechnolabs.com
bhumika_dvb
Shopify Partner
3 0 0
Hello,

When payment request initiated and before payment mutation called how to fetch checkout line items ?

And after payment mutation call when payment is marked as paid and order created in retailer side, how to identify that order from the order list? Because in payment mutation response we are not getting any order id.

Paymentsessionresolve mutation return response like below. In this response we are unable to fetch order id, so how to identify order from order list.

{
"data": {
"paymentSessionResolve": {
"paymentSession": {
"id": "",
"nextAction": {
"action": "REDIRECT",
"context": {
"redirectUrl": ""
}
}
},
"userErrors": []
}
},
"extensions": {
"cost": {
"requestedQueryCost": 12,
"actualQueryCost": 12,
"throttleStatus": {
"maximumAvailable": 1092000.0,
"currentlyAvailable": 1091988,
"restoreRate": 54600.0
}
}
}
}

Thanks,
Bhumika

Bhumika Sohaliya
Developer
www.zopa.com



DISCLAIMER

Zopa Limited is authorised and regulated by the Financial Conduct Authority,
and entered on the Financial Services Register under firm registration number
(718925). Zopa Bank Limited is authorised by the Prudential Regulation Authority
and regulated by the Financial Conduct Authority and the Prudential Regulation
Authority, and entered on the Financial Services Register (800542).

Registered Office: Zopa Limited (05197592) and Zopa Bank Limited
(10627575) are both incorporated in England & Wales and have their
registered office at: 1st Floor, Cottons Centre, Tooley Street, London, SE1 2QG.
dodod
Shopify Partner
1 0 0

Hi Bhumika,
After the order is created you can use payment ID that you received from Shopify in the very beginning and run and Admin GraphQL API query to obtain order ID and corresponding line items:
query {
  orders(first: 1, query:"payment_id:your_paymnet_id_here") {
    nodes {
      id
      name
      lineItems(first:20) {
        edges {
          node {
            id
            name
          }
        }
      }
    }
  }
}