@shopfront/bridge 1.16.0 → 1.18.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/codeStyles/Project.xml +121 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/modules.xml +1 -1
- package/.idea/{embedded-bridge.iml → shopfront-embedded-bridge.iml} +0 -0
- package/lib/APIs/Fulfilment/FulfilmentTypes.d.ts +43 -0
- package/lib/APIs/Fulfilment/FulfilmentTypes.js +2 -0
- package/lib/APIs/Sale/BaseSale.d.ts +147 -0
- package/lib/APIs/Sale/BaseSale.js +152 -0
- package/lib/APIs/Sale/CurrentSale.d.ts +132 -0
- package/lib/APIs/Sale/CurrentSale.js +210 -0
- package/lib/APIs/Sale/Exceptions.d.ts +6 -0
- package/lib/APIs/Sale/Exceptions.js +15 -0
- package/lib/APIs/Sale/Sale.d.ts +34 -0
- package/lib/APIs/Sale/Sale.js +116 -0
- package/lib/APIs/Sale/SaleCustomer.d.ts +10 -0
- package/lib/APIs/Sale/SaleCustomer.js +17 -0
- package/lib/APIs/Sale/SalePayment.d.ts +69 -0
- package/lib/APIs/Sale/SalePayment.js +104 -0
- package/lib/APIs/Sale/SaleProduct.d.ts +129 -0
- package/lib/APIs/Sale/SaleProduct.js +181 -0
- package/lib/APIs/Sale/ShopfrontSaleState.d.ts +56 -0
- package/lib/APIs/Sale/ShopfrontSaleState.js +2 -0
- package/lib/APIs/Sale/index.d.ts +9 -0
- package/lib/APIs/Sale/index.js +39 -0
- package/lib/Actions/SaleUpdate.d.ts +1 -1
- package/lib/Application.d.ts +19 -4
- package/lib/Application.js +88 -4
- package/lib/ApplicationEvents.d.ts +50 -2
- package/lib/ApplicationEvents.js +11 -0
- package/lib/EmitableEvents/Fulfilment/Options.d.ts +7 -0
- package/lib/EmitableEvents/Fulfilment/Options.js +11 -0
- package/lib/EmitableEvents/Fulfilment/OrderCancel.d.ts +6 -0
- package/lib/EmitableEvents/Fulfilment/OrderCancel.js +13 -0
- package/lib/EmitableEvents/Fulfilment/OrderCreate.d.ts +7 -0
- package/lib/EmitableEvents/Fulfilment/OrderCreate.js +13 -0
- package/lib/EmitableEvents/Fulfilment/OrderSaleCreate.d.ts +8 -0
- package/lib/EmitableEvents/Fulfilment/OrderSaleCreate.js +14 -0
- package/lib/EmitableEvents/Fulfilment/OrderUpdate.d.ts +7 -0
- package/lib/EmitableEvents/Fulfilment/OrderUpdate.js +13 -0
- package/lib/EmitableEvents/Fulfilment/OrdersSync.d.ts +8 -0
- package/lib/EmitableEvents/Fulfilment/OrdersSync.js +14 -0
- package/lib/EmitableEvents/Fulfilment/RegisterIntent.d.ts +11 -0
- package/lib/EmitableEvents/Fulfilment/RegisterIntent.js +17 -0
- package/lib/EmitableEvents/Fulfilment/index.d.ts +7 -0
- package/lib/EmitableEvents/Fulfilment/index.js +15 -0
- package/lib/EmitableEvents/SaleCreate.d.ts +31 -0
- package/lib/EmitableEvents/SaleCreate.js +63 -0
- package/lib/Events/FulfilmentCollectOrder.d.ts +6 -0
- package/lib/Events/FulfilmentCollectOrder.js +13 -0
- package/lib/Events/FulfilmentCompleteOrder.d.ts +6 -0
- package/lib/Events/FulfilmentCompleteOrder.js +13 -0
- package/lib/Events/FulfilmentGetOrder.d.ts +10 -0
- package/lib/Events/FulfilmentGetOrder.js +17 -0
- package/lib/Events/FulfilmentOrderApproval.d.ts +6 -0
- package/lib/Events/FulfilmentOrderApproval.js +13 -0
- package/lib/Events/FulfilmentProcessOrder.d.ts +14 -0
- package/lib/Events/FulfilmentProcessOrder.js +17 -0
- package/lib/Events/FulfilmentVoidOrder.d.ts +6 -0
- package/lib/Events/FulfilmentVoidOrder.js +13 -0
- package/lib/Utilities/SaleCreate.d.ts +25 -0
- package/lib/Utilities/SaleCreate.js +55 -0
- package/lib/Utilities/UUID.d.ts +12 -0
- package/lib/Utilities/UUID.js +46 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.js +3 -2
- package/package.json +1 -1
- package/.idea/misc.xml +0 -6
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurrentSale = void 0;
|
|
4
|
+
const BaseSale_1 = require("./BaseSale");
|
|
5
|
+
const SaleUpdate_1 = require("../../Actions/SaleUpdate");
|
|
6
|
+
const Exceptions_1 = require("./Exceptions");
|
|
7
|
+
const Sale_1 = require("./Sale");
|
|
8
|
+
class CurrentSale extends BaseSale_1.BaseSale {
|
|
9
|
+
/**
|
|
10
|
+
* Create a sale from a sale state.
|
|
11
|
+
* It's highly recommend to not construct a sale manually, instead use application.getCurrentSale().
|
|
12
|
+
*
|
|
13
|
+
* @param {Application} application
|
|
14
|
+
* @param {ShopfrontSaleState} saleState
|
|
15
|
+
*/
|
|
16
|
+
constructor(application, saleState) {
|
|
17
|
+
super(Sale_1.Sale.buildSaleData(saleState));
|
|
18
|
+
this.application = application;
|
|
19
|
+
this.cancelled = false;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Update the sale to be the latest sale that exists on the sell screen.
|
|
23
|
+
*
|
|
24
|
+
* @returns {Promise<void>}
|
|
25
|
+
*/
|
|
26
|
+
async refreshSale() {
|
|
27
|
+
this.checkIfCancelled();
|
|
28
|
+
const newSale = await this.application.getCurrentSale();
|
|
29
|
+
if (newSale === false) {
|
|
30
|
+
throw new Exceptions_1.InvalidSaleDeviceError();
|
|
31
|
+
}
|
|
32
|
+
this.hydrate(newSale);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Check if the sale has already been cancelled, if it has, throw a SaleCancelledError.
|
|
36
|
+
*
|
|
37
|
+
* @protected
|
|
38
|
+
*/
|
|
39
|
+
checkIfCancelled() {
|
|
40
|
+
if (this.cancelled) {
|
|
41
|
+
throw new Exceptions_1.SaleCancelledError();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Send a sale update to Shopfront.
|
|
46
|
+
*
|
|
47
|
+
* @protected
|
|
48
|
+
* @param {SaleUpdate} update
|
|
49
|
+
* @returns {Promise<void>}
|
|
50
|
+
*/
|
|
51
|
+
sendSaleUpdate(update) {
|
|
52
|
+
this.checkIfCancelled();
|
|
53
|
+
this.application.send(update);
|
|
54
|
+
return this.refreshSale();
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Cancel the current sale in progress.
|
|
58
|
+
*
|
|
59
|
+
* @returns {Promise<void>}
|
|
60
|
+
*/
|
|
61
|
+
async cancelSale() {
|
|
62
|
+
await this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("SALE_CANCEL", {}));
|
|
63
|
+
this.cancelled = true;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Add a product to the sale.
|
|
67
|
+
*
|
|
68
|
+
* @param {SaleProduct} product
|
|
69
|
+
* @returns {Promise<void>}
|
|
70
|
+
*/
|
|
71
|
+
addProduct(product) {
|
|
72
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PRODUCT_ADD", {
|
|
73
|
+
id: product.getId(),
|
|
74
|
+
quantity: product.getQuantity(),
|
|
75
|
+
price: product.getPrice(),
|
|
76
|
+
indexAddress: product.getIndexAddress(),
|
|
77
|
+
metaData: product.getMetaData(),
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Remove a product from the sale.
|
|
82
|
+
* It's highly recommended that you pass in a product that has been retrieved using sale.getProducts().
|
|
83
|
+
*
|
|
84
|
+
* @param {SaleProduct} product
|
|
85
|
+
* @returns {Promise<void>}
|
|
86
|
+
*/
|
|
87
|
+
removeProduct(product) {
|
|
88
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PRODUCT_REMOVE", {
|
|
89
|
+
id: product.getId(),
|
|
90
|
+
indexAddress: product.getIndexAddress(),
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Add a payment to the sell screen.
|
|
95
|
+
*
|
|
96
|
+
* If you specify a payment with a status, it will bypass the payment gateway (i.e. it won't request that the
|
|
97
|
+
* user takes money from the customer).
|
|
98
|
+
*
|
|
99
|
+
* If you don't specify a cashout amount, it will automatically determine if the payment method normally requests
|
|
100
|
+
* cashout (from the payment method settings).
|
|
101
|
+
*
|
|
102
|
+
* @param {SalePayment} payment
|
|
103
|
+
* @returns {Promise<void>}
|
|
104
|
+
*/
|
|
105
|
+
addPayment(payment) {
|
|
106
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PAYMENT_ADD", {
|
|
107
|
+
id: payment.getId(),
|
|
108
|
+
amount: payment.getAmount(),
|
|
109
|
+
cashout: payment.getCashout(),
|
|
110
|
+
status: payment.getStatus(),
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Reverse a payment on the sell screen.
|
|
115
|
+
*
|
|
116
|
+
* This is used to issue a refund to the customer. The sale payment amount should be positive.
|
|
117
|
+
*
|
|
118
|
+
* @param {SalePayment} payment
|
|
119
|
+
* @returns {Promise<void>}
|
|
120
|
+
*/
|
|
121
|
+
reversePayment(payment) {
|
|
122
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PAYMENT_REVERSE", {
|
|
123
|
+
id: payment.getId(),
|
|
124
|
+
amount: payment.getAmount(),
|
|
125
|
+
cashout: payment.getCashout(),
|
|
126
|
+
status: payment.getStatus(),
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Add a customer to the sale.
|
|
131
|
+
* If there is already a customer on the sale this will override that customer.
|
|
132
|
+
*
|
|
133
|
+
* @param {SaleCustomer} customer
|
|
134
|
+
* @returns {Promise<void>}
|
|
135
|
+
*/
|
|
136
|
+
addCustomer(customer) {
|
|
137
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("CUSTOMER_ADD", {
|
|
138
|
+
id: customer.getId(),
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Remove the customer from the current sale.
|
|
143
|
+
* If there is no customer currently on the sale this will be ignored.
|
|
144
|
+
* If there are "on account" or loyalty payments still on the sale, this will be ignored.
|
|
145
|
+
*
|
|
146
|
+
* @returns {Promise<void>}
|
|
147
|
+
*/
|
|
148
|
+
removeCustomer() {
|
|
149
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("CUSTOMER_REMOVE", {}));
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Set the external note for the sale.
|
|
153
|
+
*
|
|
154
|
+
* @param {string} note The note to set.
|
|
155
|
+
* @param {boolean} append Whether to append the note to the current sale note.
|
|
156
|
+
* @returns {Promise<void>}
|
|
157
|
+
*/
|
|
158
|
+
setExternalNote(note, append = false) {
|
|
159
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("SALE_EXTERNAL_NOTE", {
|
|
160
|
+
note,
|
|
161
|
+
append,
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Set the internal note for the sale.
|
|
166
|
+
*
|
|
167
|
+
* @param {string} note The note to set.
|
|
168
|
+
* @param {boolean} append Whether to append the note to the current sale note.
|
|
169
|
+
* @returns {Promise<void>}
|
|
170
|
+
*/
|
|
171
|
+
setInternalNote(note, append = false) {
|
|
172
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("SALE_INTERNAL_NOTE", {
|
|
173
|
+
note,
|
|
174
|
+
append,
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Set the order reference to the provided string.
|
|
179
|
+
*
|
|
180
|
+
* @param {string} reference
|
|
181
|
+
* @returns {Promise<void>}
|
|
182
|
+
*/
|
|
183
|
+
setOrderReference(reference) {
|
|
184
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("SALE_ORDER_REFERENCE", {
|
|
185
|
+
reference,
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Set the meta data of the sale, this will override the previous meta data.
|
|
190
|
+
*
|
|
191
|
+
* @param metaData
|
|
192
|
+
*/
|
|
193
|
+
setMetaData(metaData) {
|
|
194
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("SALE_META_DATA", {
|
|
195
|
+
metaData,
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Update a product's details, currently this only updates the top-level meta data
|
|
200
|
+
* @param product
|
|
201
|
+
*/
|
|
202
|
+
updateProduct(product) {
|
|
203
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PRODUCT_UPDATE", {
|
|
204
|
+
id: product.getId(),
|
|
205
|
+
indexAddress: product.getIndexAddress(),
|
|
206
|
+
metaData: product.getMetaData(),
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.CurrentSale = CurrentSale;
|
|
@@ -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,34 @@
|
|
|
1
|
+
import { BaseSale, SaleData } from "./BaseSale";
|
|
2
|
+
import { SaleCustomer } from "./SaleCustomer";
|
|
3
|
+
import { SalePayment } from "./SalePayment";
|
|
4
|
+
import { SaleProduct } from "./SaleProduct";
|
|
5
|
+
import { Application } from "../../Application";
|
|
6
|
+
import { ShopfrontSaleState } from "./ShopfrontSaleState";
|
|
7
|
+
export declare class Sale extends BaseSale {
|
|
8
|
+
protected created: boolean;
|
|
9
|
+
protected creating: boolean;
|
|
10
|
+
constructor(data: SaleData);
|
|
11
|
+
addCustomer(customer: SaleCustomer): Promise<void>;
|
|
12
|
+
addPayment(payment: SalePayment): Promise<void>;
|
|
13
|
+
addProduct(product: SaleProduct): Promise<void>;
|
|
14
|
+
removeCustomer(): Promise<void>;
|
|
15
|
+
removeProduct(product: SaleProduct): Promise<void>;
|
|
16
|
+
removePayment(payment: SalePayment): Promise<void>;
|
|
17
|
+
setExternalNote(note: string, append?: boolean): Promise<void>;
|
|
18
|
+
setInternalNote(note: string, append?: boolean): Promise<void>;
|
|
19
|
+
setMetaData(metaData: Record<string, unknown>): Promise<void>;
|
|
20
|
+
setOrderReference(reference: string): Promise<void>;
|
|
21
|
+
updateProduct(product: SaleProduct): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Create the sale on the server
|
|
24
|
+
*/
|
|
25
|
+
create(application: Application): Promise<{
|
|
26
|
+
success: boolean;
|
|
27
|
+
message?: string;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Converts the sale state to the sale data
|
|
31
|
+
* @param saleState
|
|
32
|
+
*/
|
|
33
|
+
static buildSaleData(saleState: ShopfrontSaleState): SaleData;
|
|
34
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Sale = void 0;
|
|
4
|
+
const BaseSale_1 = require("./BaseSale");
|
|
5
|
+
const SaleCustomer_1 = require("./SaleCustomer");
|
|
6
|
+
const SalePayment_1 = require("./SalePayment");
|
|
7
|
+
const SaleProduct_1 = require("./SaleProduct");
|
|
8
|
+
class Sale extends BaseSale_1.BaseSale {
|
|
9
|
+
constructor(data) {
|
|
10
|
+
super(data);
|
|
11
|
+
this.created = false;
|
|
12
|
+
this.creating = false;
|
|
13
|
+
}
|
|
14
|
+
async addCustomer(customer) {
|
|
15
|
+
this.customer = customer;
|
|
16
|
+
}
|
|
17
|
+
async addPayment(payment) {
|
|
18
|
+
if (this.payments.find(p => p.internalId === payment.internalId)) {
|
|
19
|
+
throw new TypeError("Payment has already been added to sale.");
|
|
20
|
+
}
|
|
21
|
+
this.payments.push(payment);
|
|
22
|
+
}
|
|
23
|
+
async addProduct(product) {
|
|
24
|
+
if (this.products.find(p => p.internalId === product.internalId)) {
|
|
25
|
+
throw new TypeError("Product has already been added to sale.");
|
|
26
|
+
}
|
|
27
|
+
this.products.push(product);
|
|
28
|
+
}
|
|
29
|
+
async removeCustomer() {
|
|
30
|
+
this.customer = null;
|
|
31
|
+
}
|
|
32
|
+
async removeProduct(product) {
|
|
33
|
+
const index = this.products.findIndex(p => p.internalId === product.internalId);
|
|
34
|
+
if (index === -1) {
|
|
35
|
+
throw new TypeError("Product could not be found in the sale.");
|
|
36
|
+
}
|
|
37
|
+
this.products.splice(index, 1);
|
|
38
|
+
}
|
|
39
|
+
async removePayment(payment) {
|
|
40
|
+
const index = this.payments.findIndex(p => p.internalId === payment.internalId);
|
|
41
|
+
if (index === -1) {
|
|
42
|
+
throw new TypeError("Payment could not be found in the sale.");
|
|
43
|
+
}
|
|
44
|
+
this.payments.splice(index, 1);
|
|
45
|
+
}
|
|
46
|
+
async setExternalNote(note, append) {
|
|
47
|
+
if (append) {
|
|
48
|
+
this.sale.notes.sale += note;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this.sale.notes.sale = note;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async setInternalNote(note, append) {
|
|
55
|
+
if (append) {
|
|
56
|
+
this.sale.notes.internal += note;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
this.sale.notes.internal = note;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async setMetaData(metaData) {
|
|
63
|
+
this.sale.metaData = metaData;
|
|
64
|
+
}
|
|
65
|
+
async setOrderReference(reference) {
|
|
66
|
+
this.sale.orderReference = reference;
|
|
67
|
+
}
|
|
68
|
+
async updateProduct(product) {
|
|
69
|
+
const index = this.products.findIndex(p => p.internalId === product.internalId);
|
|
70
|
+
if (index === -1) {
|
|
71
|
+
throw new TypeError("Product could not be found in the sale.");
|
|
72
|
+
}
|
|
73
|
+
this.products[index] = product;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Create the sale on the server
|
|
77
|
+
*/
|
|
78
|
+
async create(application) {
|
|
79
|
+
if (this.creating) {
|
|
80
|
+
throw new TypeError("Create function is currently running");
|
|
81
|
+
}
|
|
82
|
+
if (this.created) {
|
|
83
|
+
throw new TypeError("Sale has already been created");
|
|
84
|
+
}
|
|
85
|
+
this.creating = true;
|
|
86
|
+
const results = await application.createSale(this);
|
|
87
|
+
if (results.success) {
|
|
88
|
+
this.created = true;
|
|
89
|
+
}
|
|
90
|
+
this.creating = false;
|
|
91
|
+
return results;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Converts the sale state to the sale data
|
|
95
|
+
* @param saleState
|
|
96
|
+
*/
|
|
97
|
+
static buildSaleData(saleState) {
|
|
98
|
+
return {
|
|
99
|
+
register: saleState.register,
|
|
100
|
+
clientId: saleState.clientId,
|
|
101
|
+
notes: saleState.notes,
|
|
102
|
+
totals: saleState.totals,
|
|
103
|
+
linkedTo: saleState.linkedTo,
|
|
104
|
+
orderReference: saleState.orderReference,
|
|
105
|
+
refundReason: saleState.refundReason,
|
|
106
|
+
priceSet: saleState.priceSet,
|
|
107
|
+
metaData: saleState.metaData,
|
|
108
|
+
customer: saleState.customer ? new SaleCustomer_1.SaleCustomer(saleState.customer.uuid) : null,
|
|
109
|
+
payments: saleState.payments.map(SalePayment_1.SalePayment.HydrateFromState),
|
|
110
|
+
products: saleState.products.map((product, index) => {
|
|
111
|
+
return SaleProduct_1.SaleProduct.HydrateFromState(product, [index]);
|
|
112
|
+
}),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
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,69 @@
|
|
|
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
|
+
readonly internalId: string;
|
|
9
|
+
protected id: string;
|
|
10
|
+
protected type?: string;
|
|
11
|
+
protected status?: SalePaymentStatus;
|
|
12
|
+
protected amount: number;
|
|
13
|
+
protected cashout?: number;
|
|
14
|
+
protected rounding?: number;
|
|
15
|
+
constructor(id: string, amount: number, cashout?: number, status?: SalePaymentStatus);
|
|
16
|
+
/**
|
|
17
|
+
* Hydrate a sale payment from the SaleState.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
* @param {ShopfrontSalePayment} payment
|
|
21
|
+
* @returns {SalePayment}
|
|
22
|
+
* @constructor
|
|
23
|
+
*/
|
|
24
|
+
static HydrateFromState(payment: ShopfrontSalePayment): SalePayment;
|
|
25
|
+
/**
|
|
26
|
+
* Set the internal data for the payment.
|
|
27
|
+
* This method is for hydration of the payment from Shopfront, it's highly recommend that you DO NOT use this method.
|
|
28
|
+
*
|
|
29
|
+
* @internal
|
|
30
|
+
* @param {ShopfrontSalePayment} data
|
|
31
|
+
*/
|
|
32
|
+
setInternal(data: ShopfrontSalePayment): void;
|
|
33
|
+
/**
|
|
34
|
+
* Get the ID of the sale payment method.
|
|
35
|
+
*
|
|
36
|
+
* @returns {string}
|
|
37
|
+
*/
|
|
38
|
+
getId(): string;
|
|
39
|
+
/**
|
|
40
|
+
* Get the type of payment method this is.
|
|
41
|
+
*
|
|
42
|
+
* @returns {string | undefined}
|
|
43
|
+
*/
|
|
44
|
+
getType(): string | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Get the status of this payment method.
|
|
47
|
+
*
|
|
48
|
+
* @returns {SalePaymentStatus | undefined}
|
|
49
|
+
*/
|
|
50
|
+
getStatus(): SalePaymentStatus | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Get the value of this payment method.
|
|
53
|
+
*
|
|
54
|
+
* @returns {number}
|
|
55
|
+
*/
|
|
56
|
+
getAmount(): number;
|
|
57
|
+
/**
|
|
58
|
+
* Get the cashout amount paid for on this payment method.
|
|
59
|
+
*
|
|
60
|
+
* @returns {number | undefined}
|
|
61
|
+
*/
|
|
62
|
+
getCashout(): number | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Get the amount of rounding applied to this payment method.
|
|
65
|
+
*
|
|
66
|
+
* @returns {number | undefined}
|
|
67
|
+
*/
|
|
68
|
+
getRounding(): number | undefined;
|
|
69
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SalePayment = exports.SalePaymentStatus = void 0;
|
|
7
|
+
const UUID_1 = __importDefault(require("../../Utilities/UUID"));
|
|
8
|
+
var SalePaymentStatus;
|
|
9
|
+
(function (SalePaymentStatus) {
|
|
10
|
+
SalePaymentStatus["APPROVED"] = "completed";
|
|
11
|
+
SalePaymentStatus["DECLINED"] = "failed";
|
|
12
|
+
SalePaymentStatus["CANCELLED"] = "cancelled";
|
|
13
|
+
})(SalePaymentStatus = exports.SalePaymentStatus || (exports.SalePaymentStatus = {}));
|
|
14
|
+
class SalePayment {
|
|
15
|
+
constructor(id, amount, cashout, status) {
|
|
16
|
+
this.internalId = UUID_1.default.generate();
|
|
17
|
+
this.id = id;
|
|
18
|
+
this.amount = amount;
|
|
19
|
+
this.cashout = cashout;
|
|
20
|
+
this.status = status;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Hydrate a sale payment from the SaleState.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
* @param {ShopfrontSalePayment} payment
|
|
27
|
+
* @returns {SalePayment}
|
|
28
|
+
* @constructor
|
|
29
|
+
*/
|
|
30
|
+
static HydrateFromState(payment) {
|
|
31
|
+
let status = SalePaymentStatus.APPROVED;
|
|
32
|
+
switch (payment.status) {
|
|
33
|
+
case "failed":
|
|
34
|
+
status = SalePaymentStatus.DECLINED;
|
|
35
|
+
break;
|
|
36
|
+
case "cancelled":
|
|
37
|
+
status = SalePaymentStatus.CANCELLED;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
const hydrated = new SalePayment(payment.method, payment.amount, payment.cashout, status);
|
|
41
|
+
hydrated.setInternal(payment);
|
|
42
|
+
return hydrated;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Set the internal data for the payment.
|
|
46
|
+
* This method is for hydration of the payment from Shopfront, it's highly recommend that you DO NOT use this method.
|
|
47
|
+
*
|
|
48
|
+
* @internal
|
|
49
|
+
* @param {ShopfrontSalePayment} data
|
|
50
|
+
*/
|
|
51
|
+
setInternal(data) {
|
|
52
|
+
this.type = data.type;
|
|
53
|
+
this.rounding = data.rounding;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get the ID of the sale payment method.
|
|
57
|
+
*
|
|
58
|
+
* @returns {string}
|
|
59
|
+
*/
|
|
60
|
+
getId() {
|
|
61
|
+
return this.id;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get the type of payment method this is.
|
|
65
|
+
*
|
|
66
|
+
* @returns {string | undefined}
|
|
67
|
+
*/
|
|
68
|
+
getType() {
|
|
69
|
+
return this.type;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get the status of this payment method.
|
|
73
|
+
*
|
|
74
|
+
* @returns {SalePaymentStatus | undefined}
|
|
75
|
+
*/
|
|
76
|
+
getStatus() {
|
|
77
|
+
return this.status;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get the value of this payment method.
|
|
81
|
+
*
|
|
82
|
+
* @returns {number}
|
|
83
|
+
*/
|
|
84
|
+
getAmount() {
|
|
85
|
+
return this.amount;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get the cashout amount paid for on this payment method.
|
|
89
|
+
*
|
|
90
|
+
* @returns {number | undefined}
|
|
91
|
+
*/
|
|
92
|
+
getCashout() {
|
|
93
|
+
return this.cashout;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get the amount of rounding applied to this payment method.
|
|
97
|
+
*
|
|
98
|
+
* @returns {number | undefined}
|
|
99
|
+
*/
|
|
100
|
+
getRounding() {
|
|
101
|
+
return this.rounding;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.SalePayment = SalePayment;
|