Skip to content

Latest commit

 

History

History
220 lines (157 loc) · 18.4 KB

README.md

File metadata and controls

220 lines (157 loc) · 18.4 KB

Discounts

(discounts)

Overview

Work with discounts.

Discounts - Paddle Developer Center https://paddle.stoplight.io/docs/next-gen-billing/entities/discounts

Available Operations

  • create - Create a discount
  • get - Get a discount
  • list - List discounts
  • update - Update a discount

create

Creates a new discount.

If successful, your response includes a copy of the new discount entity.

Example Usage

import { Paddle } from "Paddle";
import { CurrencyCode2, Type } from "Paddle/sdk/models/shared";

async function run() {
  const sdk = new Paddle({
    security: {
      bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
    },
  });

  const result = await sdk.discounts.create({
    amount: "486.59",
    description: "Multi-tiered motivating standardization",
    expiresAt: new Date("2024-10-12T07:20:50.52Z"),
    id: "dsc_01gv5kpg05xp104ek2fmgjwttf",
    restrictTo: [
      "string",
    ],
    type: Type.FlatPerSeat,
  });

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request shared.DiscountCreate ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.CreateDiscountResponse>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

get

Returns a discount using its ID.

Example Usage

import { Paddle } from "Paddle";

async function run() {
  const sdk = new Paddle({
    security: {
      bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
    },
  });

  const result = await sdk.discounts.get({
    discountId: "dsc_01gt218xfk7yztpvgmcazkes83",
  });

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request operations.GetDiscountRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.GetDiscountResponse>

Errors

Error Object Status Code Content Type
errors.GetDiscountResponseBody 404 application/json
errors.SDKError 4xx-5xx /

list

Returns a paginated list of discounts. Use the query parameters to page through results.

By default, Paddle returns discounts that are active. Use the status query parameter to return discounts that are archived or expired.

Example Usage

import { Paddle } from "Paddle";
import { StatusDiscount } from "Paddle/sdk/models/shared";

async function run() {
  const sdk = new Paddle({
    security: {
      bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
    },
  });

  const result = await sdk.discounts.list({
    code: "BLACKFRIDAY",
  });

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request operations.ListDiscountsRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.ListDiscountsResponse>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

update

Updates a discount using its ID.

If successful, your response includes a copy of the updated discount entity.

Example Usage

import { Paddle } from "Paddle";
import { CurrencyCode2, DiscountType, SchemaStatusDiscount } from "Paddle/sdk/models/shared";

async function run() {
  const sdk = new Paddle({
    security: {
      bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
    },
  });

  const result = await sdk.discounts.update({
    discount: {
      expiresAt: new Date("2024-10-12T07:20:50.52Z"),
      id: "dsc_01gv5kpg05xp104ek2fmgjwttf",
      restrictTo: [
        "string",
      ],
    },
    discountId: "dsc_01gt218xfk7yztpvgmcazkes83",
  });

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request operations.UpdateDiscountRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.UpdateDiscountResponse>

Errors

Error Object Status Code Content Type
errors.UpdateDiscountResponseBody 404 application/json
errors.SDKError 4xx-5xx /