@shopfront/bridge 1.20.5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/{shopfront-embedded-bridge.iml → embedded-bridge.iml} +3 -1
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +1 -1
- package/.idea/php.xml +0 -1
- package/.idea/vcs.xml +1 -1
- package/eslint.config.js +16 -0
- package/jest.config.js +8 -0
- package/lib/APIs/CurrentSale/Exceptions.d.ts +6 -0
- package/lib/APIs/CurrentSale/Exceptions.js +15 -0
- package/lib/APIs/CurrentSale/Sale.d.ts +182 -0
- package/lib/APIs/CurrentSale/Sale.js +290 -0
- package/lib/APIs/CurrentSale/SaleCustomer.d.ts +10 -0
- package/lib/APIs/CurrentSale/SaleCustomer.js +17 -0
- package/lib/APIs/CurrentSale/SalePayment.d.ts +68 -0
- package/lib/APIs/CurrentSale/SalePayment.js +99 -0
- package/lib/APIs/CurrentSale/SaleProduct.d.ts +121 -0
- package/lib/APIs/CurrentSale/SaleProduct.js +167 -0
- package/lib/APIs/CurrentSale/ShopfrontSaleState.d.ts +53 -0
- package/lib/APIs/CurrentSale/ShopfrontSaleState.js +2 -0
- package/lib/APIs/CurrentSale/index.d.ts +6 -0
- package/lib/APIs/CurrentSale/index.js +37 -0
- package/lib/Application.js +0 -12
- package/lib/ApplicationEvents.d.ts +0 -12
- package/lib/ApplicationEvents.js +0 -1
- package/package.json +11 -10
- package/lib/Events/CheckGiftCardCollision.d.ts +0 -14
- package/lib/Events/CheckGiftCardCollision.js +0 -25
- package/lib/Events/GiftCardCodeCheck.d.ts +0 -14
- package/lib/Events/GiftCardCodeCheck.js +0 -21
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
2
|
<module type="WEB_MODULE" version="4">
|
|
3
3
|
<component name="NewModuleRootManager">
|
|
4
|
-
<content url="file://$MODULE_DIR$"
|
|
4
|
+
<content url="file://$MODULE_DIR$">
|
|
5
|
+
<excludeFolder url="file://$MODULE_DIR$/lib" />
|
|
6
|
+
</content>
|
|
5
7
|
<orderEntry type="inheritedJdk" />
|
|
6
8
|
<orderEntry type="sourceFolder" forTests="false" />
|
|
7
9
|
</component>
|
package/.idea/misc.xml
ADDED
package/.idea/modules.xml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<project version="4">
|
|
3
3
|
<component name="ProjectModuleManager">
|
|
4
4
|
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/embedded-bridge.iml" filepath="$PROJECT_DIR$/.idea/embedded-bridge.iml" />
|
|
6
6
|
</modules>
|
|
7
7
|
</component>
|
|
8
8
|
</project>
|
package/.idea/php.xml
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
<option name="transferred" value="true" />
|
|
8
8
|
</component>
|
|
9
9
|
<component name="PHPCodeSnifferOptionsConfiguration">
|
|
10
|
-
<option name="highlightLevel" value="WARNING" />
|
|
11
10
|
<option name="transferred" value="true" />
|
|
12
11
|
</component>
|
|
13
12
|
<component name="PhpStanOptionsConfiguration">
|
package/.idea/vcs.xml
CHANGED
package/eslint.config.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { coreLintingRules } from "@onshopfront/core/linting";
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
...coreLintingRules({}),
|
|
5
|
+
{
|
|
6
|
+
ignores: [
|
|
7
|
+
"lib/**",
|
|
8
|
+
"tests/**",
|
|
9
|
+
"**/*.js",
|
|
10
|
+
],
|
|
11
|
+
}, {
|
|
12
|
+
rules: {
|
|
13
|
+
"@typescript-eslint/no-useless-constructor": 0
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
]
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvalidSaleDeviceError = exports.SaleCancelledError = void 0;
|
|
4
|
+
class SaleCancelledError extends Error {
|
|
5
|
+
constructor() {
|
|
6
|
+
super("The sale is no longer active.");
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.SaleCancelledError = SaleCancelledError;
|
|
10
|
+
class InvalidSaleDeviceError extends Error {
|
|
11
|
+
constructor() {
|
|
12
|
+
super("This device is no longer a register able to perform a sale.");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.InvalidSaleDeviceError = InvalidSaleDeviceError;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { Application } from "../../Application";
|
|
2
|
+
import { ShopfrontSaleState } from "./ShopfrontSaleState";
|
|
3
|
+
import { SaleUpdate, SaleUpdateChanges } from "../../Actions/SaleUpdate";
|
|
4
|
+
import { SaleProduct } from "./SaleProduct";
|
|
5
|
+
import { SalePayment } from "./SalePayment";
|
|
6
|
+
import { SaleCustomer } from "./SaleCustomer";
|
|
7
|
+
export declare class Sale {
|
|
8
|
+
protected application: Application;
|
|
9
|
+
protected sale: ShopfrontSaleState;
|
|
10
|
+
protected cancelled: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Create a sale from a sale state.
|
|
13
|
+
* It's highly recommend to not construct a sale manually, instead use application.getCurrentSale().
|
|
14
|
+
*
|
|
15
|
+
* @param {Application} application
|
|
16
|
+
* @param {ShopfrontSaleState} sale
|
|
17
|
+
*/
|
|
18
|
+
constructor(application: Application, sale: ShopfrontSaleState);
|
|
19
|
+
/**
|
|
20
|
+
* Get the raw state of the sale, it is highly recommend that you DO NOT use this method as the
|
|
21
|
+
* returned data may be quite volatile.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
* @returns {ShopfrontSaleState}
|
|
25
|
+
*/
|
|
26
|
+
getRawState(): ShopfrontSaleState;
|
|
27
|
+
/**
|
|
28
|
+
* Update the sale to be the latest sale that exists on the sell screen.
|
|
29
|
+
*
|
|
30
|
+
* @returns {Promise<void>}
|
|
31
|
+
*/
|
|
32
|
+
refreshSale(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Check if the sale has already been cancelled, if it has, throw a SaleCancelledError.
|
|
35
|
+
*
|
|
36
|
+
* @protected
|
|
37
|
+
*/
|
|
38
|
+
protected checkIfCancelled(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Send a sale update to Shopfront.
|
|
41
|
+
*
|
|
42
|
+
* @protected
|
|
43
|
+
* @param {SaleUpdate} update
|
|
44
|
+
* @returns {Promise<void>}
|
|
45
|
+
*/
|
|
46
|
+
protected sendSaleUpdate(update: SaleUpdate<keyof SaleUpdateChanges>): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Get the products that are currently on the sale.
|
|
49
|
+
*
|
|
50
|
+
* @returns {Array<SaleProduct>}
|
|
51
|
+
*/
|
|
52
|
+
getProducts(): Array<SaleProduct>;
|
|
53
|
+
/**
|
|
54
|
+
* Get the payments that are currently on the sale.
|
|
55
|
+
*
|
|
56
|
+
* @returns {Array<SalePayment>}
|
|
57
|
+
*/
|
|
58
|
+
getPayments(): Array<SalePayment>;
|
|
59
|
+
/**
|
|
60
|
+
* Get the current customer on the sale.
|
|
61
|
+
*
|
|
62
|
+
* @returns {SaleCustomer | null}
|
|
63
|
+
*/
|
|
64
|
+
getCustomer(): null | SaleCustomer;
|
|
65
|
+
/**
|
|
66
|
+
* Get the external sale note (visible to the customer).
|
|
67
|
+
*
|
|
68
|
+
* @returns {string}
|
|
69
|
+
*/
|
|
70
|
+
getExternalNote(): string;
|
|
71
|
+
/**
|
|
72
|
+
* Get the internal sale note.
|
|
73
|
+
*
|
|
74
|
+
* @returns {string}
|
|
75
|
+
*/
|
|
76
|
+
getInternalNote(): string;
|
|
77
|
+
/**
|
|
78
|
+
* Get the order reference (visible to the customer).
|
|
79
|
+
*
|
|
80
|
+
* @returns {string}
|
|
81
|
+
*/
|
|
82
|
+
getOrderReference(): string;
|
|
83
|
+
/**
|
|
84
|
+
* Get the current meta data for the sale
|
|
85
|
+
*
|
|
86
|
+
* @returns {Record<string, unknown>}
|
|
87
|
+
*/
|
|
88
|
+
getMetaData(): Record<string, unknown>;
|
|
89
|
+
/**
|
|
90
|
+
* Cancel the current sale in progress.
|
|
91
|
+
*
|
|
92
|
+
* @returns {Promise<void>}
|
|
93
|
+
*/
|
|
94
|
+
cancelSale(): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Add a product to the sale.
|
|
97
|
+
*
|
|
98
|
+
* @param {SaleProduct} product
|
|
99
|
+
* @returns {Promise<void>}
|
|
100
|
+
*/
|
|
101
|
+
addProduct(product: SaleProduct): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Remove a product from the sale.
|
|
104
|
+
* It's highly recommended that you pass in a product that has been retrieved using sale.getProducts().
|
|
105
|
+
*
|
|
106
|
+
* @param {SaleProduct} product
|
|
107
|
+
* @returns {Promise<void>}
|
|
108
|
+
*/
|
|
109
|
+
removeProduct(product: SaleProduct): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Add a payment to the sell screen.
|
|
112
|
+
*
|
|
113
|
+
* If you specify a payment with a status, it will bypass the payment gateway (i.e. it won't request that the
|
|
114
|
+
* user takes money from the customer).
|
|
115
|
+
*
|
|
116
|
+
* If you don't specify a cashout amount, it will automatically determine if the payment method normally requests
|
|
117
|
+
* cashout (from the payment method settings).
|
|
118
|
+
*
|
|
119
|
+
* @param {SalePayment} payment
|
|
120
|
+
* @returns {Promise<void>}
|
|
121
|
+
*/
|
|
122
|
+
addPayment(payment: SalePayment): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Reverse a payment on the sell screen.
|
|
125
|
+
*
|
|
126
|
+
* This is used to issue a refund to the customer. The sale payment amount should be positive.
|
|
127
|
+
*
|
|
128
|
+
* @param {SalePayment} payment
|
|
129
|
+
* @returns {Promise<void>}
|
|
130
|
+
*/
|
|
131
|
+
reversePayment(payment: SalePayment): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Add a customer to the sale.
|
|
134
|
+
* If there is already a customer on the sale this will override that customer.
|
|
135
|
+
*
|
|
136
|
+
* @param {SaleCustomer} customer
|
|
137
|
+
* @returns {Promise<void>}
|
|
138
|
+
*/
|
|
139
|
+
addCustomer(customer: SaleCustomer): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Remove the customer from the current sale.
|
|
142
|
+
* If there is no customer currently on the sale this will be ignored.
|
|
143
|
+
* If there are "on account" or loyalty payments still on the sale, this will be ignored.
|
|
144
|
+
*
|
|
145
|
+
* @returns {Promise<void>}
|
|
146
|
+
*/
|
|
147
|
+
removeCustomer(): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Set the external note for the sale.
|
|
150
|
+
*
|
|
151
|
+
* @param {string} note The note to set.
|
|
152
|
+
* @param {boolean} append Whether to append the note to the current sale note.
|
|
153
|
+
* @returns {Promise<void>}
|
|
154
|
+
*/
|
|
155
|
+
setExternalNote(note: string, append?: boolean): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Set the internal note for the sale.
|
|
158
|
+
*
|
|
159
|
+
* @param {string} note The note to set.
|
|
160
|
+
* @param {boolean} append Whether to append the note to the current sale note.
|
|
161
|
+
* @returns {Promise<void>}
|
|
162
|
+
*/
|
|
163
|
+
setInternalNote(note: string, append?: boolean): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Set the order reference to the provided string.
|
|
166
|
+
*
|
|
167
|
+
* @param {string} reference
|
|
168
|
+
* @returns {Promise<void>}
|
|
169
|
+
*/
|
|
170
|
+
setOrderReference(reference: string): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Set the meta data of the sale, this will override the previous meta data.
|
|
173
|
+
*
|
|
174
|
+
* @param metaData
|
|
175
|
+
*/
|
|
176
|
+
setMetaData(metaData: Record<string, unknown>): Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* Update a product's details, currently this only updates the top-level meta data
|
|
179
|
+
* @param product
|
|
180
|
+
*/
|
|
181
|
+
updateProduct(product: SaleProduct): Promise<void>;
|
|
182
|
+
}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Sale = void 0;
|
|
4
|
+
const SaleUpdate_1 = require("../../Actions/SaleUpdate");
|
|
5
|
+
const SaleProduct_1 = require("./SaleProduct");
|
|
6
|
+
const SalePayment_1 = require("./SalePayment");
|
|
7
|
+
const SaleCustomer_1 = require("./SaleCustomer");
|
|
8
|
+
const Exceptions_1 = require("./Exceptions");
|
|
9
|
+
class Sale {
|
|
10
|
+
/**
|
|
11
|
+
* Create a sale from a sale state.
|
|
12
|
+
* It's highly recommend to not construct a sale manually, instead use application.getCurrentSale().
|
|
13
|
+
*
|
|
14
|
+
* @param {Application} application
|
|
15
|
+
* @param {ShopfrontSaleState} sale
|
|
16
|
+
*/
|
|
17
|
+
constructor(application, sale) {
|
|
18
|
+
this.application = application;
|
|
19
|
+
this.sale = sale;
|
|
20
|
+
this.cancelled = false;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get the raw state of the sale, it is highly recommend that you DO NOT use this method as the
|
|
24
|
+
* returned data may be quite volatile.
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
* @returns {ShopfrontSaleState}
|
|
28
|
+
*/
|
|
29
|
+
getRawState() {
|
|
30
|
+
return this.sale;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Update the sale to be the latest sale that exists on the sell screen.
|
|
34
|
+
*
|
|
35
|
+
* @returns {Promise<void>}
|
|
36
|
+
*/
|
|
37
|
+
async refreshSale() {
|
|
38
|
+
this.checkIfCancelled();
|
|
39
|
+
const newSale = await this.application.getCurrentSale();
|
|
40
|
+
if (newSale === false) {
|
|
41
|
+
throw new Exceptions_1.InvalidSaleDeviceError();
|
|
42
|
+
}
|
|
43
|
+
this.sale = newSale.getRawState();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if the sale has already been cancelled, if it has, throw a SaleCancelledError.
|
|
47
|
+
*
|
|
48
|
+
* @protected
|
|
49
|
+
*/
|
|
50
|
+
checkIfCancelled() {
|
|
51
|
+
if (this.cancelled) {
|
|
52
|
+
throw new Exceptions_1.SaleCancelledError();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Send a sale update to Shopfront.
|
|
57
|
+
*
|
|
58
|
+
* @protected
|
|
59
|
+
* @param {SaleUpdate} update
|
|
60
|
+
* @returns {Promise<void>}
|
|
61
|
+
*/
|
|
62
|
+
sendSaleUpdate(update) {
|
|
63
|
+
this.checkIfCancelled();
|
|
64
|
+
this.application.send(update);
|
|
65
|
+
return this.refreshSale();
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get the products that are currently on the sale.
|
|
69
|
+
*
|
|
70
|
+
* @returns {Array<SaleProduct>}
|
|
71
|
+
*/
|
|
72
|
+
getProducts() {
|
|
73
|
+
const products = [];
|
|
74
|
+
for (let i = 0, l = this.sale.products.length; i < l; i++) {
|
|
75
|
+
// The hydration method loops through child products so we don't have to
|
|
76
|
+
// worry about that here.
|
|
77
|
+
products.push(SaleProduct_1.SaleProduct.HydrateFromState(this.sale.products[i], [i]));
|
|
78
|
+
}
|
|
79
|
+
return products;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get the payments that are currently on the sale.
|
|
83
|
+
*
|
|
84
|
+
* @returns {Array<SalePayment>}
|
|
85
|
+
*/
|
|
86
|
+
getPayments() {
|
|
87
|
+
const payments = [];
|
|
88
|
+
for (let i = 0, l = this.sale.payments.length; i < l; i++) {
|
|
89
|
+
payments.push(SalePayment_1.SalePayment.HydrateFromState(this.sale.payments[i]));
|
|
90
|
+
}
|
|
91
|
+
return payments;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get the current customer on the sale.
|
|
95
|
+
*
|
|
96
|
+
* @returns {SaleCustomer | null}
|
|
97
|
+
*/
|
|
98
|
+
getCustomer() {
|
|
99
|
+
if (this.sale.customer === false) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
return new SaleCustomer_1.SaleCustomer(this.sale.customer.uuid);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get the external sale note (visible to the customer).
|
|
106
|
+
*
|
|
107
|
+
* @returns {string}
|
|
108
|
+
*/
|
|
109
|
+
getExternalNote() {
|
|
110
|
+
return this.sale.notes.sale;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get the internal sale note.
|
|
114
|
+
*
|
|
115
|
+
* @returns {string}
|
|
116
|
+
*/
|
|
117
|
+
getInternalNote() {
|
|
118
|
+
return this.sale.notes.internal;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get the order reference (visible to the customer).
|
|
122
|
+
*
|
|
123
|
+
* @returns {string}
|
|
124
|
+
*/
|
|
125
|
+
getOrderReference() {
|
|
126
|
+
return this.sale.orderReference;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get the current meta data for the sale
|
|
130
|
+
*
|
|
131
|
+
* @returns {Record<string, unknown>}
|
|
132
|
+
*/
|
|
133
|
+
getMetaData() {
|
|
134
|
+
return this.sale.metaData;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Cancel the current sale in progress.
|
|
138
|
+
*
|
|
139
|
+
* @returns {Promise<void>}
|
|
140
|
+
*/
|
|
141
|
+
async cancelSale() {
|
|
142
|
+
await this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("SALE_CANCEL", {}));
|
|
143
|
+
this.cancelled = true;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Add a product to the sale.
|
|
147
|
+
*
|
|
148
|
+
* @param {SaleProduct} product
|
|
149
|
+
* @returns {Promise<void>}
|
|
150
|
+
*/
|
|
151
|
+
addProduct(product) {
|
|
152
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PRODUCT_ADD", {
|
|
153
|
+
id: product.getId(),
|
|
154
|
+
quantity: product.getQuantity(),
|
|
155
|
+
price: product.getPrice(),
|
|
156
|
+
indexAddress: product.getIndexAddress(),
|
|
157
|
+
metaData: product.getMetaData(),
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Remove a product from the sale.
|
|
162
|
+
* It's highly recommended that you pass in a product that has been retrieved using sale.getProducts().
|
|
163
|
+
*
|
|
164
|
+
* @param {SaleProduct} product
|
|
165
|
+
* @returns {Promise<void>}
|
|
166
|
+
*/
|
|
167
|
+
removeProduct(product) {
|
|
168
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PRODUCT_REMOVE", {
|
|
169
|
+
id: product.getId(),
|
|
170
|
+
indexAddress: product.getIndexAddress(),
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Add a payment to the sell screen.
|
|
175
|
+
*
|
|
176
|
+
* If you specify a payment with a status, it will bypass the payment gateway (i.e. it won't request that the
|
|
177
|
+
* user takes money from the customer).
|
|
178
|
+
*
|
|
179
|
+
* If you don't specify a cashout amount, it will automatically determine if the payment method normally requests
|
|
180
|
+
* cashout (from the payment method settings).
|
|
181
|
+
*
|
|
182
|
+
* @param {SalePayment} payment
|
|
183
|
+
* @returns {Promise<void>}
|
|
184
|
+
*/
|
|
185
|
+
addPayment(payment) {
|
|
186
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PAYMENT_ADD", {
|
|
187
|
+
id: payment.getId(),
|
|
188
|
+
amount: payment.getAmount(),
|
|
189
|
+
cashout: payment.getCashout(),
|
|
190
|
+
status: payment.getStatus(),
|
|
191
|
+
}));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Reverse a payment on the sell screen.
|
|
195
|
+
*
|
|
196
|
+
* This is used to issue a refund to the customer. The sale payment amount should be positive.
|
|
197
|
+
*
|
|
198
|
+
* @param {SalePayment} payment
|
|
199
|
+
* @returns {Promise<void>}
|
|
200
|
+
*/
|
|
201
|
+
reversePayment(payment) {
|
|
202
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PAYMENT_REVERSE", {
|
|
203
|
+
id: payment.getId(),
|
|
204
|
+
amount: payment.getAmount(),
|
|
205
|
+
cashout: payment.getCashout(),
|
|
206
|
+
status: payment.getStatus(),
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Add a customer to the sale.
|
|
211
|
+
* If there is already a customer on the sale this will override that customer.
|
|
212
|
+
*
|
|
213
|
+
* @param {SaleCustomer} customer
|
|
214
|
+
* @returns {Promise<void>}
|
|
215
|
+
*/
|
|
216
|
+
addCustomer(customer) {
|
|
217
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("CUSTOMER_ADD", {
|
|
218
|
+
id: customer.getId(),
|
|
219
|
+
}));
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Remove the customer from the current sale.
|
|
223
|
+
* If there is no customer currently on the sale this will be ignored.
|
|
224
|
+
* If there are "on account" or loyalty payments still on the sale, this will be ignored.
|
|
225
|
+
*
|
|
226
|
+
* @returns {Promise<void>}
|
|
227
|
+
*/
|
|
228
|
+
removeCustomer() {
|
|
229
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("CUSTOMER_REMOVE", {}));
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Set the external note for the sale.
|
|
233
|
+
*
|
|
234
|
+
* @param {string} note The note to set.
|
|
235
|
+
* @param {boolean} append Whether to append the note to the current sale note.
|
|
236
|
+
* @returns {Promise<void>}
|
|
237
|
+
*/
|
|
238
|
+
setExternalNote(note, append = false) {
|
|
239
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("SALE_EXTERNAL_NOTE", {
|
|
240
|
+
note,
|
|
241
|
+
append,
|
|
242
|
+
}));
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Set the internal note for the sale.
|
|
246
|
+
*
|
|
247
|
+
* @param {string} note The note to set.
|
|
248
|
+
* @param {boolean} append Whether to append the note to the current sale note.
|
|
249
|
+
* @returns {Promise<void>}
|
|
250
|
+
*/
|
|
251
|
+
setInternalNote(note, append = false) {
|
|
252
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("SALE_INTERNAL_NOTE", {
|
|
253
|
+
note,
|
|
254
|
+
append,
|
|
255
|
+
}));
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Set the order reference to the provided string.
|
|
259
|
+
*
|
|
260
|
+
* @param {string} reference
|
|
261
|
+
* @returns {Promise<void>}
|
|
262
|
+
*/
|
|
263
|
+
setOrderReference(reference) {
|
|
264
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("SALE_ORDER_REFERENCE", {
|
|
265
|
+
reference,
|
|
266
|
+
}));
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Set the meta data of the sale, this will override the previous meta data.
|
|
270
|
+
*
|
|
271
|
+
* @param metaData
|
|
272
|
+
*/
|
|
273
|
+
setMetaData(metaData) {
|
|
274
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("SALE_META_DATA", {
|
|
275
|
+
metaData,
|
|
276
|
+
}));
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Update a product's details, currently this only updates the top-level meta data
|
|
280
|
+
* @param product
|
|
281
|
+
*/
|
|
282
|
+
updateProduct(product) {
|
|
283
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PRODUCT_UPDATE", {
|
|
284
|
+
id: product.getId(),
|
|
285
|
+
indexAddress: product.getIndexAddress(),
|
|
286
|
+
metaData: product.getMetaData(),
|
|
287
|
+
}));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
exports.Sale = Sale;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SaleCustomer = void 0;
|
|
4
|
+
class SaleCustomer {
|
|
5
|
+
constructor(id) {
|
|
6
|
+
this.id = id;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Get the ID of the customer.
|
|
10
|
+
*
|
|
11
|
+
* @returns {string}
|
|
12
|
+
*/
|
|
13
|
+
getId() {
|
|
14
|
+
return this.id;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.SaleCustomer = SaleCustomer;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ShopfrontSalePayment } from "./ShopfrontSaleState";
|
|
2
|
+
export declare enum SalePaymentStatus {
|
|
3
|
+
APPROVED = "completed",
|
|
4
|
+
DECLINED = "failed",
|
|
5
|
+
CANCELLED = "cancelled"
|
|
6
|
+
}
|
|
7
|
+
export declare class SalePayment {
|
|
8
|
+
protected id: string;
|
|
9
|
+
protected type?: string;
|
|
10
|
+
protected status?: SalePaymentStatus;
|
|
11
|
+
protected amount: number;
|
|
12
|
+
protected cashout?: number;
|
|
13
|
+
protected rounding?: number;
|
|
14
|
+
constructor(id: string, amount: number, cashout?: number, status?: SalePaymentStatus);
|
|
15
|
+
/**
|
|
16
|
+
* Hydrate a sale payment from the SaleState.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
* @param {ShopfrontSalePayment} payment
|
|
20
|
+
* @returns {SalePayment}
|
|
21
|
+
* @constructor
|
|
22
|
+
*/
|
|
23
|
+
static HydrateFromState(payment: ShopfrontSalePayment): SalePayment;
|
|
24
|
+
/**
|
|
25
|
+
* Set the internal data for the payment.
|
|
26
|
+
* This method is for hydration of the payment from Shopfront, it's highly recommend that you DO NOT use this method.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
* @param {ShopfrontSalePayment} data
|
|
30
|
+
*/
|
|
31
|
+
setInternal(data: ShopfrontSalePayment): void;
|
|
32
|
+
/**
|
|
33
|
+
* Get the ID of the sale payment method.
|
|
34
|
+
*
|
|
35
|
+
* @returns {string}
|
|
36
|
+
*/
|
|
37
|
+
getId(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Get the type of payment method this is.
|
|
40
|
+
*
|
|
41
|
+
* @returns {string | undefined}
|
|
42
|
+
*/
|
|
43
|
+
getType(): string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Get the status of this payment method.
|
|
46
|
+
*
|
|
47
|
+
* @returns {SalePaymentStatus | undefined}
|
|
48
|
+
*/
|
|
49
|
+
getStatus(): SalePaymentStatus | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Get the value of this payment method.
|
|
52
|
+
*
|
|
53
|
+
* @returns {number}
|
|
54
|
+
*/
|
|
55
|
+
getAmount(): number;
|
|
56
|
+
/**
|
|
57
|
+
* Get the cashout amount paid for on this payment method.
|
|
58
|
+
*
|
|
59
|
+
* @returns {number | undefined}
|
|
60
|
+
*/
|
|
61
|
+
getCashout(): number | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Get the amount of rounding applied to this payment method.
|
|
64
|
+
*
|
|
65
|
+
* @returns {number | undefined}
|
|
66
|
+
*/
|
|
67
|
+
getRounding(): number | undefined;
|
|
68
|
+
}
|