प्रमोशन कोड और छूट लागू करना

इस गाइड में, यूनिवर्सल कॉमर्स प्रोटोकॉल (यूसीपी) के वर्शन 2026-04-08 में, प्रमोशन कोड और छूट को मैनेज करने के लिए, तकनीकी एपीआई का संदर्भ और पेलोड स्कीमा के बारे में जानकारी दी गई है.

एंडपॉइंट बनाने से पहले, पक्का करें कि आपने प्रमोशन कोड और छूट की खास जानकारी देखी हो. इसमें, बड़े लेवल के कॉन्सेप्ट, गणित के इनवेरिएंट, और गड़बड़ी को ठीक करने के नियमों के बारे में बताया गया है.

खोज

Google से छूट के कोड पाने के लिए, आपको अपनी प्रोफ़ाइल में छूट की सुविधा के बारे में विज्ञापन दिखाना होगा. वर्शन 2026-04-08 में, प्लैटफ़ॉर्म छूट के कोड सबमिट करने से पहले यह देखते हैं कि चेकआउट की सुविधा को बढ़ाया गया है या नहीं.

{
  "ucp": {
    "version": "2026-04-08",
    "capabilities": {
      "dev.ucp.shopping.discount": [
        {
          "version": "2026-04-08",
          "extends": ["dev.ucp.shopping.checkout"],
          "spec": "https://ucp.dev/2026-04-08/specification/discount",
          "schema": "https://ucp.dev/2026-04-08/schemas/shopping/discount.json"
        }
      ]
    }
  }
}

लाइन आइटम और कुल रकम पर असर

लागू की गई छूट, चेकआउट के मुख्य फ़ील्ड में दिखती हैं. इसके लिए, कुल रकम के दो अलग-अलग टाइप इस्तेमाल किए जाते हैं. अगर किसी छूट में allocations लाइन आइटम की ओर इशारा करते हैं, तो यह items_discount में जुड़ जाती है. बिना किसी आवंटन वाली छूट या शिपिंग या शुल्क के लिए आवंटन वाली छूट, discount में जुड़ जाती हैं.

छूट का टाइप कुल रकम का टाइप यह कहां दिखती है
लाइन-आइटम डिस्काउंट items_discount line_items[].totals[type=items_discount]
ऑर्डर-लेवल डिस्काउंट discount totals[type=discount]

वर्शन की ज़रूरी शर्त:

वर्शन 2026-04-08 के लिए, totals[] और line_items[].totals[] में छूट की एंट्री के लिए नेगेटिव वैल्यू का इस्तेमाल करना ज़रूरी है. इससे रसीद पर छूट का असर दिखेगा. discounts.applied और allocations अरे में मौजूद रकम हमेशा पॉज़िटिव पूर्णांक होती हैं.

अपने-आप लागू होने वाले प्रमोशन के लिए एपीआई के उदाहरण

यहां दिए गए उदाहरणों में, अपने-आप लागू होने वाली छूट दिखाई गई हैं. अनुरोध के पेलोड में discounts.codes अरे शामिल नहीं होता. हालांकि, जवाबों में "automatic": true शामिल होता है और code फ़ील्ड शामिल नहीं होता.

आइटम-लेवल डिस्काउंट, जो अपने-आप लागू होता है

किसी खास लाइन आइटम पर, पूरी साइट के लिए 10% की छूट अपने-आप लागू हो गई.

अनुरोध का उदाहरण:

{
  "line_items": [
    {
      "id": "li_1",
      "item": { "title": "Sneakers", "price": 10000 },
      "quantity": 1
    }
  ]
}

जवाब का उदाहरण:

{
  "line_items": [
    {
      "id": "li_1",
      "item": { "title": "Sneakers", "price": 10000 },
      "quantity": 1,
      "totals": [
        {"type": "subtotal", "amount": 10000},
        {"type": "items_discount", "amount": -1000},
        {"type": "total", "amount": 9000}
      ]
    }
  ],
  "discounts": {
    "applied": [
      {
        "title": "10% Off Sitewide Sale",
        "amount": 1000,
        "automatic": true,
        "method": "each",
        "allocations": [
          {"path": "$.line_items[0]", "amount": 1000}
        ]
      }
    ]
  },
  "totals": [
    {"type": "subtotal", "display_text": "Subtotal", "amount": 10000},
    {"type": "items_discount", "display_text": "Item Discounts", "amount": -1000},
    {"type": "total", "display_text": "Total", "amount": 9000}
  ]
}

ऑर्डर-लेवल डिस्काउंट, जो अपने-आप लागू होता है

प्रमोशन का कोई नियम (जैसे, 5,000 रुपये से ज़्यादा के ऑर्डर पर 1,000 रुपये की छूट) पूरे ऑर्डर पर लागू हो गया. इसके लिए, लाइन-आइटम के लिए कोई खास आवंटन नहीं किया गया.

अनुरोध का उदाहरण:

{
  "line_items": [ ... ]
}

जवाब का उदाहरण:

{
  "line_items": [ ... ],
  "discounts": {
    "applied": [
      {
        "title": "$10 Off Orders Over $50",
        "amount": 1000,
        "automatic": true
      }
    ]
  },
  "totals": [
    {"type": "subtotal", "display_text": "Subtotal", "amount": 6000},
    {"type": "discount", "display_text": "Order Promo", "amount": -1000},
    {"type": "total", "display_text": "Total", "amount": 5000}
  ]
}

उपयोगकर्ता के लागू किए गए प्रमोशन के लिए एपीआई के उदाहरण

यहां दिए गए उदाहरणों में, प्रमोशन कोड डालने पर मिलने वाली छूट दिखाई गई हैं. अनुरोध के पेलोड में, अनुरोध किए गए कोड शामिल होते हैं. साथ ही, जवाबों में उन्हें वापस दिखाया जाता है. इसके अलावा, लागू की गई रकम का आवंटन भी दिखाया जाता है.

ऑर्डर-लेवल डिस्काउंट

ऑर्डर की कुल रकम पर, फ़्लैट डिस्काउंट लागू किया गया. इसके लिए, किसी आवंटन की ज़रूरत नहीं होती. यह छूट पूरे ऑर्डर पर लागू होती है और इसके लिए type: "discount" का इस्तेमाल किया जाता है.

अनुरोध का उदाहरण:

{
  "line_items": [ ... ],
  "discounts": {
    "codes": ["SAVE10"]
  }
}

जवाब का उदाहरण:

{
  "line_items": [ ... ],
  "discounts": {
    "codes": ["SAVE10"],
    "applied": [
      {
        "code": "SAVE10",
        "title": "$10 Off Your Order",
        "amount": 1000
      }
    ]
  },
  "totals": [
    {"type": "subtotal", "display_text": "Subtotal", "amount": 5000},
    {"type": "discount", "display_text": "Order Discount", "amount": -1000},
    {"type": "total", "display_text": "Total", "amount": 4000}
  ]
}

मिक्स डिस्काउंट (आइटम + ऑर्डर लेवल)

इस उदाहरण में, छूट के दोनों टाइप दिखाए गए हैं: लाइन आइटम के लिए, हर आइटम पर मिलने वाली छूट (20% की छूट) और ऑर्डर लेवल पर, शिपिंग पर अपने-आप मिलने वाली छूट.

अनुरोध का उदाहरण:

{
  "line_items": [ ... ],
  "discounts": {
    "codes": ["SUMMER20"]
  }
}

जवाब का उदाहरण:

{
  "line_items": [
    {
      "id": "li_1",
      "item": { "title": "T-Shirt", "price": 2000 },
      "quantity": 2,
      "totals": [
        {"type": "subtotal", "amount": 4000},
        {"type": "items_discount", "amount": -800},
        {"type": "total", "amount": 3200}
      ]
    }
  ],
  "discounts": {
    "codes": ["SUMMER20"],
    "applied": [
      {
        "code": "SUMMER20",
        "title": "Summer Sale 20% Off",
        "amount": 800,
        "allocations": [
          {"path": "$.line_items[0]", "amount": 800}
        ]
      },
      {
        "title": "Free shipping on orders over $30",
        "amount": 599,
        "automatic": true
      }
    ]
  },
  "totals": [
    {"type": "subtotal", "display_text": "Subtotal", "amount": 4000},
    {"type": "items_discount", "display_text": "Item Discounts", "amount": -800},
    {"type": "discount", "display_text": "Order Discounts", "amount": -599},
    {"type": "fulfillment", "display_text": "Shipping", "amount": 0},
    {"type": "total", "display_text": "Total", "amount": 2601}
  ]
}

अस्वीकार किया गया छूट का कोड

जब कोई कोड अमान्य होता है, तो वह codes में दिखता है. हालांकि, applied में नहीं दिखता. अस्वीकार किए जाने की वजह, messages[] अरे में मौजूद warning का इस्तेमाल करके बताई जाती है.

अनुरोध का उदाहरण:

{
  "line_items": [ ... ],
  "discounts": {
    "codes": ["SAVE10", "EXPIRED50"]
  }
}

जवाब का उदाहरण:

{
  "line_items": [ ... ],
  "discounts": {
    "codes": ["SAVE10", "EXPIRED50"],
    "applied": [
      {
        "code": "SAVE10",
        "title": "$10 Off Your Order",
        "amount": 1000
      }
    ]
  },
  "totals": [
    {"type": "subtotal", "display_text": "Subtotal", "amount": 5000},
    {"type": "discount", "display_text": "Order Discount", "amount": -1000},
    {"type": "total", "display_text": "Total", "amount": 4000}
  ],
  "messages": [
    {
      "type": "warning",
      "code": "discount_code_expired",
      "path": "$.discounts.codes[1]",
      "content": "Code 'EXPIRED50' expired on December 1st"
    }
  ]
}

आवंटन के साथ, एक से ज़्यादा छूट लागू करना

एक से ज़्यादा छूट लागू की गई हैं. साथ ही, हर छूट के लिए आवंटन की पूरी जानकारी दी गई है.

अनुरोध का उदाहरण:

{
  "line_items": [ ... ],
  "discounts": {
    "codes": ["SUMMER20", "EXTRA5"]
  }
}

जवाब का उदाहरण:

{
  "line_items": [
    {
      "id": "li_1",
      "item": { "title": "T-Shirt", "price": 6000 },
      "quantity": 1,
      "totals": [
        {"type": "subtotal", "amount": 6000},
        {"type": "items_discount", "amount": -1500},
        {"type": "total", "amount": 4500}
      ]
    },
    {
      "id": "li_2",
      "item": { "title": "Socks", "price": 4000 },
      "quantity": 1,
      "totals": [
        {"type": "subtotal", "amount": 4000},
        {"type": "items_discount", "amount": -1000},
        {"type": "total", "amount": 3000}
      ]
    }
  ],
  "discounts": {
    "codes": ["SUMMER20", "EXTRA5"],
    "applied": [
      {
        "code": "SUMMER20",
        "title": "Summer Sale 20% Off",
        "amount": 2000,
        "method": "each",
        "priority": 1,
        "allocations": [
          {"path": "$.line_items[0]", "amount": 1200},
          {"path": "$.line_items[1]", "amount": 800}
        ]
      },
      {
        "code": "EXTRA5",
        "title": "Extra $5 Off",
        "amount": 500,
        "method": "across",
        "priority": 2,
        "allocations": [
          {"path": "$.line_items[0]", "amount": 300},
          {"path": "$.line_items[1]", "amount": 200}
        ]
      }
    ]
  },
  "totals": [
    {"type": "subtotal", "display_text": "Subtotal", "amount": 10000},
    {"type": "items_discount", "display_text": "Item Discounts", "amount": -2500},
    {"type": "total", "display_text": "Total", "amount": 7500}
  ]
}