Files
medusa-store/www/apps/docs/content/references/services/classes/GiftCardService.mdx
github-actions[bot] cdd42dbdcd chore(docs): Generated References (#5743)
Generated the following references:
- `entities`
- `inventory`
- `js-client`
- `pricing`
- `product`
- `services`
- `stock-location`
- `workflows`

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Shahed Nasser <27354907+shahednasser@users.noreply.github.com>
2023-11-27 18:58:52 +00:00

751 lines
15 KiB
Plaintext

---
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&#60;[GiftCard](GiftCard.mdx)&#62; & ``{ listGiftCardsAndCount: Method listGiftCardsAndCount }``",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "giftCardTransactionRepo_",
"type": "Repository&#60;[GiftCardTransaction](GiftCardTransaction.mdx)&#62;",
"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` **activeManager\_**: [object Object]
## Methods
#### atomicPhase\_
`Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise&#60;TResult&#62;`
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
Promise&#60;TResult&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;TResult&#62;",
"optional": false,
"defaultValue": "",
"description": "the result of the transactional work",
"expandable": false,
"children": []
}
]} />
___
#### create
`**create**(giftCard): Promise&#60;[GiftCard](GiftCard.mdx)&#62;`
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&#60;[GiftCard](GiftCard.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[GiftCard](GiftCard.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "the result of the create operation",
"expandable": false,
"children": []
}
]} />
___
#### createTransaction
`**createTransaction**(data): Promise&#60;string&#62;`
##### Parameters
<ParameterTypes parameters={[
{
"name": "data",
"type": "[CreateGiftCardTransactionInput](../types/CreateGiftCardTransactionInput.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;string&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;string&#62;",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
#### delete
`**delete**(giftCardId): Promise&#60;void \| [GiftCard](GiftCard.mdx)&#62;`
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&#60;void \| [GiftCard](GiftCard.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;void \\| [GiftCard](GiftCard.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "the result of the delete operation",
"expandable": false,
"children": []
}
]} />
___
#### list
`**list**(selector?, config?): Promise&#60;[GiftCard](GiftCard.mdx)[]&#62;`
##### Parameters
<ParameterTypes parameters={[
{
"name": "selector",
"type": "[QuerySelector](../types/QuerySelector.mdx)&#60;[GiftCard](GiftCard.mdx)&#62;",
"description": "the query object for find",
"optional": false,
"defaultValue": "{}",
"expandable": false,
"children": []
},
{
"name": "config",
"type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[GiftCard](GiftCard.mdx)&#62;",
"description": "the configuration used to find the objects. contains relations, skip, and take.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;[GiftCard](GiftCard.mdx)[]&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[GiftCard](GiftCard.mdx)[]&#62;",
"optional": false,
"defaultValue": "",
"description": "the result of the find operation",
"expandable": false,
"children": []
}
]} />
___
#### listAndCount
`**listAndCount**(selector?, config?): Promise&#60;[[GiftCard](GiftCard.mdx)[], number]&#62;`
##### Parameters
<ParameterTypes parameters={[
{
"name": "selector",
"type": "[QuerySelector](../types/QuerySelector.mdx)&#60;[GiftCard](GiftCard.mdx)&#62;",
"description": "the query object for find",
"optional": false,
"defaultValue": "{}",
"expandable": false,
"children": []
},
{
"name": "config",
"type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[GiftCard](GiftCard.mdx)&#62;",
"description": "the configuration used to find the objects. contains relations, skip, and take.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;[[GiftCard](GiftCard.mdx)[], number]&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[[GiftCard](GiftCard.mdx)[], number]&#62;",
"optional": false,
"defaultValue": "",
"description": "the result of the find operation",
"expandable": false,
"children": []
}
]} />
___
#### retrieve
`**retrieve**(giftCardId, config?): Promise&#60;[GiftCard](GiftCard.mdx)&#62;`
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)&#60;[GiftCard](GiftCard.mdx)&#62;",
"description": "optional values to include with gift card query",
"optional": false,
"defaultValue": "{}",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;[GiftCard](GiftCard.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[GiftCard](GiftCard.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "the gift card",
"expandable": false,
"children": []
}
]} />
___
#### retrieveByCode
`**retrieveByCode**(code, config?): Promise&#60;[GiftCard](GiftCard.mdx)&#62;`
##### Parameters
<ParameterTypes parameters={[
{
"name": "code",
"type": "`string`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "config",
"type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[GiftCard](GiftCard.mdx)&#62;",
"description": "",
"optional": false,
"defaultValue": "{}",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;[GiftCard](GiftCard.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[GiftCard](GiftCard.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
#### retrieve\_
`Protected **retrieve_**(selector, config?): Promise&#60;[GiftCard](GiftCard.mdx)&#62;`
##### Parameters
<ParameterTypes parameters={[
{
"name": "selector",
"type": "[Selector](../types/Selector.mdx)&#60;[GiftCard](GiftCard.mdx)&#62;",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "config",
"type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[GiftCard](GiftCard.mdx)&#62;",
"description": "",
"optional": false,
"defaultValue": "{}",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;[GiftCard](GiftCard.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[GiftCard](GiftCard.mdx)&#62;",
"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&#60;[GiftCard](GiftCard.mdx)&#62;`
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&#60;[GiftCard](GiftCard.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[GiftCard](GiftCard.mdx)&#62;",
"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": []
}
]} />