---
displayed_sidebar: servicesSidebar
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# GiftCardService
Provides layer to manipulate gift cards.
## Constructors
### constructor
`**new GiftCardService**(«destructured»)`
#### Parameters
## Properties
`",
"description": "",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "__container__",
"type": "`any`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "__moduleDeclaration__",
"type": "`Record`",
"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
## Methods
### atomicPhase\_
`Protected **atomicPhase_**(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.
#### Parameters
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>
___
### create
`**create**(giftCard): Promise<[GiftCard](GiftCard.mdx)>`
Creates a gift card with provided data given that the data is validated.
#### Parameters
#### Returns
Promise<[GiftCard](GiftCard.mdx)>
___
### createTransaction
`**createTransaction**(data): Promise<string>`
#### Parameters
#### Returns
Promise<string>
___
### delete
`**delete**(giftCardId): Promise<void \| [GiftCard](GiftCard.mdx)>`
Deletes a gift card idempotently
#### Parameters
#### Returns
Promise<void \| [GiftCard](GiftCard.mdx)>
___
### list
`**list**(selector?, config?): Promise<[GiftCard](GiftCard.mdx)[]>`
#### Parameters
#### Returns
Promise<[GiftCard](GiftCard.mdx)[]>
___
### listAndCount
`**listAndCount**(selector?, config?): Promise<[[GiftCard](GiftCard.mdx)[], number]>`
#### Parameters
#### Returns
Promise<[[GiftCard](GiftCard.mdx)[], number]>
___
### retrieve
`**retrieve**(giftCardId, config?): Promise<[GiftCard](GiftCard.mdx)>`
Gets a gift card by id.
#### Parameters
#### Returns
Promise<[GiftCard](GiftCard.mdx)>
___
### retrieveByCode
`**retrieveByCode**(code, config?): Promise<[GiftCard](GiftCard.mdx)>`
#### Parameters
#### Returns
Promise<[GiftCard](GiftCard.mdx)>
___
### retrieve\_
`Protected **retrieve_**(selector, config?): Promise<[GiftCard](GiftCard.mdx)>`
#### Parameters
#### Returns
Promise<[GiftCard](GiftCard.mdx)>
___
### shouldRetryTransaction\_
`Protected **shouldRetryTransaction_**(err): boolean`
#### Parameters
` \\| `{ code: string }`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`boolean`
___
### update
`**update**(giftCardId, update): Promise<[GiftCard](GiftCard.mdx)>`
Updates a giftCard.
#### Parameters
#### Returns
Promise<[GiftCard](GiftCard.mdx)>
___
### withTransaction
`**withTransaction**(transactionManager?): [GiftCardService](GiftCardService.mdx)`
#### Parameters
#### Returns
[GiftCardService](GiftCardService.mdx)
___
### generateCode
`Static **generateCode**(): string`
Generates a 16 character gift card code
#### Returns
`string`
___
### 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
#### Returns
``null`` \| `number`