Skip to content

Commit

Permalink
Merge pull request #13 from ResaleAI/plugin-api-updates
Browse files Browse the repository at this point in the history
Plugin api updates
  • Loading branch information
zaviermiller authored May 20, 2024
2 parents abe75d6 + 454753d commit ee3e241
Show file tree
Hide file tree
Showing 218 changed files with 1,407 additions and 14,952 deletions.
21 changes: 10 additions & 11 deletions examples/movie-theater-node/components/AdmissionDisclaimer.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import ReceiptComponent from '@resaleai/receipt-components';
import { rc } from '@resaleai/receipt-components';

const AdmissionDisclaimer = new ReceiptComponent('AdmissionDisclaimer', {
render: () => `
<align mode="center">
***************************
<br />
Not valid for admission
<br />
***************************
</align>`,
});
function AdmissionDisclaimer(_props: null) {
return rc('align', { mode: 'center' }, [
rc('textLiteral', { text: '***************************' }),
rc('break'),
rc('textLiteral', { text: 'Not valid for admission' }),
rc('break'),
rc('textLiteral', { text: '***************************' }),
])
}

export default AdmissionDisclaimer;
222 changes: 111 additions & 111 deletions examples/movie-theater-node/components/LineItemList.ts
Original file line number Diff line number Diff line change
@@ -1,118 +1,118 @@
import ReceiptComponent from '@resaleai/receipt-components';
import hr from './hr';
import { serializeObject } from '../util';
import { LineItem } from '../types';
// import ReceiptComponent from '@resaleai/receipt-components';
// import hr from './hr';
// import { serializeObject } from '../util';
// import { LineItem } from '../types';

interface LineItemListItemProps {
item: string;
}
// interface LineItemListItemProps {
// item: string;
// }

interface LineItemListProps {
items: string;
paymentMethod: string;
}
// interface LineItemListProps {
// items: string;
// paymentMethod: string;
// }

const LineItemListItem = new ReceiptComponent<LineItemListItemProps>(
'LineItemListItem',
{
render: (props) => {
const item = JSON.parse(props.item);
// const LineItemListItem = new ReceiptComponent<LineItemListItemProps>(
// 'LineItemListItem',
// {
// render: (props) => {
// const item = JSON.parse(props.item);

const template = `
<row>
<col cols="7">
${item.name}
</col>
<col cols="1" justify="center">
${item.quantity}
</col>
<col cols="2" justify="right">
${item.price.toFixed(2)}
</col>
</row>
`;
return template;
},
}
);
// const template = `
// <row>
// <col cols="7">
// ${item.name}
// </col>
// <col cols="1" justify="center">
// ${item.quantity}
// </col>
// <col cols="2" justify="right">
// ${item.price.toFixed(2)}
// </col>
// </row>
// `;
// return template;
// },
// }
// );

const LineItemList = new ReceiptComponent<LineItemListProps>('LineItemList', {
render: (props) => {
const items: LineItem[] = JSON.parse(props.items);
const subtotal = items.reduce((acc, item) => acc + item.price, 0);
const tax = subtotal * 0.07;
const total = subtotal + tax;
// const LineItemList = new ReceiptComponent<LineItemListProps>('LineItemList', {
// render: (props) => {
// const items: LineItem[] = JSON.parse(props.items);
// const subtotal = items.reduce((acc, item) => acc + item.price, 0);
// const tax = subtotal * 0.07;
// const total = subtotal + tax;

const template = `
<fragment>
<hr />
<br />
<text bold>
<row>
<col cols="7">
Item
</col>
<col cols="1" justify="center">
Qty
</col>
<col cols="2" justify="right">
Price
</col>
</row>
</text>
<br />
<hr />
<row>
${items
.map(
(item) => `<LineItemListItem item="${serializeObject(item)}" /><br />`
)
.join('\n')}
<col cols="8"></col>
<col cols="2" justify="right">
-------
</col>
<col cols="5">
</col>
<col cols="3">
Subtotal:
</col>
<col cols="2" justify="right">
${subtotal.toFixed(2)}
</col>
<col cols="5">
</col>
<col cols="3">
TAX:
</col>
<col cols="2" justify="right">
${tax.toFixed(2)}
</col>
<col cols="5">
</col>
<col cols="3">
<scale height="2">
TOTAL:
</scale>
</col>
<col cols="2" justify="right">
<scale height="2">
${total.toFixed(2)}
</scale>
</col>
</row>
<br />
<text bold>
Payments:
</text>
<br />
<text> ${props.paymentMethod} ${total.toFixed(2)}</text>
<br />
</fragment>
`;
return template;
},
components: [LineItemListItem, hr],
});
// const template = `
// <fragment>
// <hr />
// <br />
// <text bold>
// <row>
// <col cols="7">
// Item
// </col>
// <col cols="1" justify="center">
// Qty
// </col>
// <col cols="2" justify="right">
// Price
// </col>
// </row>
// </text>
// <br />
// <hr />
// <row>
// ${items
// .map(
// (item) => `<LineItemListItem item="${serializeObject(item)}" /><br />`
// )
// .join('\n')}
// <col cols="8"></col>
// <col cols="2" justify="right">
// -------
// </col>
// <col cols="5">
// </col>
// <col cols="3">
// Subtotal:
// </col>
// <col cols="2" justify="right">
// ${subtotal.toFixed(2)}
// </col>
// <col cols="5">
// </col>
// <col cols="3">
// TAX:
// </col>
// <col cols="2" justify="right">
// ${tax.toFixed(2)}
// </col>
// <col cols="5">
// </col>
// <col cols="3">
// <scale height="2">
// TOTAL:
// </scale>
// </col>
// <col cols="2" justify="right">
// <scale height="2">
// ${total.toFixed(2)}
// </scale>
// </col>
// </row>
// <br />
// <text bold>
// Payments:
// </text>
// <br />
// <text> ${props.paymentMethod} ${total.toFixed(2)}</text>
// <br />
// </fragment>
// `;
// return template;
// },
// components: [LineItemListItem, hr],
// });

export default LineItemList;
// export default LineItemList;
54 changes: 26 additions & 28 deletions examples/movie-theater-node/components/RewardsInfo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ReceiptComponent from '@resaleai/receipt-components';
import { rc, text } from '@resaleai/receipt-components';
import hr from './hr';

interface RewardsInfoProps {
Expand All @@ -8,32 +8,30 @@ interface RewardsInfoProps {
creditBalance: number;
}

const RewardsInfo = new ReceiptComponent<RewardsInfoProps>('RewardsInfo', {
render: (props) => `
<fragment>
<hr />
<align mode="center">
<scale width="2" height="2">
MOVIE REWARDS
</scale>
<br />
Card No.: **********${props.cardNumberLast4}
<br />
Credits earned: ${props.creditsEarned}
<br />
Credits used: ${props.creditsUsed}
<br />
<inverse>
Credit Balance: ${props.creditBalance}
</inverse>
<br />
<scale height="2">
Register or choose rewards at MyReward.com
</scale>
</align>
</fragment>
`,
components: [hr],
});
function RewardsInfo(props: RewardsInfoProps) {
return rc('fragment', null, [
hr(),
rc('align', { mode: 'center' }, [
rc('scale', { width: 2, height: 2 }, [
text('MOVIE REWARDS'),
]),
rc('break'),
text(`Card No.: **********${props.cardNumberLast4}`),
rc('break'),
text(`Credits earned: ${props.creditsEarned}`),
rc('break'),
text(`Credits used: ${props.creditsUsed}`),
rc('break'),
rc('inverse', null, [
text(`Credit Balance: ${props.creditBalance}`),
]),
rc('break'),
rc('scale', { height: 2 }, [
text('Register or choose rewards at MyReward.com'),
]),

]),
]);
}

export default RewardsInfo;
45 changes: 21 additions & 24 deletions examples/movie-theater-node/components/TheaterHeader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ReceiptComponent from '@resaleai/receipt-components';
import ReceiptComponent, { rc, text } from '@resaleai/receipt-components';

interface TheaterHeaderProps {
theaterName: string;
Expand All @@ -8,28 +8,25 @@ interface TheaterHeaderProps {
zip: string;
}

const TheaterHeader = new ReceiptComponent<TheaterHeaderProps>(
'TheaterHeader',
{
render: (props) => `
<align mode="center">
<scale width="2" height="2">
${props.theaterName}
</scale>
<br />
<text font="2">
${props.address}
<br />
${props.city}, ${props.state} ${props.zip}
</text>
<br />
<inverse>
SALES RECEIPT
</inverse>
<br />
</align>
`,
}
);
function TheaterHeader(props: TheaterHeaderProps) {
return rc('fragment', null, [
rc('align', { mode: 'center' }, [
rc('scale', { width: 2, height: 2 }, [
text(props.theaterName)
]),
rc('break'),
rc('text', { font: 2 }, [
text(props.address),
rc('break'),
text(`${props.city}, ${props.state} ${props.zip}`),
]),
rc('break'),
rc('inverse', null, [
text('SALES RECEIPT')
]),
rc('break'),
]),
]);
}

export default TheaterHeader;
Loading

0 comments on commit ee3e241

Please sign in to comment.