الانتقال إلى المحتوى الرئيسي
PATCH
/
discounts
/
{discount_id}
JavaScript
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);
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)
package main

import (
	"context"
	"fmt"

	"github.com/dodopayments/dodopayments-go"
	"github.com/dodopayments/dodopayments-go/option"
)

func main() {
	client := dodopayments.NewClient(
		option.WithBearerToken("My Bearer Token"),
	)
	discount, err := client.Discounts.Update(
		context.TODO(),
		"dsc_qxxEmg5PuM1uNTE0LgkP9",
		dodopayments.DiscountUpdateParams{},
	)
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", discount.BusinessID)
}
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");
    }
}
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")
}
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)
<?php

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

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

$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',
    expiresAt: new \DateTimeImmutable('2019-12-27T18:11:19.117Z'),
    metadata: ['foo' => 'string'],
    name: 'name',
    preserveOnPlanChange: true,
    restrictedTo: ['string'],
    subscriptionCycles: 0,
    type: DiscountType::PERCENTAGE,
    usageLimit: 0,
  );

  var_dump($discount);
} catch (APIException $e) {
  echo $e->getMessage();
}
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);
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(())
}
curl --request PATCH \
  --url https://test.dodopayments.com/discounts/{discount_id} \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "amount": 123,
  "code": "<string>",
  "expires_at": "2023-11-07T05:31:56Z",
  "metadata": {},
  "name": "<string>",
  "preserve_on_plan_change": true,
  "restricted_to": [
    "<string>"
  ],
  "subscription_cycles": 123,
  "type": "percentage",
  "usage_limit": 123
}
'
{
  "amount": 123,
  "business_id": "<string>",
  "code": "<string>",
  "created_at": "2023-11-07T05:31:56Z",
  "discount_id": "<string>",
  "metadata": {},
  "preserve_on_plan_change": true,
  "restricted_to": [
    "<string>"
  ],
  "times_used": 123,
  "type": "percentage",
  "expires_at": "2023-11-07T05:31:56Z",
  "name": "<string>",
  "subscription_cycles": 123,
  "usage_limit": 123
}

التفويضات

Authorization
string
header
مطلوب

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

معلمات المسار

discount_id
string
مطلوب

Discount Id

الجسم

application/json

Request body for patching (updating) a discount.

All fields are optional and only update if provided.

amount
integer<int32> | null

If present, update the discount amount in basis points (e.g., 540 = 5.4%, 10000 = 100%).

Must be at least 1 if provided.

code
string | null

If present, update the discount code (uppercase).

expires_at
string<date-time> | null
metadata
null | Metadata · object

Additional metadata for the discount

name
string | null
preserve_on_plan_change
boolean | null

Whether this discount should be preserved when a subscription changes plans. If not provided, the existing value is kept.

restricted_to
string[] | null

If present, replaces all restricted product IDs with this new set. To remove all restrictions, send empty array

subscription_cycles
integer<int32> | null

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
null | enum<string>

If present, update the discount type. Currently only percentage is supported.

الخيارات المتاحة:
percentage
usage_limit
integer<int32> | null

الاستجابة

Updated discount

amount
integer<int32>
مطلوب

The discount amount in basis points (e.g., 540 => 5.4%).

business_id
string
مطلوب

The business this discount belongs to.

code
string
مطلوب

The discount code (up to 16 chars).

created_at
string<date-time>
مطلوب

Timestamp when the discount is created

discount_id
string
مطلوب

The unique discount ID

metadata
Metadata · object
مطلوب

Arbitrary key-value metadata. Values can be string, integer, number, or boolean.

preserve_on_plan_change
boolean
مطلوب

Whether this discount should be preserved when a subscription changes plans. Default: false (discount is removed on plan change)

restricted_to
string[]
مطلوب

List of product IDs to which this discount is restricted.

times_used
integer<int32>
مطلوب

How many times this discount has been used.

type
enum<string>
مطلوب

The type of discount. Currently only percentage is supported.

الخيارات المتاحة:
percentage
expires_at
string<date-time> | null

Optional date/time after which discount is expired.

name
string | null

Name for the Discount

subscription_cycles
integer<int32> | null

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.

usage_limit
integer<int32> | null

Usage limit for this discount, if any.

آخر تعديل في ١ أبريل ٢٠٢٦