메인 콘텐츠로 건너뛰기
POST
/
discounts
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.create({ amount: 0, type: 'percentage' });

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.create(
amount=0,
type="percentage",
)
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.New(context.TODO(), dodopayments.DiscountNewParams{
Amount: dodopayments.F(int64(0)),
Type: dodopayments.F(dodopayments.DiscountTypePercentage),
})
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.DiscountCreateParams;
import com.dodopayments.api.models.discounts.DiscountType;

public final class Main {
private Main() {}

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

DiscountCreateParams params = DiscountCreateParams.builder()
.amount(0)
.type(DiscountType.PERCENTAGE)
.build();
Discount discount = client.discounts().create(params);
}
}
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.DiscountCreateParams
import com.dodopayments.api.models.discounts.DiscountType

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

val params: DiscountCreateParams = DiscountCreateParams.builder()
.amount(0)
.type(DiscountType.PERCENTAGE)
.build()
val discount: Discount = client.discounts().create(params)
}
require "dodopayments"

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

discount = dodo_payments.discounts.create(amount: 0, type: :percentage)

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

var_dump($discount);
} catch (APIException $e) {
echo $e->getMessage();
}
using System;
using DodoPayments.Client;
using DodoPayments.Client.Models.Discounts;

DodoPaymentsClient client = new();

DiscountCreateParams parameters = new()
{
Amount = 0,
Type = DiscountType.Percentage,
};

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

Console.WriteLine(discount);
use dodopayments::Client;

#[tokio::main]
async fn main() -> dodopayments::Result<()> {
let client = Client::from_env()?;
let result = client
.discounts()
.create()
.body(dodopayments::models::DiscountsCreateParams {
amount: Some(0),
r#type: Some(Box::new(dodopayments::models::DiscountType::Percentage)),
..Default::default()
})
.await?;
println!("{result:?}");
Ok(())
}
curl --request POST \
--url https://test.dodopayments.com/discounts \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"amount": 123,
"type": "percentage",
"code": "<string>",
"expires_at": "2023-11-07T05:31:56Z",
"metadata": {},
"name": "<string>",
"preserve_on_plan_change": true,
"restricted_to": [
"<string>"
],
"subscription_cycles": 123,
"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.

본문

application/json

Request body for creating a discount.

code is optional; if not provided, we generate a random 16-char code.

amount
integer<int32>
필수

The discount amount in basis points (e.g. 540 means 5.4%, 10000 means 100%).

Must be at least 1.

type
enum<string>
필수

The discount type. Currently only percentage is supported.

사용 가능한 옵션:
percentage
code
string | null

Optionally supply a code (will be uppercased).

  • Must be at least 3 characters if provided.
  • If omitted, a random 16-character code is generated.
expires_at
string<date-time> | null

When the discount expires, if ever.

metadata
Metadata · object

Additional metadata for the discount

name
string | null
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[] | null

List of product IDs to restrict usage (if any).

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

How many times this discount can be used (if any). Must be >= 1 if provided.

응답

Created 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.

마지막 수정일 2026년 4월 1일