تنفيذ واجهة برمجة تطبيقات REST لعملية الدفع الأصلية

يقدّم هذا الدليل مرجع واجهة برمجة التطبيقات الفني ومخططات الحمولة للإصدار 2026-04-08 من ميزة الدفع المدمج في بروتوكول Universal Commerce Protocol (UCP).

قبل إنشاء نقاط النهاية، تأكَّد من مراجعة نظرة عامة حول ميزة "الدفع بدون مغادرة التطبيق" للتعرّف على مسار الدفع العام ومتطلبات المصادقة وأدوات المطوّرين.

إنشاء جلسة دفع

تتيح نقطة النهاية هذه إنشاء جلسة دفع تحتوي على المنتجات التي يريد المستخدم شراءها.

  • نقطة النهاية: POST /checkout-sessions
  • المشغّل: ينقر المستخدِم على "اشترِ الآن" على منتج أو على "الدفع على Google" من سلة التسوّق.

الطلب: ترسل Google عناصر الطلب ومعلومات محدودة عن عنوان المشتري، بما في ذلك المدينة والولاية والرمز البريدي.

// Request Example: Create checkout with multiple items.
{
  "line_items": [
    {
      "item": {
        // Must match ID in product feed
        "id": "product_12345"
      },
      "quantity": 1
    },
    {
      "item": {
        // Must match ID in product feed
        "id": "product_67890"
      },
      "quantity": 1
    }
  ],
  "context": {
    "language": "en"
  },
  "fulfillment": {
    "methods": [
      {
        "type": "shipping",
        "line_item_ids": [
          "line_1",
          "line_2"
        ],
        "destinations": [
          {
            "id": "addr_1",
            "address_locality": "Sunnyvale",
            "address_region": "CA",
            "postal_code": "94089",
            "address_country": "US"
          }
        ],
        "selected_destination_id": "addr_1"
      }
    ]
  }
}

الرد: يمكنك إرجاع الجلسة التي تم إعدادها مع المبالغ الإجمالية والضرائب (المقدّرة في البداية) وإمكانات الدفع.

ملاحظة حول الحقل ucp.status:

تم تقديم الحقل ucp.status في الإصدار 2026-04-08، وهو يشير إلى نتيجة الإنشاء:

  • "success" (أو تم حذفه): القيمة التلقائية. تم إنشاء الجلسة، حتى مع وجود messages يمكن استرداده.
  • "error": تعذّر إنشاء الجلسة بسبب خطأ لا يمكن إصلاحه (على سبيل المثال، جميع السلع غير متوفرة). في هذه الحالة، يجب أن يكون نص الاستجابة عنصر استجابة خطأ، وليس عنصر دفع. اطّلِع على مثال على خطأ غير قابل للاسترداد في قسم "التعامل مع الأخطاء".

ملاحظة حول تغييرات مصفوفة totals:

  • أصبح الحقل type ضمن كل كائن في مصفوفة totals سلسلة مفتوحة.
  • يمكن أن تكون قيمة الحقل amount سالبة الآن (على سبيل المثال، لتمثيل الخصومات).
  • يمكن أن تتضمّن العناصر في totals (مثل type: "fee" وtype: "tax") اختياريًا مصفوفة lines لتفصيل المكوّنات الفرعية (مثل رسوم الخدمة أو إعادة التدوير، أو تفاصيل الضرائب الفيدرالية والمحلية المتعددة المستويات، مثل ضريبة السلع والخدمات أو ضريبة مبيعات المقاطعة أو ضريبة QST في كندا).
  • الأسعار شاملة الضرائب: في الأسواق التي تكون فيها الأسعار شاملة الضرائب، يجب أن تتضمّن السمة subtotal الضريبة، ويجب حذف عنصر السطر tax، ويجب تقديم السمة display_text بشكل صريح لإدخالات subtotal وfulfillment في totals. يمكنك الاطّلاع على الأسعار شاملة الضرائب لمعرفة التفاصيل.
// Response Example: Initialize Session with multiple items.
{
  "ucp": {
    "version": "2026-04-08",
    "status": "success",
    "capabilities": {
      "dev.ucp.shopping.checkout": [ { "version": "2026-04-08" } ],
      "dev.ucp.shopping.fulfillment": [ { "version": "2026-04-08", "extends": "dev.ucp.shopping.checkout" } ]
    },
    "payment_handlers": {
      "com.google.pay": [
        {
          "id": "8c9202bd-63cc-4241-8d24-d57ce69ea31c",
          "version": "2026-01-23",
          "spec": "https://pay.google.com/gp/p/ucp/2026-01-23/",
          "schema": "https://pay.google.com/gp/p/ucp/2026-01-23/schemas/config.json",
          "config": {
            "api_version": 2,
            "api_version_minor": 0,
            "environment": "TEST",
            "merchant_info": {
              "merchant_name": "Example Merchant",
              "merchant_id": "KWMZPRLQFTYNXSDB",
              "merchant_origin": "checkout.merchant.com"
            },
            "allowed_payment_methods": [
              {
                "type": "CARD",
                "parameters": {
                  "allowed_auth_methods": [ "PAN_ONLY", "CRYPTOGRAM_3DS" ],
                  "allowed_card_networks": [ "AMEX", "DISCOVER", "JCB", "MASTERCARD", "VISA" ],
                  "billing_address_required": true,
                  "billing_address_parameters": {
                    "format": "FULL",
                    "phone_number_required": true
                  }
                },
                "tokenization_specification": {
                  "type": "PAYMENT_GATEWAY",
                  "parameters": {
                    "gateway": "example",
                    "gatewayMerchantId": "exampleGatewayMerchantId"
                  }
                }
              }
            ]
          }
        }
      ]
    }
  },
  "id": "bf8c1b4b-6b1c-4c6a-8f2a-53c2a7c3b2e1",
  "status": "incomplete",
  "messages": [
    {
      "type": "error",
      "code": "missing_buyer_info",
      "path": "$.buyer",
      "content_type": "plain",
      "content": "Buyer information is required for checkout",
      "severity": "recoverable"
    },
    {
      "type": "error",
      "code": "missing_fulfillment_info",
      "path": "$.fulfillment.methods[0].destinations[0]",
      "content_type": "plain",
      "content": "Shipping address is incomplete",
      "severity": "recoverable"
    }
  ],
  "currency": "USD",
  "line_items": [
    {
      "id": "line_1",
      "item": {
        "id": "product_12345",
        "title": "Running Shoes",
        "price": 10000,
        "image_url": "https://merchant.example.com/images/product_12345.png"
      },
      "quantity": 1,
      "totals": [
        {
          "type": "subtotal",
          "amount": 10000
        },
        {
          "type": "total",
          "amount": 10000
        }
      ]
    },
    {
      "id": "line_2",
      "item": {
        "id": "product_67890",
        "title": "T-Shirt",
        "price": 2500,
        "image_url": "https://merchant.example.com/images/product_67890.png"
      },
      "quantity": 1,
      "totals": [
        {
          "type": "subtotal",
          "amount": 2500
        },
        {
          "type": "total",
          "amount": 2500
        }
      ]
    }
  ],
  "totals": [
    {
      "type": "subtotal",
      "display_text": "Subtotal", // Tax-inclusive markets: Set to "Subtotal (including taxes)".
      "amount": 12500 // Tax-inclusive markets: Amount must include tax.
    },
    {
      "type": "fee",
      "display_text": "Fees",
      "amount": 549,
      "lines": [
        { "display_text": "Service Fee", "amount": 399 },
        { "display_text": "Recycling Fee", "amount": 150 }
      ]
    },
    {
      "type": "fulfillment",
      "display_text": "Ground Shipping", // Tax-inclusive markets: Provide display text for fulfillment totals.
      "amount": 500
    },
    {
      "type": "tax", // Tax-inclusive markets: Omit this entry.
      "display_text": "Estimated Tax",
      "amount": 1050
    },
    {
      "type": "total",
      "display_text": "Total",
      "amount": 14599
    }
  ],
  "fulfillment": {
    "methods": [
      {
        "id": "method_shipping",
        "type": "shipping",
        "line_item_ids": [
          "line_1",
          "line_2"
        ],
        "destinations": [
          {
            "id": "addr_1",
            "address_locality": "Sunnyvale",
            "address_region": "CA",
            "postal_code": "94089",
            "address_country": "US"
          }
        ],
        "selected_destination_id": "addr_1",
        "groups": [
          {
            "id": "group_1",
            "line_item_ids": [
              "line_1",
              "line_2"
            ],
            "options": [
              {
                "id": "ship_ground",
                "title": "Ground (3-5 days)",
                "description": "Estimated Delivery: Fri 5/8", // Maximum length: 200 characters.
                "totals": [ {"type": "total", "amount": 500} ]
              },
              {
                "id": "ship_express",
                "title": "Express (1-2 days)",
                "description": "Estimated Delivery: Wed 5/6", // Maximum length: 200 characters.
                "totals": [ {"type": "total", "amount": 1500} ]
              }
            ],
            "selected_option_id": "ship_ground"
          }
        ]
      }
    ]
  },
  "links": [
    {
      "type": "terms_of_service",
      "url": "https://m.com/terms",
      "title": "Terms of Service"
    },
    {
      "type": "privacy_policy",
      "url": "https://m.com/privacy",
      "title": "Privacy Policy"
    }
  ]
}

الأسعار شاملة الضريبة

في الأسواق التي يتم فيها تضمين الضريبة في المجموع الفرعي المعروض بدلاً من تفصيله بشكل منفصل، يجب أن يتوافق التنفيذ مع المتطلبات التالية عند تقديم بيانات جلسة الدفع:

  • إدراج الضريبة في المجموع الفرعي: يجب أن يتضمّن الحقل amount الخاص بالإدخال subtotal جميع الضرائب السارية.
  • عدم تضمين إدخالات ضريبية منفصلة: لا تضمِّن عنصرًا مخصّصًا يتضمّن type: "tax" في مصفوفة totals.
  • توفير نص عرض مخصّص: يجب تضمين السمة display_text ضمن عنصر المجموع الفرعي الذي يوضّح بشكل صريح أنّ الضرائب مضمّنة، مثل "Subtotal (including taxes)". يجب أيضًا تضمين السمة display_text لإدخالات التنفيذ (مثل "Shipping").

مثال: مصفوفة الإجماليات الشاملة للضريبة

يوضّح المثال التالي مصفوفة totals لتاجر في سوق يشمل الضرائب:

"totals": [
  {
    "type": "subtotal",
    "display_text": "Subtotal (including taxes)",
    "amount": 12500
  },
  {
    "type": "fulfillment",
    "display_text": "Shipping",
    "amount": 399
  },
  {
    "type": "total",
    "display_text": "Total",
    "amount": 12899
  }
]

تفصيل الضريبة على عدة مستويات

بالنسبة إلى الأسواق التي تتطلّب إفصاحات ضريبية مفصّلة ومتعدّدة المستويات أو نطاقات السلطة (مثل ضريبة السلع والخدمات (GST) أو ضريبة المبيعات المنسَّقة (HST) الفيدرالية الكندية وضريبة مبيعات المقاطعة (PST) أو ضريبة QST الإقليمية)، يمكنك تقديم عنصر type: "tax" ذي مستوى أعلى مع مصفوفة lines متداخلة:

  • إجمالي الضريبة على المستوى الأعلى: لعرض عنصر tax مجمّع واحد يحتوي على إجمالي الضريبة amount ووصف display_text (مثلاً، "Taxes").
  • تفاصيل السطر الفرعي: قسِّم عناصر الضريبة الفردية في مصفوفة lines مع display_text (مثل "TPS / GST (5%)" و"TVQ / QST (9.975%)") وamount الخاصة بكل عنصر.
  • القاعدة الثابتة: يجب أن يساوي مجموع كل مبالغ الأسطر الفرعية مبلغ amount الخاص بإدخال tax الرئيسي.

مثال: تفاصيل الضريبة المتعددة المستويات

{
  "type": "tax",
  "display_text": "Taxes",
  "amount": 1498,
  "lines": [
    { "display_text": "TPS / GST (5%)", "amount": 500 },
    { "display_text": "TVQ / QST (9.975%)", "amount": 998 }
  ]
}

الحصول على جلسة الدفع

تتيح نقطة النهاية هذه استرداد جلسة دفع.

  • نقطة النهاية: GET /checkout-sessions/{id}

الطلب: ترسل Google معرّف جلسة الدفع. في حال استخدام المعرّفات العامة (مثل gid://merchant.example.com/Checkout/session_abc123)، يُرجى العِلم أنّ المعرّف في مسار الطلب سيكون المكوّن الأخير فقط من هذا المعرّف (مثل session_abc123).

الاستجابة: عليك إرجاع عنصر الدفع الكامل. بالنسبة إلى جلسة تتضمّن سلعًا متعدّدة تم إنشاؤها ضمن الإصدار 2026-01-23 أو إصدار أحدث، ستحتوي المصفوفة line_items على إدخالات سلع متعدّدة.

تعديل جلسة إكمال الدفع

تتيح نقطة النهاية هذه إجراء تعديلات على جلسة الدفع. عند تعديل عنوان الشحن، يجب إعادة احتساب الضرائب وخيارات الشحن وعرضها.

  • نقطة النهاية: PUT /checkout-sessions/{id}

تعديل عنوان الشحن

  • المشغّل: يختار المستخدم عنوان الشحن أو يغيّره.

الطلب: تعدّل Google عنوان التسليم عندما يغيّر المستخدم عنوان الشحن.

// Request Example: Update shipping address with multiple items.
{
  "line_items": [
    {
      // line_items id from Create Checkout response
      "id": "line_1",
      "item": {
        "id": "product_12345"
      },
      "quantity": 1
    },
    {
      // line_items id from Create Checkout response
      "id": "line_2",
      "item": {
        "id": "product_67890"
      },
      "quantity": 1
    }
  ],
  "context": {
    "language": "en"
  },
  "fulfillment": {
    "methods": [
      {
        "id": "method_shipping",
        "type": "shipping",
        "line_item_ids": [
          "line_1",
          "line_2"
        ],
        "destinations": [
          {
            "id": "addr_1",
            "address_locality": "Mountain View",
            "address_region": "CA",
            "postal_code": "94043",
            "address_country": "US"
          }
        ],
        "selected_destination_id": "addr_1",
        "groups": [
          {
            "id": "group_1",
            "selected_option_id": "ship_ground"
          }
        ]
      }
    ]
  }
}

الردّ: عليك إعادة احتساب الضرائب وخيارات الشحن حسب الحاجة، ثم إرجاع عنصر الدفع الكامل.

// Response Example: Updated session with new address for multiple items.
{
  "id": "bf8c1b4b-6b1c-4c6a-8f2a-53c2a7c3b2e1",
  "currency": "USD",
  "line_items": [
    {
      "id": "line_1",
      "item": {
        "id": "product_12345",
        "title": "Running Shoes",
        "price": 10000,
        "image_url": "https://merchant.example.com/images/product_12345.png"
      },
      "quantity": 1,
      "totals": [
        { "type": "subtotal", "amount": 10000 },
        { "type": "total", "amount": 10000 }
      ]
    },
    {
      "id": "line_2",
      "item": {
        "id": "product_67890",
        "title": "T-Shirt",
        "price": 2500,
        "image_url": "https://merchant.example.com/images/product_67890.png"
      },
      "quantity": 1,
      "totals": [
        { "type": "subtotal", "amount": 2500 },
        { "type": "total", "amount": 2500 }
      ]
    }
  ],
  "totals": [
     { "type": "subtotal", "display_text": "Subtotal", "amount": 12500 },
     // Shipping cost might change based on new address
     { "type": "fulfillment", "display_text": "Ground Shipping", "amount": 600 },
     {
       "type": "fee",
       "display_text": "Fees",
       "amount": 549,
       "lines": [
         { "display_text": "Service Fee", "amount": 399 },
         { "display_text": "Recycling Fee", "amount": 150 }
       ]
     },
     // Tax will likely change based on new address
     { "type": "tax", "display_text": "Estimated Tax", "amount": 1120 },
     { "type": "total", "display_text": "Total", "amount": 14769 }
  ],
  "fulfillment": {
    "methods": [
      {
        "id": "method_shipping",
        "type": "shipping",
        "line_item_ids": ["line_1", "line_2"],
        "selected_destination_id": "addr_1",
        "destinations": [
          {
            "id": "addr_1",
            "address_locality": "Mountain View",
            "address_region": "CA",
            "postal_code": "94043",
            "address_country": "US"
          }
        ],
        "groups": [
          {
            "id": "group_1",
            "line_item_ids": ["line_1", "line_2"],
            "selected_option_id": "ship_ground",
            "options": [
              {
                "id": "ship_ground",
                "title": "Ground (3-5 days)",
                "description": "Estimated Delivery: Fri 5/8", // Maximum length: 200 characters.
                "totals": [ { "type": "total", "amount": 600 } ]
              },
              {
                "id": "ship_express",
                "title": "Express (1-2 days)",
                "description": "Estimated Delivery: Wed 5/6", // Maximum length: 200 characters.
                "totals": [ { "type": "total", "amount": 1600 } ]
              }
            ]
          }
        ]
      }
    ]
  }
  // ... other fields like ucp, status, messages, links
}

تحويل كائن عملية الدفع الكامل إلى كائن قابل للاستخدام

الطلب: ترسل Google عنصر الدفع الكامل مع المعلومات المعدَّلة (بما في ذلك عنوان التسليم الكامل ومعلومات الاتصال الخاصة بالمشتري) عندما ينقر المشتري على "الدفع باستخدام GPay".

// Request Example: full checkout object hydration for multiple items.
{
  "buyer": {
    "first_name": "John",
    "last_name": "Buyer",
    "email": "johnbuyer@example.com",
    "phone_number": "+18888888888"
  },
  "line_items": [
    {
      "id": "line_1",
      "item": { "id": "product_12345" },
      "quantity": 1
    },
    {
      "id": "line_2",
      "item": { "id": "product_67890" },
      "quantity": 1
    }
  ],
  "fulfillment": {
    "methods": [
      {
        "id": "method_shipping",
        "type": "shipping",
        "line_item_ids": ["line_1", "line_2"],
        "selected_destination_id": "addr_1",
        "destinations": [
          {
            "id": "addr_1",
            "first_name": "Alice",
            "last_name": "Receiver",
            "street_address": "1600 Amphitheatre Pkwy",
            "extended_address": "Suite #60",
            "address_locality": "Mountain View",
            "address_region": "CA",
            "postal_code": "94043",
            "address_country": "US",
            "phone_number": "+18888888888"
          }
        ],
        "groups": [
          {
            "id": "group_1",
            "selected_option_id": "ship_ground"
          }
        ]
      }
    ]
  }
}

الردّ: عليك إعادة احتساب الضرائب وخيارات الشحن حسب الحاجة، ثم إرجاع عنصر الدفع الكامل.

// Response Example: Session after full hydration with multiple items.
{
  "ucp": {
    "version": "2026-04-08",
    "status": "success",
    "capabilities": {
      "dev.ucp.shopping.checkout": [ { "version": "2026-04-08" } ],
      "dev.ucp.shopping.fulfillment": [ { "version": "2026-04-08", "extends": "dev.ucp.shopping.checkout" } ]
    },
    "payment_handlers": {
      "com.google.pay": [
        {
          "id": "8c9202bd-63cc-4241-8d24-d57ce69ea31c",
          "version": "2026-01-23",
          "spec": "https://pay.google.com/gp/p/ucp/2026-01-23/",
          "schema": "https://pay.google.com/gp/p/ucp/2026-01-23/schemas/config.json",
          "config": {
            "api_version": 2,
            "api_version_minor": 0,
            "environment": "TEST",
            "merchant_info": {
              "merchant_name": "Example Merchant",
              "merchant_id": "KWMZPRLQFTYNXSDB",
              "merchant_origin": "checkout.merchant.com"
            },
            "allowed_payment_methods": [
              {
                "type": "CARD",
                "parameters": {
                  "allowed_auth_methods": [ "PAN_ONLY", "CRYPTOGRAM_3DS" ],
                  "allowed_card_networks": [ "AMEX", "DISCOVER", "JCB", "MASTERCARD", "VISA" ],
                  "billing_address_required": true,
                  "billing_address_parameters": {
                    "format": "FULL",
                    "phone_number_required": true
                  }
                },
                "tokenization_specification": {
                  "type": "PAYMENT_GATEWAY",
                  "parameters": {
                    "gateway": "example",
                    "gatewayMerchantId": "exampleGatewayMerchantId"
                  }
                }
              }
            ]
          }
        }
      ]
    }
  },
  "id": "bf8c1b4b-6b1c-4c6a-8f2a-53c2a7c3b2e1",
  "status": "ready_for_complete",
  "currency": "USD",
  "buyer": {
    "first_name": "John",
    "last_name": "Buyer",
    "email": "johnbuyer@example.com",
    "phone_number": "+18888888888"
  },
  "line_items": [
    {
      "id": "line_1",
      "item": {
        "id": "product_12345",
        "title": "Running Shoes",
        "price": 10000,
        "image_url": "https://merchant.example.com/images/product_12345.png"
      },
      "quantity": 1,
      "totals": [
        { "type": "subtotal", "amount": 10000 },
        { "type": "total", "amount": 10000 }
      ]
    },
    {
      "id": "line_2",
      "item": {
        "id": "product_67890",
        "title": "T-Shirt",
        "price": 2500,
        "image_url": "https://merchant.example.com/images/product_67890.png"
      },
      "quantity": 1,
      "totals": [
        { "type": "subtotal", "amount": 2500 },
        { "type": "total", "amount": 2500 }
      ]
    }
  ],
  "totals": [
     { "type": "subtotal", "display_text": "Subtotal", "amount": 12500 },
     { "type": "fulfillment", "display_text": "Ground Shipping", "amount": 600 },
      {
        "type": "fee",
        "display_text": "Fees",
        "amount": 549,
        "lines": [
          { "display_text": "Service Fee", "amount": 399 },
          { "display_text": "Recycling Fee", "amount": 150 }
        ]
      },
     { "type": "tax", "display_text": "Estimated Tax", "amount": 1120 },
     { "type": "total", "display_text": "Total", "amount": 14769 }
  ],
  "fulfillment": {
    "methods": [
      {
        "id": "method_shipping",
        "type": "shipping",
        "line_item_ids": ["line_1", "line_2"],
        "selected_destination_id": "addr_1",
        "destinations": [
          {
            "id": "addr_1",
            "first_name": "Alice",
            "last_name": "Receiver",
            "street_address": "1600 Amphitheatre Pkwy",
            "extended_address": "Suite #60",
            "address_locality": "Mountain View",
            "address_region": "CA",
            "postal_code": "94043",
            "address_country": "US",
            "phone_number": "+18888888888"
          }
        ],
        "groups": [
          {
            "id": "group_1",
            "line_item_ids": ["line_1", "line_2"],
            "selected_option_id": "ship_ground",
            "options": [
              {
                "id": "ship_ground",
                "title": "Ground (3-5 days)",
                "description": "Estimated Delivery: Fri 5/8", // Maximum length: 200 characters.
                "totals": [ { "type": "total", "amount": 600 } ]
              },
              {
                "id": "ship_express",
                "title": "Express (1-2 days)",
                "description": "Estimated Delivery: Wed 5/6", // Maximum length: 200 characters.
                "totals": [ { "type": "total", "amount": 1600 } ]
              }
            ]
          }
        ]
      }
    ]
  },
  "links": [
    {
      "type": "terms_of_service",
      "url": "https://m.com/terms",
      "title": "Terms of Service"
    },
    {
      "type": "privacy_policy",
      "url": "https://m.com/privacy",
      "title": "Privacy Policy"
    }
  ]
}

إكمال جلسة الدفع

تتيح نقطة النهاية هذه إكمال جلسة دفع وتقديم طلب. يجب أن تعرض هذه الطريقة جلسة الدفع المكتملة وأن تتضمّن معلومات الطلب. يجب أن تبدأ عملية معالجة الدفع بعد تلقّي هذه المكالمة.

  • نقطة النهاية: POST /checkout-sessions/{id}/complete
  • الإجراء: ينقر المستخدم على "الدفع باستخدام GPay"، وتتلقّى Google ردًا ناجحًا من عملية الدفع المكتملة.

الطلب: ترسل Google أداة الدفع المحدّدة من معالج الدفع، بما في ذلك بيانات الاعتماد (مثل بيانات الترميز في Google Pay) وإشارات المخاطر حول المشتري لتتمكّن من رصد عمليات الاحتيال بنفسك. سيعتمد محتوى الرمز المميّز على مقدّم خدمة الدفع.

{
  "payment": {
    "instruments": [
      {
        "billing_address": {
          "first_name": "John",
          "last_name": "Buyer",
          "street_address": "100 Main St",
          "extended_address": "Apt 4B",
          "address_locality": "San Francisco",
          "address_region": "CA",
          "postal_code": "94105",
          "address_country": "US",
          "phone_number": "+18888888888"
        },
        "credential": {
          "token": "examplePaymentMethodToken",
          "type": "PAYMENT_GATEWAY"
        },
        "display": {
          "brand": "VISA",
          "description": "Visa •••• 1234",
          "last_digits": "1234"
        },
        "handler_id": "8c9202bd-63cc-4241-8d24-d57ce69ea31c",
        "id": "94e7fee0-1a82-4c2a-9ef4-0861a3c829b2",
        "selected": true,
        "type": "card"
      }
    ]
  },
  "signals": {
    "com.google.authentication_triggered": "",
    "com.google.authorization_processed_with_3ds": "",
    "com.google.avs_full_result": "",
    "com.google.cvv_result": "",
    "com.google.ip_address": "203.0.113.1",
    "dev.ucp.buyer_id": "ec46fedc6aad89d3660a50a61d00b4908fd160ecf5dda6d49ed41a605c5b180a",
    "dev.ucp.buyer_ip": "203.0.113.1"
  }
}

إذا كنت بحاجة إلى معلومات إلزامية لإكمال عملية الدفع ولم يتم تقديمها في جلسة الدفع، يمكنك منع إكمال عملية الدفع وطلب هذه المعلومات من خلال عرض حالة غير مكتملة في الردّ.

إذا كان بإمكان Google جمع المعلومات الناقصة باستخدام الحقول المحدّدة في "منصّة إدارة الموافقة" (على سبيل المثال، عنوان البريد الإلكتروني للمشتري)، اضبط قيمة status على incomplete وأدرِج رسالة واحدة أو أكثر في مصفوفة messages مع ضبط قيمة severity على recoverable، ما يشير إلى المعلومات الناقصة.

{
  "ucp": {
    "version": "2026-04-08",
    "status": "success"
  },
  "id": "bf8c1b4b-6b1c-4c6a-8f2a-53c2a7c3b2e1",
  "status": "incomplete",
  "messages": [
    {
      "type": "error",
      "code": "missing_buyer_info",
      "severity": "recoverable",
      "content": "Buyer email is required"
    },
    {
      "type": "error",
      "code": "missing_fulfillment_info",
      "severity": "recoverable",
      "content": "Select delivery window for your purchase"
    }
  ]
}

عند استلام وسيلة دفع في Google Pay، عليك إجراء ما يلي:

  1. التحقّق من صحة المعالج: تأكَّد من أنّ handler_id يتوافق مع معالج الدفع في Google Pay المحدّد في عملية الضبط.
  2. استخراج الرمز المميّز: استرداد الرمز المميّز لطريقة الدفع التي تم إنشاؤها من payment.instruments[0].credential.token
  3. معالجة الدفع: استخدِم الرمز المميز وتفاصيل المعاملة لإكمال عملية الدفع. يمكنك الرجوع إلى مستندات Google Pay API للحصول على مستندات تفصيلية حول مواصفات الترميز والتعامل معه.

الردّ: إذا كان بإمكانك إكمال عملية الدفع ومعالجة الدفعة، عليك عرض عنصر الدفع الكامل الذي يشير إلى أنّ الطلب مكتمل، بما في ذلك وسيلة الدفع المؤكَّدة (مع عرض البيانات الوصفية لوسيلة الدفع وعنوان إرسال الفواتير، بدون الرمز المميز الحساس credential أو signals) ومعرّف الطلب وعنوان URL ثابت يؤدي إلى الطلب.

{
  "ucp": {
      "version": "2026-04-08",
      "status": "success",
      "capabilities": [...]
  },
  "id": "bf8c1b4b-6b1c-4c6a-8f2a-53c2a7c3b2e1",
  "status": "completed",

  // ... other fields (line_items, currency, etc.)

  "payment": {
    "instruments": [
      {
        "id": "94e7fee0-1a82-4c2a-9ef4-0861a3c829b2",
        "handler_id": "8c9202bd-63cc-4241-8d24-d57ce69ea31c",
        "type": "card",
        "selected": true,
        "display": {
          "brand": "VISA",
          "description": "Visa •••• 1234",
          "last_digits": "1234"
        },
        "billing_address": {
          "first_name": "John",
          "last_name": "Buyer",
          "street_address": "100 Main St",
          "extended_address": "Apt 4B",
          "address_locality": "San Francisco",
          "address_region": "CA",
          "postal_code": "94105",
          "address_country": "US",
          "phone_number": "+18888888888"
        }
      }
    ]
  },
  "order": {
    "id": "ORD1773956535.2727807",
    // Example customer-facing order number
    "label": "#100",
    "permalink_url": "https://merchant.example.com/orders/789"
  }
}

إلغاء جلسة الدفع

تلغي نقطة النهاية هذه جلسة الدفع.

  • نقطة النهاية: POST /checkout-sessions/{id}/cancel

الطلب: ترسل Google معرّف جلسة الدفع.

الردّ: عليك إرجاع عنصر الدفع الكامل مع تعديل الحالة إلى canceled.

معالجة الأخطاء

للاطّلاع على الإرشادات الكاملة حول كيفية تنسيق رسائل الخطأ والتمييز بين أخطاء البروتوكول وأخطاء منطق النشاط التجاري، يُرجى الرجوع إلى نظرة عامة على رموز الخطأ.

خطأ غير قابل للإصلاح

بدءًا من الإصدار 2026-04-08، عندما يمنع خطأ غير قابل للاسترداد إنشاء جلسة دفع (على سبيل المثال، إذا كانت جميع السلع غير متوفرة)، يجب عرض رمز حالة HTTP 200 OK. في نص الاستجابة، اضبط "status": "error" ضمن العنصر ucp. يُعلم ذلك Google بأنّ الطلب صالح، ولكن إحدى قواعد النشاط التجاري منعت إنشاء الجلسة. في هذه الحالة، لا يتم عرض معرّف جلسة الدفع.

HTTP/1.1 200 OK
Content-Type: application/json

{
  "ucp": {
    "version": "2026-04-08",
    "status": "error"
  },
  "messages": [
    {
      "type": "error",
      "code": "out_of_stock",
      "content": "All requested items are currently out of stock",
      "severity": "unrecoverable"
    }
  ],
  "continue_url": "https://merchant.com/"
}