> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dodopayments.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 更新折扣

> 更新您账户中的折扣。



## OpenAPI

````yaml patch /discounts/{discount_id}
openapi: 3.1.0
info:
  title: public
  description: ''
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0
  version: 1.110.1
servers:
  - url: https://test.dodopayments.com/
    description: Test Mode Server Host
  - url: https://live.dodopayments.com/
    description: Live Mode Server Host
security: []
tags:
  - name: Products
  - name: Payments
  - name: Subscriptions
  - name: Addons
  - name: Customers
  - name: Refunds
  - name: Disputes
  - name: Events
  - name: License Keys
  - name: Entitlements
  - name: Licenses
  - name: Discounts
  - name: Meters
  - name: Credit Entitlements
  - name: Credit Entitlement Balances
  - name: Outgoing Webhooks
  - name: Checkout
  - name: Webhook Events
  - name: Payment Connector Webhooks
paths:
  /discounts/{discount_id}:
    patch:
      tags:
        - Discounts
      summary: PATCH /discounts/{discount_id}
      operationId: patch_discount_handler
      parameters:
        - name: discount_id
          in: path
          description: Discount Id
          required: true
          schema:
            type: string
          example: dsc_qxxEmg5PuM1uNTE0LgkP9
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PatchDiscountRequest'
        required: true
      responses:
        '200':
          description: Updated discount
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DiscountResponse'
        '404':
          description: Discount not found or soft-deleted
        '500':
          description: Something went wrong :(
      security:
        - API_KEY: []
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import DodoPayments from 'dodopayments';


            const client = new DodoPayments({
              bearerToken: process.env['DODO_PAYMENTS_API_KEY'], // This is the default and can be omitted
            });


            const discount = await
            client.discounts.update('dsc_qxxEmg5PuM1uNTE0LgkP9');


            console.log(discount.business_id);
        - lang: Python
          source: |-
            import os
            from dodopayments import DodoPayments

            client = DodoPayments(
                bearer_token=os.environ.get("DODO_PAYMENTS_API_KEY"),  # This is the default and can be omitted
            )
            discount = client.discounts.update(
                discount_id="dsc_qxxEmg5PuM1uNTE0LgkP9",
            )
            print(discount.business_id)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/dodopayments/dodopayments-go\"\n\t\"github.com/dodopayments/dodopayments-go/option\"\n)\n\nfunc main() {\n\tclient := dodopayments.NewClient(\n\t\toption.WithBearerToken(\"My Bearer Token\"),\n\t)\n\tdiscount, err := client.Discounts.Update(\n\t\tcontext.TODO(),\n\t\t\"dsc_qxxEmg5PuM1uNTE0LgkP9\",\n\t\tdodopayments.DiscountUpdateParams{},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", discount.BusinessID)\n}\n"
        - lang: Java
          source: |-
            package com.dodopayments.api.example;

            import com.dodopayments.api.client.DodoPaymentsClient;
            import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient;
            import com.dodopayments.api.models.discounts.Discount;
            import com.dodopayments.api.models.discounts.DiscountUpdateParams;

            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    DodoPaymentsClient client = DodoPaymentsOkHttpClient.fromEnv();

                    Discount discount = client.discounts().update("dsc_qxxEmg5PuM1uNTE0LgkP9");
                }
            }
        - lang: Kotlin
          source: |-
            package com.dodopayments.api.example

            import com.dodopayments.api.client.DodoPaymentsClient
            import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient
            import com.dodopayments.api.models.discounts.Discount
            import com.dodopayments.api.models.discounts.DiscountUpdateParams

            fun main() {
                val client: DodoPaymentsClient = DodoPaymentsOkHttpClient.fromEnv()

                val discount: Discount = client.discounts().update("dsc_qxxEmg5PuM1uNTE0LgkP9")
            }
        - lang: Ruby
          source: >-
            require "dodopayments"


            dodo_payments = Dodopayments::Client.new(
              bearer_token: "My Bearer Token",
              environment: "test_mode" # defaults to "live_mode"
            )


            discount =
            dodo_payments.discounts.update("dsc_qxxEmg5PuM1uNTE0LgkP9")


            puts(discount)
        - lang: PHP
          source: |-
            <?php

            require_once dirname(__DIR__) . '/vendor/autoload.php';

            use Dodopayments\Client;
            use Dodopayments\Core\Exceptions\APIException;
            use Dodopayments\Discounts\DiscountType;
            use Dodopayments\Misc\Currency;

            $client = new Client(
              bearerToken: getenv('DODO_PAYMENTS_API_KEY') ?: 'My Bearer Token',
              environment: 'test_mode',
            );

            try {
              $discount = $client->discounts->update(
                'dsc_qxxEmg5PuM1uNTE0LgkP9',
                amount: 0,
                code: 'code',
                currencyOptions: [
                  [
                    'currency' => Currency::AED,
                    'isDefault' => true,
                    'maxAmountPossible' => 0,
                    'minimumSubtotal' => 0,
                  ],
                ],
                customerEligibility: 'any',
                expiresAt: new \DateTimeImmutable('2019-12-27T18:11:19.117Z'),
                metadata: ['foo' => 'string'],
                name: 'name',
                perCustomerUsageLimit: 0,
                preserveOnPlanChange: true,
                restrictedTo: ['string'],
                startsAt: new \DateTimeImmutable('2019-12-27T18:11:19.117Z'),
                subscriptionCycles: 0,
                type: DiscountType::FLAT,
                usageLimit: 0,
              );

              var_dump($discount);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: C#
          source: |-
            using System;
            using DodoPayments.Client;
            using DodoPayments.Client.Models.Discounts;

            DodoPaymentsClient client = new();

            DiscountUpdateParams parameters = new()
            {
                DiscountID = "dsc_qxxEmg5PuM1uNTE0LgkP9"
            };

            var discount = await client.Discounts.Update(parameters);

            Console.WriteLine(discount);
        - lang: Rust
          source: |-
            use dodopayments::Client;

            #[tokio::main]
            async fn main() -> dodopayments::Result<()> {
                let client = Client::from_env()?;
                let discount_id = "discount_id";
                let result = client
                    .discounts()
                    .update()
                    .discount_id(discount_id)
                    .body(Default::default())
                    .await?;
                println!("{result:?}");
                Ok(())
            }
components:
  schemas:
    PatchDiscountRequest:
      type: object
      description: |-
        Request body for patching (updating) a discount.

        All fields are optional and only update if provided.
      properties:
        amount:
          type:
            - integer
            - 'null'
          format: int32
          description: >-
            If present, update the discount amount in **basis points** (e.g.,
            `540` = `5.4%`, `10000` = `100%`).


            Must be at least 1 if provided.
        code:
          type:
            - string
            - 'null'
          description: If present, update the discount code (uppercase).
        currency_options:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/CurrencyOptionRequest'
          description: >-
            If present, fully replaces the discount's currency options
            (replace-set

            semantics, like `restricted_to`). Send an empty array to clear them.
        customer_eligibility:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/CustomerEligibility'
              description: >-
                If present, update who may redeem this discount. Plain field
                (not

                double-option): the DB column is `NOT NULL`, so it can never be
                cleared

                back to unset, only changed to another `CustomerEligibility`
                value.
        expires_at:
          type:
            - string
            - 'null'
          format: date-time
        metadata:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/Metadata'
              description: Additional metadata for the discount
        name:
          type:
            - string
            - 'null'
        per_customer_usage_limit:
          type:
            - integer
            - 'null'
          format: int32
          description: |-
            If present, update the per-customer usage limit (double-option: send
            `null` to clear it back to unlimited). Must be `<= usage_limit` (the
            value in effect after this patch) when both are set.
        preserve_on_plan_change:
          type:
            - boolean
            - 'null'
          description: >-
            Whether this discount should be preserved when a subscription
            changes plans.

            If not provided, the existing value is kept.
        restricted_to:
          type:
            - array
            - 'null'
          items:
            type: string
          description: |-
            If present, replaces all restricted product IDs with this new set.
            To remove all restrictions, send empty array
        starts_at:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            If present, update `starts_at` (double-option: send `null` to clear
            it).
        subscription_cycles:
          type:
            - integer
            - 'null'
          format: int32
          description: |-
            Number of subscription billing cycles this discount is valid for.
            If not provided, the discount will be applied indefinitely to
            all recurring payments related to the subscription.
        type:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/DiscountType'
              description: If present, update the discount type (`percentage` or `flat`).
        usage_limit:
          type:
            - integer
            - 'null'
          format: int32
    DiscountResponse:
      type: object
      required:
        - discount_id
        - business_id
        - type
        - code
        - amount
        - times_used
        - restricted_to
        - created_at
        - preserve_on_plan_change
        - customer_eligibility
        - metadata
      properties:
        amount:
          type: integer
          format: int32
          description: The discount amount in **basis points** (e.g., 540 => 5.4%).
        business_id:
          type: string
          description: The business this discount belongs to.
        code:
          type: string
          description: The discount code (up to 16 chars).
        created_at:
          type: string
          format: date-time
          description: Timestamp when the discount is created
        currency_options:
          type: array
          items:
            $ref: '#/components/schemas/CurrencyOptionResponse'
          description: >-
            Per-currency options (flat deduction / percentage cap + minimum
            subtotal).

            Empty for discounts without any configured currency options.
        customer_eligibility:
          $ref: '#/components/schemas/CustomerEligibility'
          description: Who may redeem this discount code.
        discount_id:
          type: string
          description: The unique discount ID
        expires_at:
          type:
            - string
            - 'null'
          format: date-time
          description: Optional date/time after which discount is expired.
        metadata:
          $ref: '#/components/schemas/Metadata'
        name:
          type:
            - string
            - 'null'
          description: Name for the Discount
        per_customer_usage_limit:
          type:
            - integer
            - 'null'
          format: int32
          description: >-
            Maximum number of times a single customer may redeem this discount,
            if any.
        preserve_on_plan_change:
          type: boolean
          description: >-
            Whether this discount should be preserved when a subscription
            changes plans.

            Default: false (discount is removed on plan change)
        restricted_to:
          type: array
          items:
            type: string
          description: List of product IDs to which this discount is restricted.
        starts_at:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            Optional date/time before which the discount is not yet active. NULL
            = active immediately.
        subscription_cycles:
          type:
            - integer
            - 'null'
          format: int32
          description: |-
            Number of subscription billing cycles this discount is valid for.
            If not provided, the discount will be applied indefinitely to
            all recurring payments related to the subscription.
        times_used:
          type: integer
          format: int32
          description: How many times this discount has been used.
        type:
          $ref: '#/components/schemas/DiscountType'
          description: The type of discount (`percentage` or `flat`).
        usage_limit:
          type:
            - integer
            - 'null'
          format: int32
          description: Usage limit for this discount, if any.
    CurrencyOptionRequest:
      type: object
      description: >-
        A per-currency discount option (request shape).


        `max_amount_possible` is the most this code discounts in this currency —
        the

        flat deduction for `flat` codes, or the max-discount cap for
        `percentage`

        codes. Maps to the DB column of the same name.
      required:
        - currency
      properties:
        currency:
          $ref: '#/components/schemas/Currency'
          description: The currency this option applies to.
        is_default:
          type: boolean
          description: |-
            Whether this row is the default to convert from for unconfigured
            currencies. At most one row per discount may be default.
        max_amount_possible:
          type:
            - integer
            - 'null'
          format: int32
          description: >-
            The most this code discounts in this currency's subunits. For `flat`
            codes

            this is the deduction; for `percentage` codes it is the max-discount
            cap.

            Must be > 0 if provided.
        minimum_subtotal:
          type: integer
          format: int32
          description: >-
            Eligible-cart threshold in this currency's subunits (0 = no
            minimum).
    CustomerEligibility:
      type: string
      description: >-
        Who may redeem a discount code. Mirrors the Postgres enum

        `discount_customer_eligibility` (migration
        `20260714063329_discount_expansion`).
      enum:
        - any
        - first_time
        - existing
        - specific
    Metadata:
      type: object
      title: Metadata
      description: >-
        Arbitrary key-value metadata. Values can be string, integer, number, or
        boolean.
      additionalProperties:
        oneOf:
          - type: string
            title: String
          - type: integer
            title: Integer
            format: int64
          - type: number
            title: Number
            format: double
          - type: boolean
            title: Boolean
        title: Metadata Value
        description: Metadata value can be a string, integer, number, or boolean
    DiscountType:
      type: string
      enum:
        - flat
        - percentage
    CurrencyOptionResponse:
      type: object
      description: |-
        A per-currency discount option (response shape). `max_amount_possible`
        mirrors the DB column of the same name.
      required:
        - currency
        - minimum_subtotal
        - is_default
      properties:
        currency:
          $ref: '#/components/schemas/Currency'
          description: The currency this option applies to.
        is_default:
          type: boolean
          description: Whether this is the default row FX conversions pivot from.
        max_amount_possible:
          type:
            - integer
            - 'null'
          format: int32
          description: >-
            The most this code discounts in this currency's subunits (flat
            deduction

            or percentage cap).
        minimum_subtotal:
          type: integer
          format: int32
          description: >-
            Eligible-cart threshold in this currency's subunits (0 = no
            minimum).
    Currency:
      type: string
      enum:
        - AED
        - ALL
        - AMD
        - ANG
        - AOA
        - ARS
        - AUD
        - AWG
        - AZN
        - BAM
        - BBD
        - BDT
        - BGN
        - BHD
        - BIF
        - BMD
        - BND
        - BOB
        - BRL
        - BSD
        - BWP
        - BYN
        - BZD
        - CAD
        - CHF
        - CLP
        - CNY
        - COP
        - CRC
        - CUP
        - CVE
        - CZK
        - DJF
        - DKK
        - DOP
        - DZD
        - EGP
        - ETB
        - EUR
        - FJD
        - FKP
        - GBP
        - GEL
        - GHS
        - GIP
        - GMD
        - GNF
        - GTQ
        - GYD
        - HKD
        - HNL
        - HRK
        - HTG
        - HUF
        - IDR
        - ILS
        - INR
        - IQD
        - JMD
        - JOD
        - JPY
        - KES
        - KGS
        - KHR
        - KMF
        - KRW
        - KWD
        - KYD
        - KZT
        - LAK
        - LBP
        - LKR
        - LRD
        - LSL
        - LYD
        - MAD
        - MDL
        - MGA
        - MKD
        - MMK
        - MNT
        - MOP
        - MRU
        - MUR
        - MVR
        - MWK
        - MXN
        - MYR
        - MZN
        - NAD
        - NGN
        - NIO
        - NOK
        - NPR
        - NZD
        - OMR
        - PAB
        - PEN
        - PGK
        - PHP
        - PKR
        - PLN
        - PYG
        - QAR
        - RON
        - RSD
        - RUB
        - RWF
        - SAR
        - SBD
        - SCR
        - SEK
        - SGD
        - SHP
        - SLE
        - SLL
        - SOS
        - SRD
        - SSP
        - STN
        - SVC
        - SZL
        - THB
        - TND
        - TOP
        - TRY
        - TTD
        - TWD
        - TZS
        - UAH
        - UGX
        - USD
        - UYU
        - UZS
        - VES
        - VND
        - VUV
        - WST
        - XAF
        - XCD
        - XOF
        - XPF
        - YER
        - ZAR
        - ZMW
  securitySchemes:
    API_KEY:
      type: http
      scheme: bearer

````