---
displayed_sidebar: servicesSidebar
---

import ParameterTypes from "@site/src/components/ParameterTypes"

# DiscountService

Provides layer to manipulate discounts.

## Implements

## constructor

### Parameters

<ParameterTypes parameters={[
  {
    "name": "__namedParameters",
    "type": "`Object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

___

## Properties

<ParameterTypes parameters={[
  {
    "name": "__configModule__",
    "type": "`Record<string, unknown>`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "__container__",
    "type": "`any`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "__moduleDeclaration__",
    "type": "`Record<string, unknown>`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "customerService_",
    "type": "[CustomerService](services.CustomerService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "discountConditionRepository_",
    "type": "Repository&#60;[DiscountCondition](../../entities/classes/entities.DiscountCondition.mdx)&#62; & `object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "discountConditionService_",
    "type": "[DiscountConditionService](services.DiscountConditionService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "discountRepository_",
    "type": "Repository&#60;[Discount](../../entities/classes/entities.Discount.mdx)&#62;",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "discountRuleRepository_",
    "type": "Repository&#60;[DiscountRule](../../entities/classes/entities.DiscountRule.mdx)&#62;",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "eventBus_",
    "type": "[EventBusService](services.EventBusService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "featureFlagRouter_",
    "type": "`FlagRouter`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "giftCardRepository_",
    "type": "Repository&#60;[GiftCard](../../entities/classes/entities.GiftCard.mdx)&#62; & `object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "manager_",
    "type": "`EntityManager`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "newTotalsService_",
    "type": "[NewTotalsService](services.NewTotalsService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "productService_",
    "type": "[ProductService](services.ProductService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "regionService_",
    "type": "[RegionService](services.RegionService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "totalsService_",
    "type": "[TotalsService](services.TotalsService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "transactionManager_",
    "type": "`undefined` \\| `EntityManager`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

___

## Accessors

### activeManager\_

#### Returns

<ParameterTypes parameters={[
  {
    "name": "EntityManager",
    "type": "`EntityManager`",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

## Methods

### addRegion

Adds a region to the discount regions array.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discountId",
    "type": "`string`",
    "description": "id of discount",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "regionId",
    "type": "`string`",
    "description": "id of region to add",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Discount](../../entities/classes/entities.Discount.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the update operation",
    "expandable": false,
    "children": []
  }
]} />

___

### atomicPhase\_

Wraps some work within a transactional block. If the service already has
a transaction manager attached this will be reused, otherwise a new
transaction manager is created.

#### Type Parameters

<ParameterTypes parameters={[
  {
    "name": "TResult",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "TError",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "work",
    "type": "(`transactionManager`: `EntityManager`) => Promise&#60;TResult&#62;",
    "description": "the transactional work to be done",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "isolationOrErrorHandler",
    "type": "`IsolationLevel` \\| (`error`: `TError`) => Promise&#60;void \\| TResult&#62;",
    "description": "the isolation level to be used for the work.",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "maybeErrorHandlerOrDontFail",
    "type": "(`error`: `TError`) => Promise&#60;void \\| TResult&#62;",
    "description": "Potential error handler",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;TResult&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the transactional work",
    "expandable": false,
    "children": []
  }
]} />

___

### calculateDiscountForLineItem

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discountId",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "lineItem",
    "type": "[LineItem](../../entities/classes/entities.LineItem.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "calculationContextData",
    "type": "`CalculationContextData`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;number&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### canApplyForCustomer

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discountRuleId",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "customerId",
    "type": "`undefined` \\| `string`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;boolean&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### create

Creates a discount with provided data given that the data is validated.
Normalizes discount code to uppercase.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discount",
    "type": "`CreateDiscountInput`",
    "description": "the discount data to create",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Discount](../../entities/classes/entities.Discount.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the create operation",
    "expandable": false,
    "children": []
  }
]} />

___

### createDynamicCode

Creates a dynamic code for a discount id.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discountId",
    "type": "`string`",
    "description": "the id of the discount to create a code for",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "data",
    "type": "`CreateDynamicDiscountInput`",
    "description": "the object containing a code to identify the discount by",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Discount](../../entities/classes/entities.Discount.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the newly created dynamic code",
    "expandable": false,
    "children": []
  }
]} />

___

### delete

Deletes a discount idempotently

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discountId",
    "type": "`string`",
    "description": "id of discount to delete",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;void&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the delete operation",
    "expandable": false,
    "children": []
  }
]} />

___

### deleteDynamicCode

Deletes a dynamic code for a discount id.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discountId",
    "type": "`string`",
    "description": "the id of the discount to create a code for",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "code",
    "type": "`string`",
    "description": "the code to identify the discount by",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;void&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the newly created dynamic code",
    "expandable": false,
    "children": []
  }
]} />

___

### hasCustomersGroupCondition

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discount",
    "type": "[Discount](../../entities/classes/entities.Discount.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "boolean",
    "type": "`boolean`",
    "optional": true,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### hasExpired

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discount",
    "type": "[Discount](../../entities/classes/entities.Discount.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "boolean",
    "type": "`boolean`",
    "optional": true,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### hasNotStarted

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discount",
    "type": "[Discount](../../entities/classes/entities.Discount.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "boolean",
    "type": "`boolean`",
    "optional": true,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### hasReachedLimit

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discount",
    "type": "[Discount](../../entities/classes/entities.Discount.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "boolean",
    "type": "`boolean`",
    "optional": true,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### isDisabled

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discount",
    "type": "[Discount](../../entities/classes/entities.Discount.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "boolean",
    "type": "`boolean`",
    "optional": true,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### isValidForRegion

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discount",
    "type": "[Discount](../../entities/classes/entities.Discount.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "region_id",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;boolean&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### list

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "selector",
    "type": "`FilterableDiscountProps`",
    "description": "the query object for find",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[Discount](../../entities/classes/entities.Discount.mdx)&#62;",
    "description": "the config object containing query settings",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Discount](../../entities/classes/entities.Discount.mdx)[]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the find operation",
    "expandable": false,
    "children": []
  }
]} />

___

### listAndCount

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "selector",
    "type": "`FilterableDiscountProps`",
    "description": "the query object for find",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[Discount](../../entities/classes/entities.Discount.mdx)&#62;",
    "description": "the config object containing query settings",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[[Discount](../../entities/classes/entities.Discount.mdx)[], number]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the find operation",
    "expandable": false,
    "children": []
  }
]} />

___

### listByCodes

List all the discounts corresponding to the given codes

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discountCodes",
    "type": "`string`[]",
    "description": "discount codes of discounts to retrieve",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[Discount](../../entities/classes/entities.Discount.mdx)&#62;",
    "description": "the config object containing query settings",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Discount](../../entities/classes/entities.Discount.mdx)[]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the discounts",
    "expandable": false,
    "children": []
  }
]} />

___

### removeRegion

Removes a region from the discount regions array.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discountId",
    "type": "`string`",
    "description": "id of discount",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "regionId",
    "type": "`string`",
    "description": "id of region to remove",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Discount](../../entities/classes/entities.Discount.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the update operation",
    "expandable": false,
    "children": []
  }
]} />

___

### retrieve

Gets a discount by id.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discountId",
    "type": "`string`",
    "description": "id of discount to retrieve",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[Discount](../../entities/classes/entities.Discount.mdx)&#62;",
    "description": "the config object containing query settings",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Discount](../../entities/classes/entities.Discount.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the discount",
    "expandable": false,
    "children": []
  }
]} />

___

### retrieveByCode

Gets the discount by discount code.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discountCode",
    "type": "`string`",
    "description": "discount code of discount to retrieve",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[Discount](../../entities/classes/entities.Discount.mdx)&#62;",
    "description": "the config object containing query settings",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Discount](../../entities/classes/entities.Discount.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the discount",
    "expandable": false,
    "children": []
  }
]} />

___

### shouldRetryTransaction\_

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "err",
    "type": "`Record<string, unknown>` \\| `object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "boolean",
    "type": "`boolean`",
    "optional": true,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### update

Updates a discount.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discountId",
    "type": "`string`",
    "description": "discount id of discount to update",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "update",
    "type": "`UpdateDiscountInput`",
    "description": "the data to update the discount with",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Discount](../../entities/classes/entities.Discount.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the update operation",
    "expandable": false,
    "children": []
  }
]} />

___

### validateDiscountForCartOrThrow

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "cart",
    "type": "[Cart](../../entities/classes/entities.Cart.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "discount",
    "type": "[Discount](../../entities/classes/entities.Discount.mdx) \\| [Discount](../../entities/classes/entities.Discount.mdx)[]",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;void&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### validateDiscountForProduct

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discountRuleId",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "productId",
    "type": "`string`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;boolean&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### validateDiscountRule\_

Creates a discount rule with provided data given that the data is validated.

#### Type Parameters

<ParameterTypes parameters={[
  {
    "name": "T",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "discountRule",
    "type": "`T`",
    "description": "the discount rule to create",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "T",
    "type": "`T`",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the create operation",
    "expandable": false,
    "children": []
  }
]} />

___

### withTransaction

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "transactionManager",
    "type": "`EntityManager`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "DiscountService",
    "type": "`object`",
    "description": "Provides layer to manipulate discounts.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />
