Hoppa till huvudinnehåll
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
}

Auktoriseringar

Authorization
string
header
obligatorisk

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

Kropp

application/json

Request body for creating a discount.

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

amount
integer<int32>
obligatorisk

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

Must be at least 1.

type
enum<string>
obligatorisk

The discount type. Currently only percentage is supported.

Tillgängliga alternativ:
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.

Svar

Created discount

amount
integer<int32>
obligatorisk

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

business_id
string
obligatorisk

The business this discount belongs to.

code
string
obligatorisk

The discount code (up to 16 chars).

created_at
string<date-time>
obligatorisk

Timestamp when the discount is created

discount_id
string
obligatorisk

The unique discount ID

metadata
Metadata · object
obligatorisk

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

preserve_on_plan_change
boolean
obligatorisk

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

restricted_to
string[]
obligatorisk

List of product IDs to which this discount is restricted.

times_used
integer<int32>
obligatorisk

How many times this discount has been used.

type
enum<string>
obligatorisk

The type of discount. Currently only percentage is supported.

Tillgängliga alternativ:
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.

Senast ändrad 1 april 2026