Properties missing from Transaction GraphQL

New Member
12 0 0

Hi.

 

We have switched from Rest API to GraphQL.

 

On the Transaction for order the receipts field is missing. We need this to get the payment reference so we can match against the export from our payment gateways.

 

receipt is included on the Transaction in Rest Api, but not in GraphQL.

 

How can we get this property ?

0 Likes
Highlighted
Shopify Partner
38 4 4

The field your looking for is in the transactions.

 

{
  order(id: "") {
    transactions(first: 10) {
      receipt
    }
  }
}
0 Likes
Highlighted
New Member
12 0 0

Thanks.

 

It was not listed in the documentation......

 

But I cannot undersstand how to parse the returned data.

 

It returns something like this (not all data because of privacy):

 

{\"id\"=>177793221, \"merchant_id\"=>10630, \"order_id\"=>\"c12034637004864.1\", \"accepted\"=>true, \"type\"=>\"Payment\", \"text_on_statement\"=>nil, \"branding_id\"=>nil, \"variables\"=>{}, \"currency\"=>\"NOK\"
0 Likes
Highlighted
Shopify Partner
38 4 4

Assuming you are using Ruby and from that output you've got a hash. If that is the string you are getting from whatever source the following example shows parsing it in IRB:

 

irb(main):001:0> h = eval "{\"id\"=>177793221, \"merchant_id\"=>10630, \"order_id\"=>\"c12034637004864.1\", \"accepted\"=>true, \"type\"=>\"Payment\", \"text_on_statement\"=>nil, \"branding_id\"=>nil, \"variables\"=>{}, \"currency\"=>\"NOK\"}"
=> {"id"=>177793221, "merchant_id"=>10630, "order_id"=>"c12034637004864.1", "accepted"=>true, "type"=>"Payment", "text_on_statement"=>nil, "branding_id"=>nil, "variables"=>{}, "currency"=>"NOK"}
irb(main):002:0> h['id']
=> 177793221
irb(main):003:0> h['currency']
=> "NOK"
irb(main):004:0>
0 Likes
Highlighted
New Member
12 0 0

Thanks for the info.

 

We are using C#. We found a way around it. It's close to json, so we replaced the => with : and it seems to work.

 

But maybe there is a better way in C# ?

0 Likes
Highlighted
Shopify Partner
38 4 4

I'm not sure from the C# side. The response I get from Shopify GQL is in JSON so I'm not sure how that response got formatted to a valid Ruby hash object.

0 Likes
Highlighted
New Member
12 0 0

The same happens in Shopify GraphiQL app:

 

{
  orders(first: 1) {
    edges {
      node {
        id
        transactions {
          accountNumber
          receipt
        }
      }
    }
  }
}

Returns (i have removed most of the receipt for security reasons):

 

{
  "data": {
    "orders": {
      "edges": [
        {
          "node": {
            "id": "gid://shopify/Order/261361239",
            "transactions": [
              {
                "accountNumber": "",
                "receipt": "{\"timestamp\"=>\"2014-07-09T18:34:47Z\", \"ack\"=>\"Success\", \"correlation_id\"=>\"2f1d3fbf83cf7\", \"version\"=>\"72\", \"build\"=>\"11811513\""}"
              }
            ]
          }
        }
      ]
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 4,
      "actualQueryCost": 4,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 996,
        "restoreRate": 50
      }
    }
  }
}

 

 

 

 

0 Likes
Highlighted
Shopify Partner
38 4 4

So that looks like if the receipt object there were internally represented as a Ruby hash that called .to_s and used that value as that for the receipt field as a raw string response. Bug maybe, certainly not what you would expect.

 

irb(main):001:0> receipt_string = "{\"timestamp\"=>\"2014-07-09T18:34:47Z\", \"ack\"=>\"Success\", \"correlation_id\"=>\"2f1d3fbf83cf7\", \"version\"=>\"72\", \"build\"=>\"11811513\"}"
=> "{\"timestamp\"=>\"2014-07-09T18:34:47Z\", \"ack\"=>\"Success\", \"correlation_id\"=>\"2f1d3fbf83cf7\", \"version\"=>\"72\", \"build\"=>\"11811513\"}"
irb(main):002:0> receipt_hash = eval(receipt_string)
=> {"timestamp"=>"2014-07-09T18:34:47Z", "ack"=>"Success", "correlation_id"=>"2f1d3fbf83cf7", "version"=>"72", "build"=>"11811513"}
irb(main):003:0> receipt_hash.to_s == receipt_string
=> true

 

 

0 Likes