Shopify Order の決済方法を取得する方法 [Shopify GraphQL API 編]

Shopify Order の決済方法を Shopify GraphQL API で取得する方法をご紹介します。

shopify

背景 Shopify で利用された決済方法を知りたい

Shopify で利用された決済方法を Shopify API 経由で取得したいというのが本記事のテーマです。

決済方法の例)

  • クレジットカードのブランド (Visa、Mastercard、American Express、JCB)
  • Apple Pay, Google Pay
  • Amazon Pay
  • PayPal

Shopify Order の決済方法を取得する GraphQL クエリと実行結果

Shopify Community で質問してみるとすぐに回答をいただけました。有り難い。

Solved: How to get the detailed payment method when using Shopify Payments via Shopify GraphQL API – Shopify Community

GraphQL クエリ

{
  order(id: "gid://shopify/Order/3928604967067") {
    paymentGatewayNames
    transactions(first:10) {
      id
      accountNumber
      formattedGateway
      paymentMethod
      paymentIcon {
        altText
      }
    }
  }
}

実行結果

{
  "data": {
    "order": {
      "paymentGatewayNames": [
        "shopify_payments"
      ],
      "transactions": [
        {
          "id": "gid://shopify/OrderTransaction/4886496805019",
          "accountNumber": "•••• •••• •••• 1111",
          "formattedGateway": "Shopify Payments",
          "paymentMethod": "VISA",
          "paymentIcon": {
            "altText": "Visa"
          }
        }
      ]
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 3,
      "actualQueryCost": 3,
      "throttleStatus": {
        "maximumAvailable": 2000,
        "currentlyAvailable": 1997,
        "restoreRate": 100
      }
    }
  }
}

以上、Shopify Order の決済方法を Shopify GraphQL API で取得したい、現場からお送りしました。