🧑‍🏫

【Shopify.dev和訳】API Examples/Orders

2021/09/18に公開

この記事について

この記事は、API Examples/Ordersの記事を和訳したものです。

記事内で使用する画像は、公式ドキュメント内の画像を引用して使用させていただいております。

Shopify アプリのご紹介

Shopify アプリである、「商品ページ発売予告アプリ | リテリア Coming Soon」は、商品ページを買えない状態のまま、発売日時の予告をすることができるアプリです。Shopify で Coming Soon 機能を実現することができます。

https://apps.shopify.com/shopify-application-314?locale=ja&from=daniel

Shopify アプリである、「らくらく日本語フォント設定|リテリア Font Picker」は、ノーコードで日本語フォントを使用できるアプリです。日本語フォントを導入することでブランドを演出することができます。

https://apps.shopify.com/font-picker-1?locale=ja&from=daniel

注文の編集

AdminAPI を使用して既存の注文を編集する

アプリは、Shopify チャネルによって作成された注文(POS、オンラインストア、ドラフト注文など)、またはアプリが API を介して作成した注文を編集できます。

このガイドでは、GraphQL AdminAPI を使用して既存の注文を編集する方法について説明します。たとえば、顧客の注文に新しいアイテムを追加したり、ラインアイテムの数量を変更したりできます。


使い方

GraphQL Admin API を使用した注文の編集は、begin ミューテーション、一連の編集、最後にコミットという新しいパターンに従います。orderEditBeginミューテーションでは、オーダーに加えたい編集を追跡するCalculatedOrderオブジェクトが作成されます。変更内容が満足のいくものであれば、orderEditCommitミューテーションで変更内容をオーダーにコミットします。

注文編集ミューテーションとオブジェクトの詳細については、GraphQL Admin API リファレンスを参照してください。

注文の編集の種類

注文に対して次の編集を行うことができます。

  • 新しいバリアントラインアイテムを追加します
  • 新しいカスタムラインアイテムを追加する
  • 広告申込情報を削除する
  • 広告申込情報の数量を変更する

満たされていないラインアイテムのみを編集できます。編集によって注文総額が変更された場合、差額を顧客から収集するか、顧客に返金する必要がある場合があります。orderEditCommitミューテーションを使用して、顧客に請求書を送信することができます。この請求書を使用して、顧客は未払い金を支払い、注文を完了することができます(ドラフト注文の完了に似ています)。


アクセススコープ

GraphQL Admin API を使って注文を編集するには、アプリが Shopify ストアのwrite_order_editsアクセススコープを要求する必要があります。
アプリのインストール時にアクセススコープを要求する方法の詳細については、OAuthを参照してください。


注文編集を開始します

orderEditBeginミューテーションは、順序を編集するための最初のステップです。注文の ID をミューテーションに渡し、CalculatedOrder オブジェクトの ID を戻りフィールドとして要求します。CalculationdOrder オブジェクトは、orderEditCommitミューテーションを使用して編集をコミットする準備ができるまで、編集を追跡します。

Mutation
mutation beginEdit{
 orderEditBegin(id: "gid://shopify/Order/1234"){
    calculatedOrder{
      id
    }
  }
}
JSON response
{
  "data": {
    "calculatedOrder": {
      "id": "gid://shopify/CalculatedOrder/5678"
    }
  }
}

注文を編集する

これで、CalculatedOrder オブジェクト ID が得られたので、次のように注文を編集します。

新しいバリアントを追加します

orderEditAddVariantミューテーションを使用して、数量 3 の新しい製品バリアントを注文に追加できます。ミューテーションの入力として、CalculatedOrder オブジェクト ID、バリアント ID、およびバリアント数量を含めます。addedLineItemsフィールドを使用して追加されたラインアイテムの ID を要求し、バリアントが正しく追加されたことを確認します。

Mutation
mutation addVariantToOrder{
  orderEditAddVariant(id: "gid://shopify/CalculatedOrder/5678", variantId: "gid://shopify/ProductVariant/19523055845398", quantity: 1){
    calculatedOrder {
      id
      addedLineItems(first:5) {
        edges {
          node {
            id
            quantity
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}
JSON response
{
  "data": {
    "calculatedOrder": {
      "id": "gid://shopify/CalculatedOrder/5678",
      "addedLineItems": {
        "edges": [
          {
            "node": {
              "id": "gid://shopify/CalculatedLineItems/121314",
              "quantity": 3
            }
          }
        ]
      }
    },
    "userErrors": []
  }
}

バリアントに割引を追加する

orderEditAddLineItemDiscountミューテーションは、固定額またはパーセンテージの割引をラインアイテムに追加します。CalculatedOrderオブジェクト ID、ラインアイテム ID、OrderEditAppliedDiscountInputの入力をミューテーションの入力として含めます。

Mutation
mutation addDiscount {
  orderEditAddLineItemDiscount(id: "gid://shopify/CalculatedOrder/5678", lineItemId: "gid://shopify/CalculatedLineItem/121314", discount: {percentValue: 20, description: "Upsell"}) {
    calculatedOrder {
      id
      addedLineItems(first:5) {
        edges {
          node {
            id
            quantity
          }
        }
      }
    }
    userErrors {
      message
    }
  }
}
JSON response
{
  "data": {
    "calculatedOrder": {
      "id": "gid://shopify/CalculatedOrder/5678",
      "addedLineItems": {
        "edges": [
          {
            "node": {
              "id": "gid://shopify/CalculatedLineItem/151617",
              "quantity": 2
            }
          }
        ]
      }
    },
    "userErrors": []
  }
}

バリアントから割引を削除する

orderEditRemoveLineItemDiscountミューテーションは固定額またはパーセンテージの割引をラインアイテムから削除します。CalculatedOrderオブジェクト ID とdiscountApplicationIdをミューテーションの入力として含めます。

Mutation
mutation removeDiscount {
  orderEditRemoveLineItemDiscount(id: "gid://shopify/CalculatedOrder/5678", discountApplicationId: "gid://shopify/CalculatedDiscountApplication/134243") {
    userErrors {
      field
      message
    }
  }
}
JSON response
{
  "data": {
    "orderEditRemoveLineItemDiscount": {
      "userErrors": []
    }
  }
}

カスタムラインアイテムを追加する

ギフトラッピングの注文にカスタムラインアイテムを追加します。入力に、CalculatedOrder ID、ラインアイテムのタイトル、数量、および価格をorderEditAddCustomItemフィールドに含めます。レスポンスで、追加されたラインアイテムの ID、タイトル、および数量を要求して、正しく追加されたことを確認します。

Mutation
mutation addCustomItemToOrder {
  orderEditAddCustomItem(id: "gid://shopify/CalculatedOrder/19300374", title: "Custom Line Item", quantity: 1, price: {amount: 40.00, currencyCode: CAD}) {
    calculatedOrder {
      id
      addedLineItems(first: 5) {
        edges {
          node {
            id
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}
JSON response
{
  "data": {
    "calculatedOrder": {
      "id": "gid://shopify/CalculatedOrder/5678",
      "addedLineItems": {
        "edges": [
          {
            "node": {
              "id": "gid://shopify/CalculatedLineItem/121314",
              "title": "Shopify socks",
              "quantity": 4
            }
          },
          {
            "node": {
              "id": "gid://shopify/CalculatedLineItem/151617",
              "title": "Gift wrapping service",
              "quantity": 1
            }
          }
        ]
      }
    },
    "userErrors": []
  }
}

ラインアイテムの数量を編集する

注文にギフトラッピングサービスを追加するために、orderEditSetQuantityミューテーションを使用してラインアイテムの数量を調整します。入力には、注文idlineItemId、設定したい新しいquantityの値を入れます。レスポンスで、ラインアイテムの ID と数量を要求して、正しく更新されたことを確認します。

Mutation
mutation increaseLineItemQuantity {
  orderEditSetQuantity(id: "gid://shopify/CalculatedOrder/19300374", lineItemId: "gid://shopify/CalculatedLineItem/2941798776854", quantity: 2) {
    calculatedOrder {
      id
      addedLineItems(first: 5) {
        edges {
          node {
            id
            quantity
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}
JSON response
{
  "data": {
    "calculatedOrder": {
      "id": "gid://shopify/CalculatedOrder/5678",
      "addedLineItems": {
        "edges": [
          {
            "node": {
              "id": "gid://shopify/CalculatedLineItem/151617",
              "quantity": 2
            }
          }
        ]
      }
    },
    "userErrors": []
  }
}

注文編集をコミットする

注文への変更をコミットします。orderEditCommitミューテーションは、CalculatedOrderオブジェクトによって追跡された変更をオーダーにコミットします。入力には、CalculatedOrderオブジェクト ID、false に設定されたnotifyCustomerフィールド、およびstaffNoteを含めます。notifyCustomerが true に設定されている場合、更新された注文情報を含む請求書メールが顧客に送信されます。

Mutation
mutation commitEdit {
  orderEditCommit(id: "gid://shopify/CalculatedOrder/19300374", notifyCustomer: false, staffNote: "I edited the order! It was me!") {
    order {
      id
    }
    userErrors {
      field
      message
    }
  }
}
JSON response
{
  "data": {
    "order": {
      "id": "gid://shopify/Order/1234"
    }
  },
  "userErrors": []
}

編集した webhook を注文する

orders/editedwebhook をサブスクライブして、注文が編集されたときに通知を受け取ります。webhook は、注文の編集が完了するたびにトリガーされます。


追加情報


販売データ

注文から販売データを取得する

マーチャントは、Shopify エコシステム全体で正確な注文データを必要とします。これにより、売上の報告、アカウントの調整、および税法の適用ができます。GraphQL Admin API を使用すると、売上データにアクセスして、注文の売上関連の変更を詳細に項目別に表示し、監査目的で使用することができます。

このチュートリアルでは、次のことを行います。

  • Shopify がどのように注文の売上データを管理しているか、その背後にある概念を紹介しています。
  • 販売データをクエリするためのいくつかの一般的なタスクを実行する方法を示します。

販売契約と販売

販売契約は、商人と顧客の間でビジネスを行うための契約です。Shopify は、注文、編集、または返金が行われるたびに販売契約を作成します。販売契約には、最初の契約または注文に加えられたその後の変更に関する項目別の詳細を提供する 1 つ以上の販売記録があります。

たとえば、顧客が注文すると、Shopify は注文を作成して販売契約を生成し、注文で購入された各ラインアイテムの販売を記録します。販売記録は、注文明細のタイプに固有です。注文明細は、購入した商品、顧客が追加したヒント、チェックアウト時に徴収された送料など、さまざまなものを表すことができます。

返品できる販売契約は次のとおりです。

返品できる販売タイプは次のとおりです。


売上調整

販売可能な注文明細タイプの 1 つは、調整です。売上調整は、あるラインアイテムに対して、そのラインアイテムの合計金額よりも多い、または少ない金額の返金が行われた場合に発生します。例としては、返品手数料やのれん代の支払いがあります。

これが発生すると、Shopify は、返品または返金される各ラインアイテムの販売記録と、調整のための追加の販売記録(返品手数料など)を含む販売契約を作成します。

返品または返金されたアイテムの販売記録は、元のラインアイテムの販売額の取り消しを表します。追加調整販売記録は、返金されたすべてのラインアイテムの元の合計値と実際に返金された金額との差を表します。


丸め

注文の販売データのすべての貨幣価値は、通貨の最小単位で表されます。

税金や注文割引など、特定の金額を複数のラインアイテムに分割する場合、金額が注文のすべてのラインアイテムに均等に分割されない場合があります。

これに対処するために、均等に分割できなかった残りの通貨単位は、最初の項目から始めて、余ったすべての通貨単位が分配されるまで、1 つずつ割り当てられます。全体として、値は正しく合計されます。あるラインアイテムが同じ価格(税および割引前)の別のラインアイテムとは異なる税額または割引額を持つ場合があります。これは、金額をアイテム間で均等に分割できないためです。

ラインアイテム間での通貨単位の割り当ては不変です。それらが割り当てられた後、通貨単位がラインアイテム間で再割り当てまたは再配分されることはありません。


要件


利用可能なフィールド

次の例は、注文履歴データをクエリするために使用できるすべてのフィールドを示しています。

query {
  order(id: "gid://shopify/Order/123456789") {
    id
    agreements(first: 1) {
      edges {
        node {
          id
          happenedAt
          app {
            id
          }
          user {
            id
          }
          ... on RefundAgreement {
            refund {
              id
            }
          }
          sales(first: 1) {
            edges {
              node {
                id
                actionType
                lineType
                quantity
                ... on ProductSale {
                  lineItem {
                    id
                  }
                }
                ... on GiftCardSale {
                  lineItem {
                    id
                  }
                }
                ... on TipSale {
                  lineItem {
                    id
                  }
                }
                ... on ShippingLineSale {
                  shippingLine {
                    id
                  }
                }
                ... on DutySale {
                  duty {
                    price {
                      shopMoney {
                        amount
                      }
                    }
                  }
                }
                totalAmount {
                  shopMoney {
                    amount
                  }
                }
                totalTaxAmount {
                  shopMoney {
                    amount
                  }
                }
                totalDiscountAmountBeforeTaxes {
                  shopMoney {
                    amount
                  }
                }
                totalDiscountAmountAfterTaxes {
                  shopMoney {
                    amount
                  }
                }
                taxes {
                  id
                  amount {
                    shopMoney {
                      amount
                    }
                  }
                  taxLine {
                    title
                  }
                }
              }
              cursor
            }
            pageInfo {
              hasNextPage
            }
          }
        }
        cursor
      }
      pageInfo {
        hasNextPage
        hasPreviousPage
      }
    }
  }
}

1.注文の販売契約を取得します

注文の販売契約を取得するには、orderフィールドにクエリを実行して、注文のagreementsフィールドを要求します。

次の例は、注文の最初の 10 件の販売契約を取得する方法を示しています。取得する結果のセットの選択については、GraphQL を使用した結果のページ付けを参照してください。

レスポンスボディは、注文の最初の販売契約と 3 つの対応する販売記録を返します。2 つのレコードはProductSaleで、特定の製品販売のラインアイテムを表します。1 つのレコードはShippingLineSaleで、配送料のラインアイテムを表します。

Query:POST /api/2021-07/graphql.json

query {
  order(id: "gid://shopify/Order/3949557088312") {
    agreements(first: 10) {
      edges {
        node {
          id
          happenedAt
          sales(first: 10) {
            edges {
              node {
                actionType
                lineType
                quantity
                totalAmount {
                  shopMoney {
                    amount
                  }
                }
                ... on ProductSale {
                  lineItem {
                    id
                    name
                  }
                }
                ... on ShippingLineSale {
                  shippingLine {
                    id
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
応答を表示/非表示
JSON response
{
  "data": {
    "order": {
      "agreements": {
        "edges": [
          {
            "node": {
              "id": "gid://shopify/SalesAgreement/4291552739384",
              "happenedAt": "2021-06-02T18:13:14Z",
              "sales": {
                "edges": [
                  {
                    "node": {
                      "actionType": "ORDER",
                      "lineType": "PRODUCT",
                      "quantity": 2,
                      "totalAmount": {
                        "shopMoney": {
                          "amount": "10.0"
                        }
                      },
                      "lineItem": {
                        "id": "gid://shopify/LineItem/10487437033528",
                        "name": "T-shirt - small"
                      }
                    }
                  },
                  {
                    "node": {
                      "actionType": "ORDER",
                      "lineType": "PRODUCT",
                      "quantity": 1,
                      "totalAmount": {
                        "shopMoney": {
                          "amount": "20.0"
                        }
                      },
                      "lineItem": {
                        "id": "gid://shopify/LineItem/10487437066296",
                        "name": "Jeans - long"
                      }
                    }
                  },
                  {
                    "node": {
                      "actionType": "ORDER",
                      "lineType": "SHIPPING",
                      "quantity": null,
                      "totalAmount": {
                        "shopMoney": {
                          "amount": "15.0"
                        }
                      },
                      "shippingLine": {
                        "id": "gid://shopify/ShippingLine/63437432064256"
                      }
                    }
                  }
                ]
              }
            }
          }
        ]
      }
    }
  }
}

2.注文編集のための販売契約を取得します

次の例では、注文編集の販売契約を取得します。ここでは、購入した 1 つの製品が、同じ価格の製品バリアントと引き換えに返品されます。

応答には、注文の編集のために新しく追加された販売契約が含まれます。応答には、2 つの固有の販売記録が含まれています。返品された製品は"quantity": -1で示されます。2 行目は、交換で注文された製品バリアントを表しています。

Query:POST /api/2021-07/graphql.json

query {
  order(id: "gid://shopify/Order/3949557088312") {
    agreements(first: 10) {
      edges {
        node {
          id
          happenedAt
          sales(first: 10) {
            edges {
              node {
                actionType
                lineType
                quantity
                totalAmount {
                  shopMoney {
                    amount
                  }
                }
                ... on ProductSale {
                  lineItem {
                    id
                    name
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
応答を表示/非表示
JSON response
{
  "data": {
    "order": {
      "agreements": {
        "edges": [
          {
            "node": {...}
          },
          # Newly-added agreement from order edit
          {
            "node": {
              "id": "gid://shopify/SalesAgreement/4291553722424",
              "happenedAt": "2021-06-02T18:23:58Z",
              "sales": {
                "edges": [
                  {
                    "node": {
                      "actionType": "ORDER",
                      "lineType": "PRODUCT",
                      "quantity": 1,
                      "totalAmount": {
                        "shopMoney": {
                          "amount": "20.0"
                        }
                      },
                      "lineItem": {
                        "id": "gid://shopify/LineItem/10487439425592",
                        "name": "Jeans - short"
                      }
                    }
                  },
                  {
                    "node": {
                      "actionType": "RETURN",
                      "lineType": "PRODUCT",
                      "quantity": -1,
                      "totalAmount": {
                        "shopMoney": {
                          "amount": "-20.0"
                        }
                      },
                      "lineItem": {
                        "id": "gid://shopify/LineItem/10487437066296",
                        "name": "Jeans - long"
                      }
                    }
                  }
                ]
              }
            }
          }
        ]
      }
    }
  }
}

3.販売調整を取得します

払い戻しの金額が返品されたアイテムの元の販売金額と一致しない可能性がある場合は、注文の販売調整を取得できます。

次の例では、商品が返品され、販売者は 1 米ドルの返品手数料を請求します。払い戻しが処理された後、前の例の 3 つに加えて、新しい 2 つの販売記録を持つ新しい販売契約が生成されます。最初の注文ラインは元の価格での製品の返品を表し、2 番目の注文ラインは返品手数料のコストを表します。
Query:POST /api/2021-07/graphql.json

query {
  order(id: "gid://shopify/Order/3949557088312") {
    agreements(first: 10) {
      edges {
        node {
          id
          happenedAt
          sales(first: 10) {
            edges {
              node {
                actionType
                lineType
                quantity
                totalAmount {
                  shopMoney {
                    amount
                  }
                }
                ... on ProductSale {
                  lineItem {
                    id
                    name
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
応答を表示/非表示
JSON response
{
  "data": {
    "order": {
      "agreements": {
        "edges": [
          {...},
          {...},
          {...},
          # Newly-added agreement from partial refund with restock fee
          {
            "node": {
              "id": "gid://shopify/SalesAgreement/4291555000376",
              "happenedAt": "2021-06-02T18:31:57Z",
              "sales": {
                "edges": [
                  {
                    "node": {
                      "actionType": "RETURN",
                      "lineType": "ADJUSTMENT",
                      "quantity": null,
                      "totalAmount": {
                        "shopMoney": {
                          "amount": "1.0"
                        }
                      }
                    }
                  },
                  {
                    "node": {
                      "actionType": "RETURN",
                      "lineType": "PRODUCT",
                      "quantity": -1,
                      "totalAmount": {
                        "shopMoney": {
                          "amount": "-5.0"
                        }
                      },
                      "lineItem": {
                        "id": "gid://shopify/LineItem/10487437033528",
                        "name": "T-shirt - small"
                      }
                    }
                  }
                ]
              }
            }
          }
        ]
      }
    }
  }
}

テストオーダー

REST AdminAPI を使用してテスト注文を管理する

REST Admin API を使用して、アプリの動作を検証するためのテストオーダーとトランザクションを作成できます。

プラットフォーム料金を回避するには、注文をテストするための次の推奨ワークフローに従います。

  1. 承認されたトランザクションで注文を作成します。
  2. トランザクションをキャプチャするときに親 ID として使用するトランザクション ID を取得します。
  3. トランザクションをキャプチャし、注文のtestプロパティをtrueに設定します。

手動支払いゲートウェイや代金引換支払い方法などの他の方法では、テストオーダーは作成されず、プラットフォーム料金がかかります。


始める前に

このガイドを理解するためには、注文トランザクションの概念を理解しておくとよいでしょう。トランザクションは注文に関連付けられており、金銭のやり取りが行われるたびに発生します。トランザクションは支払いプロバイダーによって処理され、発行者アカウント(顧客のクレジットカード)から取得者(マーチャントの銀行口座)への送金が行われます。詳細については、「支払いを受ける」を参照してください。


注文を作成する

注文をテストするには、POST リクエストをOrderリソースに送信して、承認トランザクションで注文を作成します。transactionsリクエストの本文にオブジェクトを含めます。

POSThttps://{shop}.myshopify.com/admin/api/2021-07/orders.json

{
  "order": {
    "email": " ",
    "financial_status": "pending",
    "line_items": [
      {
        "title": "Big Brown Bear Boots",
        "price": 100,
        "grams": "1300",
        "quantity": 2,
        "tax_lines": [
          {
            "price": 13.5,
            "rate": 0.06,
            "title": "State tax"
          }
        ]
      }
    ],
    "transactions": [
      {
        "kind": "authorization",
        "status": "success",
        "amount": 200
      }
    ]
  }
}
応答を表示/非表示
JSON response
{
  "order": {
    "id": 1165756760120,
    "email": "",
    "closed_at": null,
    "created_at": "2019-04-03T17:39:55-04:00",
    "updated_at": "2019-04-03T17:39:55-04:00",
    "number": 90,
    "note": null,
    "token": "07867cf3c1b2508b4310adaf9fce9ba9",
    "gateway": "",
    "test": false,
    "total_price": "200.00",
    "subtotal_price": "200.00",
    "total_weight": 0,
    "total_tax": "0.00",
    "taxes_included": false,
    "currency": "USD",
    "financial_status": "pending",
    "confirmed": true,
    "total_discounts": "0.00",
    "total_line_items_price": "200.00",
    "cart_token": null,
    "buyer_accepts_marketing": false,
    "name": "#1090",
    "referring_site": null,
    "landing_site": null,
    "cancelled_at": null,
    "cancel_reason": null,
    "total_price_usd": "200.00",
    "checkout_token": null,
    "reference": null,
    "user_id": null,
    "location_id": null,
    "source_identifier": null,
    "source_url": null,
    "processed_at": "2019-04-03T17:39:55-04:00",
    "device_id": null,
    "phone": null,
    "customer_locale": null,
    "app_id": 2802623,
    "browser_ip": null,
    "landing_site_ref": null,
    "order_number": 1090,
    "discount_applications": [],
    "discount_codes": [],
    "note_attributes": [],
    "payment_gateway_names": [
      ""
    ],
    "processing_method": "",
    "checkout_id": null,
    "source_name": "2802623",
    "fulfillment_status": null,
    "tax_lines": [
      {
        "price": "13.50",
        "rate": 0.06,
        "title": "State tax",
        "price_set": {
          "shop_money": {
            "amount": "13.50",
            "currency_code": "USD"
          },
          "presentment_money": {
            "amount": "13.50",
            "currency_code": "USD"
          }
        }
      }
    ],
    ...
  }
}

トランザクション ID を取得する

注文を作成すると、返される Order オブジェクトに ID が含まれます。その後、注文 ID を使用して、トランザクションとその ID を返すことができます。トランザクションを取得するには、GET リクエストをOrderTransactionリソースに送信します。

GEThttps://{shop}.myshopify.com/admin/api/2021-07/orders/{order_id}/transactions.json

応答を表示/非表示
JSON response
{
  "transactions": [
    {
      "id": 1458851250232,
      "order_id": 1165756760120,
      "kind": "authorization",
      "gateway": "",
      "status": "success",
      "message": null,
      "created_at": "2019-04-03T17:39:55-04:00",
      "test": false,
      "authorization": null,
      "location_id": null,
      "user_id": null,
      "parent_id": null,
      "processed_at": "2019-04-03T17:39:55-04:00",
      "device_id": null,
      "receipt": {},
      "error_code": null,
      "source_name": "2802623",
      "amount": "200.00",
      "currency": "USD",
      "admin_graphql_api_id": "gid://shopify/OrderTransaction/1458851250232"
    }
  ]
}

トランザクションをキャプチャします

トランザクションを返した後、その ID を使用して、支払いをキャプチャするためのキャプチャトランザクションを作成できます。キャプチャトランザクションを作成するには、POST リクエストの本文にある Transaction オブジェクトを、承認のトランザクション ID をparent_idとして注文トランザクションリソースに送信し、testプロパティを true に設定します。

POSThttps://{shop}.myshopify.com/admin/api/2021-07/orders/{order_id}/transactions.json

{
  "transaction": {
    "currency": "USD",
    "amount": "200.00",
    "kind": "capture",
    "parent_id": 1458851250232,
    "test": "true"
  }
}
応答を表示/非表示
JSON response
{
  "transaction": {
    "id": 1458851708984,
    "order_id": 1165756760120,
    "kind": "capture",
    "gateway": "",
    "status": "success",
    "message": "Marked the payment as received",
    "created_at": "2019-04-03T17:49:07-04:00",
    "test": true,
    "authorization": null,
    "location_id": null,
    "user_id": null,
    "parent_id": 1458851250232,
    "processed_at": "2019-04-03T17:49:07-04:00",
    "device_id": null,
    "receipt": {},
    "error_code": null,
    "source_name": "2802623",
    "amount": "200.00",
    "currency": "USD",
    "admin_graphql_api_id": "gid://shopify/OrderTransaction/1458851708984"
  }
}

テストの順序を確認する

上記の手順を実行した後、注文を取得して、テストモードになっていることを確認できます。注文がテストオーダーの場合、レスポンスにはtrueに設定されたtestプロパティが含まれます。

GEThttps://{shop}.myshopify.com/admin/api/2021-07/orders/{order_id}.json

応答を表示/非表示
JSON response
{
  "order": {
    "id": 1165756760120,
    "email": "",
    "closed_at": null,
    "created_at": "2019-04-03T17:39:55-04:00",
    "updated_at": "2019-04-03T17:49:07-04:00",
    "number": 90,
    "note": null,
    "token": "07867cf3c1b2508b4310adaf9fce9ba9",
    "gateway": "",
    "test": true,
    ...
  }
}

Shopify アプリのご紹介

Shopify アプリである、「商品ページ発売予告アプリ | リテリア Coming Soon」は、商品ページを買えない状態のまま、発売日時の予告をすることができるアプリです。Shopify で Coming Soon 機能を実現することができます。

https://apps.shopify.com/shopify-application-314?locale=ja&from=daniel

Shopify アプリである、「らくらく日本語フォント設定|リテリア Font Picker」は、ノーコードで日本語フォントを使用できるアプリです。日本語フォントを導入することでブランドを演出することができます。

https://apps.shopify.com/font-picker-1?locale=ja&from=daniel

Discussion

ログインするとコメントできます