---
displayed_sidebar: servicesSidebar
---

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

# GiftCardService

Provides layer to manipulate gift cards.

## Constructors

### constructor

**new GiftCardService**(`«destructured»`)

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "__namedParameters",
    "type": "[`InjectedDependencies`](../types/InjectedDependencies-12.mdx)",
    "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": "eventBus_",
    "type": "[`EventBusService`](EventBusService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "giftCardRepository_",
    "type": "`Repository`<[`GiftCard`](GiftCard.mdx)\\> & { `listGiftCardsAndCount`: Method listGiftCardsAndCount  }",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "giftCardTransactionRepo_",
    "type": "`Repository`<[`GiftCardTransaction`](GiftCardTransaction.mdx)\\>",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "manager_",
    "type": "`EntityManager`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "regionService_",
    "type": "[`RegionService`](RegionService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "transactionManager_",
    "type": "`undefined` \\| `EntityManager`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "Events",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "Events.CREATED",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "\"gift_card.created\"",
    "expandable": false,
    "children": []
  }
]} />

## Accessors

### activeManager\_

`Protected` `get` **activeManager_**(): `EntityManager`

#### Returns

`EntityManager`

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

## Methods

### atomicPhase\_

`Protected` **atomicPhase_**<`TResult`, `TError`\>(`work`, `isolationOrErrorHandler?`, `maybeErrorHandlerOrDontFail?`): `Promise`<`TResult`\>

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.

<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`<`TResult`\\>",
    "description": "the transactional work to be done",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "isolationOrErrorHandler",
    "type": "`IsolationLevel` \\| (`error`: `TError`) => `Promise`<`void` \\| `TResult`\\>",
    "description": "the isolation level to be used for the work.",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "maybeErrorHandlerOrDontFail",
    "type": "(`error`: `TError`) => `Promise`<`void` \\| `TResult`\\>",
    "description": "Potential error handler",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

`Promise`<`TResult`\>

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

___

### create

**create**(`giftCard`): `Promise`<[`GiftCard`](GiftCard.mdx)\>

Creates a gift card with provided data given that the data is validated.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "giftCard",
    "type": "[`CreateGiftCardInput`](../types/CreateGiftCardInput.mdx)",
    "description": "the gift card data to create",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

`Promise`<[`GiftCard`](GiftCard.mdx)\>

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "`Promise`<[`GiftCard`](GiftCard.mdx)\\>",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the create operation",
    "expandable": false,
    "children": []
  }
]} />

___

### createTransaction

**createTransaction**(`data`): `Promise`<`string`\>

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "data",
    "type": "[`CreateGiftCardTransactionInput`](../types/CreateGiftCardTransactionInput.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

`Promise`<`string`\>

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

___

### delete

**delete**(`giftCardId`): `Promise`<`void` \| [`GiftCard`](GiftCard.mdx)\>

Deletes a gift card idempotently

#### Parameters

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

#### Returns

`Promise`<`void` \| [`GiftCard`](GiftCard.mdx)\>

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "`Promise`<`void` \\| [`GiftCard`](GiftCard.mdx)\\>",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the delete operation",
    "expandable": false,
    "children": []
  }
]} />

___

### list

**list**(`selector?`, `config?`): `Promise`<[`GiftCard`](GiftCard.mdx)[]\>

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "selector",
    "type": "[`QuerySelector`](../types/QuerySelector.mdx)<[`GiftCard`](GiftCard.mdx)\\>",
    "description": "the query object for find",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[`FindConfig`](../interfaces/FindConfig.mdx)<[`GiftCard`](GiftCard.mdx)\\>",
    "description": "the configuration used to find the objects. contains relations, skip, and take.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

`Promise`<[`GiftCard`](GiftCard.mdx)[]\>

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "`Promise`<[`GiftCard`](GiftCard.mdx)[]\\>",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the find operation",
    "expandable": false,
    "children": []
  }
]} />

___

### listAndCount

**listAndCount**(`selector?`, `config?`): `Promise`<[[`GiftCard`](GiftCard.mdx)[], `number`]\>

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "selector",
    "type": "[`QuerySelector`](../types/QuerySelector.mdx)<[`GiftCard`](GiftCard.mdx)\\>",
    "description": "the query object for find",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[`FindConfig`](../interfaces/FindConfig.mdx)<[`GiftCard`](GiftCard.mdx)\\>",
    "description": "the configuration used to find the objects. contains relations, skip, and take.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

`Promise`<[[`GiftCard`](GiftCard.mdx)[], `number`]\>

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "`Promise`<[[`GiftCard`](GiftCard.mdx)[], `number`]\\>",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the find operation",
    "expandable": false,
    "children": []
  }
]} />

___

### retrieve

**retrieve**(`giftCardId`, `config?`): `Promise`<[`GiftCard`](GiftCard.mdx)\>

Gets a gift card by id.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "giftCardId",
    "type": "`string`",
    "description": "id of gift card to retrieve",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[`FindConfig`](../interfaces/FindConfig.mdx)<[`GiftCard`](GiftCard.mdx)\\>",
    "description": "optional values to include with gift card query",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

`Promise`<[`GiftCard`](GiftCard.mdx)\>

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "`Promise`<[`GiftCard`](GiftCard.mdx)\\>",
    "optional": false,
    "defaultValue": "",
    "description": "the gift card",
    "expandable": false,
    "children": []
  }
]} />

___

### retrieveByCode

**retrieveByCode**(`code`, `config?`): `Promise`<[`GiftCard`](GiftCard.mdx)\>

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "code",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[`FindConfig`](../interfaces/FindConfig.mdx)<[`GiftCard`](GiftCard.mdx)\\>",
    "description": "",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

`Promise`<[`GiftCard`](GiftCard.mdx)\>

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "`Promise`<[`GiftCard`](GiftCard.mdx)\\>",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### retrieve\_

`Protected` **retrieve_**(`selector`, `config?`): `Promise`<[`GiftCard`](GiftCard.mdx)\>

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "selector",
    "type": "[`Selector`](../types/Selector.mdx)<[`GiftCard`](GiftCard.mdx)\\>",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[`FindConfig`](../interfaces/FindConfig.mdx)<[`GiftCard`](GiftCard.mdx)\\>",
    "description": "",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

`Promise`<[`GiftCard`](GiftCard.mdx)\>

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "`Promise`<[`GiftCard`](GiftCard.mdx)\\>",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### shouldRetryTransaction\_

`Protected` **shouldRetryTransaction_**(`err`): `boolean`

#### Parameters

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

#### Returns

`boolean`

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

___

### update

**update**(`giftCardId`, `update`): `Promise`<[`GiftCard`](GiftCard.mdx)\>

Updates a giftCard.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "giftCardId",
    "type": "`string`",
    "description": "giftCard id of giftCard to update",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "update",
    "type": "[`UpdateGiftCardInput`](../types/UpdateGiftCardInput.mdx)",
    "description": "the data to update the giftCard with",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

`Promise`<[`GiftCard`](GiftCard.mdx)\>

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "`Promise`<[`GiftCard`](GiftCard.mdx)\\>",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the update operation",
    "expandable": false,
    "children": []
  }
]} />

___

### withTransaction

**withTransaction**(`transactionManager?`): [`GiftCardService`](GiftCardService.mdx)

#### Parameters

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

#### Returns

[`GiftCardService`](GiftCardService.mdx)

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

___

### generateCode

`Static` **generateCode**(): `string`

Generates a 16 character gift card code

#### Returns

`string`

<ParameterTypes parameters={[
  {
    "name": "string",
    "type": "`string`",
    "optional": true,
    "defaultValue": "",
    "description": "the generated gift card code",
    "expandable": false,
    "children": []
  }
]} />

___

### resolveTaxRate

`Static` `Protected` **resolveTaxRate**(`giftCardTaxRate`, `region`): ``null`` \| `number`

The tax_rate of the giftcard can depend on whether regions tax gift cards, an input
provided by the user or the tax rate. Based on these conditions, tax_rate changes.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "giftCardTaxRate",
    "type": "``null`` \\| `number`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "region",
    "type": "[`Region`](Region.mdx)",
    "description": "A region holds settings specific to a geographical location, including the currency, tax rates, and fulfillment and payment providers. A Region can consist of multiple countries to accomodate common shopping settings across countries.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

``null`` \| `number`

<ParameterTypes parameters={[
  {
    "name": "``null`` \\| number",
    "type": "``null`` \\| `number`",
    "optional": true,
    "defaultValue": "",
    "description": "the tax rate for the gift card",
    "expandable": false,
    "children": []
  }
]} />
