Skip to content

Commit afa47f1

Browse files
committed
implement cash drawer api
1 parent e69b192 commit afa47f1

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed

.changeset/hip-shirts-drum.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/ui-extensions': minor
3+
---
4+
5+
implements the cash drawer api to the ui extensions repository
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs';
2+
import {generateJsxCodeBlock} from '../helpers/generateCodeBlock';
3+
import {TargetLink} from '../types/ExtensionTargetType';
4+
5+
const generateJsxCodeBlockForCashDrawerApi = (
6+
title: string,
7+
fileName: string,
8+
) => generateJsxCodeBlock(title, 'cash-drawer-api', fileName);
9+
10+
const data: ReferenceEntityTemplateSchema = {
11+
name: 'Cash Drawer API',
12+
description: `
13+
The Cash Drawer API is an API exposed to extensions for cash drawer functionality, specifically allowing UI extensions to control cash drawer operations.
14+
15+
#### Supporting targets
16+
- ${TargetLink.PosHomeTileRender}
17+
- ${TargetLink.PosHomeModalRender}
18+
- ${TargetLink.PosPurchasePostActionMenuItemRender}
19+
- ${TargetLink.PosPurchasePostActionRender}
20+
- ${TargetLink.PosPurchasePostBlockRender}
21+
- ${TargetLink.PosReturnPostActionMenuItemRender}
22+
- ${TargetLink.PosReturnPostActionRender}
23+
- ${TargetLink.PosReturnPostBlockRender}
24+
- ${TargetLink.PosExchangePostActionMenuItemRender}
25+
- ${TargetLink.PosExchangePostActionRender}
26+
- ${TargetLink.PosExchangePostBlockRender}
27+
`,
28+
isVisualComponent: false,
29+
type: 'APIs',
30+
definitions: [
31+
{
32+
title: 'CashDrawerApi',
33+
description: 'Interface for handling cash drawer operations.',
34+
type: 'CashDrawerApi',
35+
},
36+
],
37+
category: 'APIs',
38+
related: [],
39+
examples: {
40+
description: 'Examples of using the Cash Drawer API',
41+
examples: [
42+
{
43+
codeblock: generateJsxCodeBlockForCashDrawerApi(
44+
'Open the cash drawer',
45+
'default.example',
46+
),
47+
},
48+
],
49+
},
50+
};
51+
52+
export default data;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {render} from 'preact';
2+
3+
export default async () => {
4+
render(<Extension />, document.body);
5+
};
6+
7+
const Extension = () => {
8+
return (
9+
<s-page heading="Cash Drawer API">
10+
<s-scroll-box>
11+
<s-button
12+
onClick={() =>
13+
shopify.cashDrawer.open()
14+
}
15+
>
16+
Open cash drawer
17+
</s-button>
18+
</s-scroll-box>
19+
</s-page>
20+
);
21+
};

packages/ui-extensions/src/surfaces/point-of-sale/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export type {
77

88
export type {CartLineItemApi} from './api/cart-line-item-api/cart-line-item-api';
99

10+
export type {CashDrawerApi} from './api/cash-drawer-api/cash-drawer-api';
11+
1012
export type {ActionApi, ActionApiContent} from './api/action-api/action-api';
1113

1214
export type {StandardApi} from './api/standard/standard-api';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* The Cash Drawer API in POS UI extensions includes select cash drawer functionality.
3+
*/
4+
export interface CashDrawerApiContent {
5+
/**
6+
* Opens the connected cash drawer.
7+
*
8+
* @returns Void
9+
*
10+
*/
11+
open(): Promise<void>;
12+
}
13+
14+
/**
15+
* Interface for the Cash Drawer API
16+
*/
17+
export interface CashDrawerApi {
18+
cashDrawer: CashDrawerApiContent;
19+
}

0 commit comments

Comments
 (0)