@bates-solutions/squareup 0.1.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/LICENSE +21 -0
- package/README.md +154 -0
- package/README.md.backup +292 -0
- package/dist/angular/__tests__/setup.d.ts +1 -0
- package/dist/angular/__tests__/setup.d.ts.map +1 -0
- package/dist/angular/__tests__/setup.js +5 -0
- package/dist/angular/__tests__/setup.js.map +1 -0
- package/dist/angular/components/index.d.ts +2 -0
- package/dist/angular/components/index.d.ts.map +1 -0
- package/dist/angular/components/index.js +2 -0
- package/dist/angular/components/index.js.map +1 -0
- package/dist/angular/components/payment-button.component.d.ts +49 -0
- package/dist/angular/components/payment-button.component.d.ts.map +1 -0
- package/dist/angular/components/payment-button.component.js +176 -0
- package/dist/angular/components/payment-button.component.js.map +1 -0
- package/dist/angular/directives/index.d.ts +2 -0
- package/dist/angular/directives/index.d.ts.map +1 -0
- package/dist/angular/directives/index.js +2 -0
- package/dist/angular/directives/index.js.map +1 -0
- package/dist/angular/directives/square-card.directive.d.ts +52 -0
- package/dist/angular/directives/square-card.directive.d.ts.map +1 -0
- package/dist/angular/directives/square-card.directive.js +98 -0
- package/dist/angular/directives/square-card.directive.js.map +1 -0
- package/dist/angular/index.d.ts +42 -0
- package/dist/angular/index.d.ts.map +1 -0
- package/dist/angular/index.js +45 -0
- package/dist/angular/index.js.map +1 -0
- package/dist/angular/services/index.d.ts +6 -0
- package/dist/angular/services/index.d.ts.map +1 -0
- package/dist/angular/services/index.js +6 -0
- package/dist/angular/services/index.js.map +1 -0
- package/dist/angular/services/square-catalog.service.d.ts +60 -0
- package/dist/angular/services/square-catalog.service.d.ts.map +1 -0
- package/dist/angular/services/square-catalog.service.js +152 -0
- package/dist/angular/services/square-catalog.service.js.map +1 -0
- package/dist/angular/services/square-customers.service.d.ts +77 -0
- package/dist/angular/services/square-customers.service.d.ts.map +1 -0
- package/dist/angular/services/square-customers.service.js +187 -0
- package/dist/angular/services/square-customers.service.js.map +1 -0
- package/dist/angular/services/square-orders.service.d.ts +66 -0
- package/dist/angular/services/square-orders.service.d.ts.map +1 -0
- package/dist/angular/services/square-orders.service.js +170 -0
- package/dist/angular/services/square-orders.service.js.map +1 -0
- package/dist/angular/services/square-payments.service.d.ts +73 -0
- package/dist/angular/services/square-payments.service.d.ts.map +1 -0
- package/dist/angular/services/square-payments.service.js +167 -0
- package/dist/angular/services/square-payments.service.js.map +1 -0
- package/dist/angular/services/square-sdk.service.d.ts +45 -0
- package/dist/angular/services/square-sdk.service.d.ts.map +1 -0
- package/dist/angular/services/square-sdk.service.js +133 -0
- package/dist/angular/services/square-sdk.service.js.map +1 -0
- package/dist/angular/square.module.d.ts +36 -0
- package/dist/angular/square.module.d.ts.map +1 -0
- package/dist/angular/square.module.js +75 -0
- package/dist/angular/square.module.js.map +1 -0
- package/dist/angular/types.d.ts +189 -0
- package/dist/angular/types.d.ts.map +1 -0
- package/dist/angular/types.js +8 -0
- package/dist/angular/types.js.map +1 -0
- package/dist/core/builders/order.builder.d.ts +140 -0
- package/dist/core/builders/order.builder.d.ts.map +1 -0
- package/dist/core/builders/order.builder.js +185 -0
- package/dist/core/builders/order.builder.js.map +1 -0
- package/dist/core/client.d.ts +93 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/client.js +99 -0
- package/dist/core/client.js.map +1 -0
- package/dist/core/errors.d.ts +55 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +118 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/index.d.ts +17 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +18 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/services/catalog.service.d.ts +218 -0
- package/dist/core/services/catalog.service.d.ts.map +1 -0
- package/dist/core/services/catalog.service.js +274 -0
- package/dist/core/services/catalog.service.js.map +1 -0
- package/dist/core/services/customers.service.d.ts +197 -0
- package/dist/core/services/customers.service.d.ts.map +1 -0
- package/dist/core/services/customers.service.js +246 -0
- package/dist/core/services/customers.service.js.map +1 -0
- package/dist/core/services/inventory.service.d.ts +196 -0
- package/dist/core/services/inventory.service.d.ts.map +1 -0
- package/dist/core/services/inventory.service.js +266 -0
- package/dist/core/services/inventory.service.js.map +1 -0
- package/dist/core/services/invoices.service.d.ts +211 -0
- package/dist/core/services/invoices.service.d.ts.map +1 -0
- package/dist/core/services/invoices.service.js +297 -0
- package/dist/core/services/invoices.service.js.map +1 -0
- package/dist/core/services/loyalty.service.d.ts +282 -0
- package/dist/core/services/loyalty.service.d.ts.map +1 -0
- package/dist/core/services/loyalty.service.js +340 -0
- package/dist/core/services/loyalty.service.js.map +1 -0
- package/dist/core/services/orders.service.d.ts +121 -0
- package/dist/core/services/orders.service.d.ts.map +1 -0
- package/dist/core/services/orders.service.js +208 -0
- package/dist/core/services/orders.service.js.map +1 -0
- package/dist/core/services/payments.service.d.ts +121 -0
- package/dist/core/services/payments.service.d.ts.map +1 -0
- package/dist/core/services/payments.service.js +189 -0
- package/dist/core/services/payments.service.js.map +1 -0
- package/dist/core/services/subscriptions.service.d.ts +205 -0
- package/dist/core/services/subscriptions.service.d.ts.map +1 -0
- package/dist/core/services/subscriptions.service.js +265 -0
- package/dist/core/services/subscriptions.service.js.map +1 -0
- package/dist/core/types/index.d.ts +68 -0
- package/dist/core/types/index.d.ts.map +1 -0
- package/dist/core/types/index.js +2 -0
- package/dist/core/types/index.js.map +1 -0
- package/dist/core/utils.d.ts +74 -0
- package/dist/core/utils.d.ts.map +1 -0
- package/dist/core/utils.js +96 -0
- package/dist/core/utils.js.map +1 -0
- package/dist/react/SquareProvider.d.ts +50 -0
- package/dist/react/SquareProvider.d.ts.map +1 -0
- package/dist/react/SquareProvider.js +134 -0
- package/dist/react/SquareProvider.js.map +1 -0
- package/dist/react/__tests__/CardInput.test.d.ts +2 -0
- package/dist/react/__tests__/CardInput.test.d.ts.map +1 -0
- package/dist/react/__tests__/CardInput.test.js +218 -0
- package/dist/react/__tests__/CardInput.test.js.map +1 -0
- package/dist/react/__tests__/PaymentButton.test.d.ts +2 -0
- package/dist/react/__tests__/PaymentButton.test.d.ts.map +1 -0
- package/dist/react/__tests__/PaymentButton.test.js +400 -0
- package/dist/react/__tests__/PaymentButton.test.js.map +1 -0
- package/dist/react/__tests__/SquareProvider.test.d.ts +2 -0
- package/dist/react/__tests__/SquareProvider.test.d.ts.map +1 -0
- package/dist/react/__tests__/SquareProvider.test.js +126 -0
- package/dist/react/__tests__/SquareProvider.test.js.map +1 -0
- package/dist/react/__tests__/setup.d.ts +2 -0
- package/dist/react/__tests__/setup.d.ts.map +1 -0
- package/dist/react/__tests__/setup.js +3 -0
- package/dist/react/__tests__/setup.js.map +1 -0
- package/dist/react/__tests__/useCatalog.test.d.ts +2 -0
- package/dist/react/__tests__/useCatalog.test.d.ts.map +1 -0
- package/dist/react/__tests__/useCatalog.test.js +277 -0
- package/dist/react/__tests__/useCatalog.test.js.map +1 -0
- package/dist/react/__tests__/useCustomers.test.d.ts +2 -0
- package/dist/react/__tests__/useCustomers.test.d.ts.map +1 -0
- package/dist/react/__tests__/useCustomers.test.js +312 -0
- package/dist/react/__tests__/useCustomers.test.js.map +1 -0
- package/dist/react/__tests__/useOrders.test.d.ts +2 -0
- package/dist/react/__tests__/useOrders.test.d.ts.map +1 -0
- package/dist/react/__tests__/useOrders.test.js +216 -0
- package/dist/react/__tests__/useOrders.test.js.map +1 -0
- package/dist/react/__tests__/usePayments.test.d.ts +2 -0
- package/dist/react/__tests__/usePayments.test.d.ts.map +1 -0
- package/dist/react/__tests__/usePayments.test.js +235 -0
- package/dist/react/__tests__/usePayments.test.js.map +1 -0
- package/dist/react/__tests__/useSquarePayment.test.d.ts +2 -0
- package/dist/react/__tests__/useSquarePayment.test.d.ts.map +1 -0
- package/dist/react/__tests__/useSquarePayment.test.js +447 -0
- package/dist/react/__tests__/useSquarePayment.test.js.map +1 -0
- package/dist/react/components/CardInput.d.ts +69 -0
- package/dist/react/components/CardInput.d.ts.map +1 -0
- package/dist/react/components/CardInput.js +58 -0
- package/dist/react/components/CardInput.js.map +1 -0
- package/dist/react/components/PaymentButton.d.ts +71 -0
- package/dist/react/components/PaymentButton.d.ts.map +1 -0
- package/dist/react/components/PaymentButton.js +140 -0
- package/dist/react/components/PaymentButton.js.map +1 -0
- package/dist/react/components/index.d.ts +5 -0
- package/dist/react/components/index.d.ts.map +1 -0
- package/dist/react/components/index.js +3 -0
- package/dist/react/components/index.js.map +1 -0
- package/dist/react/hooks/index.d.ts +11 -0
- package/dist/react/hooks/index.d.ts.map +1 -0
- package/dist/react/hooks/index.js +6 -0
- package/dist/react/hooks/index.js.map +1 -0
- package/dist/react/hooks/useCatalog.d.ts +98 -0
- package/dist/react/hooks/useCatalog.d.ts.map +1 -0
- package/dist/react/hooks/useCatalog.js +134 -0
- package/dist/react/hooks/useCatalog.js.map +1 -0
- package/dist/react/hooks/useCustomers.d.ts +105 -0
- package/dist/react/hooks/useCustomers.d.ts.map +1 -0
- package/dist/react/hooks/useCustomers.js +174 -0
- package/dist/react/hooks/useCustomers.js.map +1 -0
- package/dist/react/hooks/useOrders.d.ts +112 -0
- package/dist/react/hooks/useOrders.d.ts.map +1 -0
- package/dist/react/hooks/useOrders.js +115 -0
- package/dist/react/hooks/useOrders.js.map +1 -0
- package/dist/react/hooks/usePayments.d.ts +98 -0
- package/dist/react/hooks/usePayments.d.ts.map +1 -0
- package/dist/react/hooks/usePayments.js +89 -0
- package/dist/react/hooks/usePayments.js.map +1 -0
- package/dist/react/hooks/useSquarePayment.d.ts +52 -0
- package/dist/react/hooks/useSquarePayment.d.ts.map +1 -0
- package/dist/react/hooks/useSquarePayment.js +146 -0
- package/dist/react/hooks/useSquarePayment.js.map +1 -0
- package/dist/react/index.d.ts +8 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +7 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/types.d.ts +183 -0
- package/dist/react/types.d.ts.map +1 -0
- package/dist/react/types.js +2 -0
- package/dist/react/types.js.map +1 -0
- package/dist/server/index.d.ts +43 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +45 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/middleware/express.d.ts +77 -0
- package/dist/server/middleware/express.d.ts.map +1 -0
- package/dist/server/middleware/express.js +123 -0
- package/dist/server/middleware/express.js.map +1 -0
- package/dist/server/middleware/nextjs.d.ts +118 -0
- package/dist/server/middleware/nextjs.d.ts.map +1 -0
- package/dist/server/middleware/nextjs.js +172 -0
- package/dist/server/middleware/nextjs.js.map +1 -0
- package/dist/server/types.d.ts +89 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server/types.js +7 -0
- package/dist/server/types.js.map +1 -0
- package/dist/server/webhook.d.ts +114 -0
- package/dist/server/webhook.d.ts.map +1 -0
- package/dist/server/webhook.js +190 -0
- package/dist/server/webhook.js.map +1 -0
- package/package.json +118 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
var SquareModule_1;
|
|
14
|
+
import { NgModule, InjectionToken, Optional, SkipSelf, } from '@angular/core';
|
|
15
|
+
/**
|
|
16
|
+
* Injection token for Square configuration
|
|
17
|
+
*/
|
|
18
|
+
export const SQUARE_CONFIG = new InjectionToken('SQUARE_CONFIG');
|
|
19
|
+
/**
|
|
20
|
+
* Square Angular module
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { SquareModule } from '@bates-solutions/squareup/angular';
|
|
25
|
+
*
|
|
26
|
+
* @NgModule({
|
|
27
|
+
* imports: [
|
|
28
|
+
* SquareModule.forRoot({
|
|
29
|
+
* applicationId: 'sq0idp-xxx',
|
|
30
|
+
* locationId: 'LXXX',
|
|
31
|
+
* environment: 'sandbox',
|
|
32
|
+
* })
|
|
33
|
+
* ]
|
|
34
|
+
* })
|
|
35
|
+
* export class AppModule {}
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
let SquareModule = SquareModule_1 = class SquareModule {
|
|
39
|
+
constructor(parentModule) {
|
|
40
|
+
if (parentModule) {
|
|
41
|
+
throw new Error('SquareModule is already loaded. Import it in the AppModule only using forRoot().');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Configure the Square module with application settings
|
|
46
|
+
*
|
|
47
|
+
* @param config - Square configuration options
|
|
48
|
+
* @returns Module with providers
|
|
49
|
+
*/
|
|
50
|
+
static forRoot(config) {
|
|
51
|
+
return {
|
|
52
|
+
ngModule: SquareModule_1,
|
|
53
|
+
providers: [
|
|
54
|
+
{
|
|
55
|
+
provide: SQUARE_CONFIG,
|
|
56
|
+
useValue: {
|
|
57
|
+
environment: 'sandbox',
|
|
58
|
+
currency: 'USD',
|
|
59
|
+
...config,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
SquareModule = SquareModule_1 = __decorate([
|
|
67
|
+
NgModule({})
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
69
|
+
,
|
|
70
|
+
__param(0, Optional()),
|
|
71
|
+
__param(0, SkipSelf()),
|
|
72
|
+
__metadata("design:paramtypes", [SquareModule])
|
|
73
|
+
], SquareModule);
|
|
74
|
+
export { SquareModule };
|
|
75
|
+
//# sourceMappingURL=square.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"square.module.js","sourceRoot":"","sources":["../../src/angular/square.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EACL,QAAQ,EAER,cAAc,EACd,QAAQ,EACR,QAAQ,GACT,MAAM,eAAe,CAAC;AAGvB;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,cAAc,CAAe,eAAe,CAAC,CAAC;AAE/E;;;;;;;;;;;;;;;;;;GAkBG;AAGI,IAAM,YAAY,oBAAlB,MAAM,YAAY;IACvB,YAAoC,YAA2B;QAC7D,IAAI,YAAY,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,kFAAkF,CACnF,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,MAAoB;QACjC,OAAO;YACL,QAAQ,EAAE,cAAY;YACtB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,aAAa;oBACtB,QAAQ,EAAE;wBACR,WAAW,EAAE,SAAS;wBACtB,QAAQ,EAAE,KAAK;wBACf,GAAG,MAAM;qBACV;iBACF;aACF;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA9BY,YAAY;IAFxB,QAAQ,CAAC,EAAE,CAAC;IACb,kEAAkE;;IAEnD,WAAA,QAAQ,EAAE,CAAA;IAAE,WAAA,QAAQ,EAAE,CAAA;qCAAgB,YAAY;GADpD,YAAY,CA8BxB"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Angular-specific types for Square integration
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Square module configuration
|
|
6
|
+
*/
|
|
7
|
+
export interface SquareConfig {
|
|
8
|
+
/** Square application ID */
|
|
9
|
+
applicationId: string;
|
|
10
|
+
/** Square location ID */
|
|
11
|
+
locationId: string;
|
|
12
|
+
/** Environment (sandbox or production) */
|
|
13
|
+
environment?: 'sandbox' | 'production';
|
|
14
|
+
/** Access token for server-side operations */
|
|
15
|
+
accessToken?: string;
|
|
16
|
+
/** Default currency code */
|
|
17
|
+
currency?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Square Web Payments SDK types
|
|
21
|
+
*/
|
|
22
|
+
export interface Payments {
|
|
23
|
+
card(options?: CardOptions): Promise<Card>;
|
|
24
|
+
googlePay(options: GooglePayOptions): Promise<GooglePay>;
|
|
25
|
+
applePay(options: ApplePayOptions): Promise<ApplePay>;
|
|
26
|
+
}
|
|
27
|
+
export interface Card {
|
|
28
|
+
attach(element: HTMLElement): Promise<void>;
|
|
29
|
+
destroy(): Promise<void>;
|
|
30
|
+
tokenize(): Promise<TokenResult>;
|
|
31
|
+
}
|
|
32
|
+
export interface GooglePay {
|
|
33
|
+
attach(element: HTMLElement, options?: DigitalWalletOptions): Promise<void>;
|
|
34
|
+
destroy(): Promise<void>;
|
|
35
|
+
tokenize(): Promise<TokenResult>;
|
|
36
|
+
}
|
|
37
|
+
export interface ApplePay {
|
|
38
|
+
attach(element: HTMLElement, options?: DigitalWalletOptions): Promise<void>;
|
|
39
|
+
destroy(): Promise<void>;
|
|
40
|
+
tokenize(): Promise<TokenResult>;
|
|
41
|
+
}
|
|
42
|
+
export interface CardOptions {
|
|
43
|
+
style?: CardStyle;
|
|
44
|
+
}
|
|
45
|
+
export interface CardStyle {
|
|
46
|
+
'.input-container'?: Record<string, string>;
|
|
47
|
+
'.input-container.is-focus'?: Record<string, string>;
|
|
48
|
+
'.input-container.is-error'?: Record<string, string>;
|
|
49
|
+
'.message-text'?: Record<string, string>;
|
|
50
|
+
'.message-icon'?: Record<string, string>;
|
|
51
|
+
'.message-text.is-error'?: Record<string, string>;
|
|
52
|
+
input?: Record<string, string>;
|
|
53
|
+
'input.is-focus'?: Record<string, string>;
|
|
54
|
+
'input::placeholder'?: Record<string, string>;
|
|
55
|
+
}
|
|
56
|
+
export interface GooglePayOptions {
|
|
57
|
+
redirectURL?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface ApplePayOptions {
|
|
60
|
+
redirectURL?: string;
|
|
61
|
+
}
|
|
62
|
+
export interface DigitalWalletOptions {
|
|
63
|
+
buttonColor?: 'default' | 'black' | 'white';
|
|
64
|
+
buttonSizeMode?: 'fill' | 'static';
|
|
65
|
+
buttonType?: 'long' | 'short';
|
|
66
|
+
}
|
|
67
|
+
export interface TokenResult {
|
|
68
|
+
status: 'OK' | 'Cancel' | 'Error';
|
|
69
|
+
token?: string;
|
|
70
|
+
errors?: TokenError[];
|
|
71
|
+
}
|
|
72
|
+
export interface TokenError {
|
|
73
|
+
type: string;
|
|
74
|
+
message: string;
|
|
75
|
+
field?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Injection token for Square configuration
|
|
79
|
+
*/
|
|
80
|
+
export declare const SQUARE_CONFIG = "SQUARE_CONFIG";
|
|
81
|
+
/**
|
|
82
|
+
* Payment request types
|
|
83
|
+
*/
|
|
84
|
+
export interface CreatePaymentRequest {
|
|
85
|
+
sourceId: string;
|
|
86
|
+
amount: number;
|
|
87
|
+
currency?: string;
|
|
88
|
+
idempotencyKey?: string;
|
|
89
|
+
customerId?: string;
|
|
90
|
+
orderId?: string;
|
|
91
|
+
note?: string;
|
|
92
|
+
referenceId?: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Order types
|
|
96
|
+
*/
|
|
97
|
+
export interface CreateOrderRequest {
|
|
98
|
+
lineItems?: OrderLineItem[];
|
|
99
|
+
discounts?: OrderDiscount[];
|
|
100
|
+
taxes?: OrderTax[];
|
|
101
|
+
serviceCharges?: OrderServiceCharge[];
|
|
102
|
+
fulfillments?: OrderFulfillment[];
|
|
103
|
+
customerId?: string;
|
|
104
|
+
referenceId?: string;
|
|
105
|
+
note?: string;
|
|
106
|
+
}
|
|
107
|
+
export interface OrderLineItem {
|
|
108
|
+
name?: string;
|
|
109
|
+
quantity: string;
|
|
110
|
+
catalogObjectId?: string;
|
|
111
|
+
variationName?: string;
|
|
112
|
+
basePriceMoney?: Money;
|
|
113
|
+
note?: string;
|
|
114
|
+
}
|
|
115
|
+
export interface OrderDiscount {
|
|
116
|
+
name?: string;
|
|
117
|
+
percentage?: string;
|
|
118
|
+
amountMoney?: Money;
|
|
119
|
+
scope?: 'LINE_ITEM' | 'ORDER';
|
|
120
|
+
}
|
|
121
|
+
export interface OrderTax {
|
|
122
|
+
name?: string;
|
|
123
|
+
percentage?: string;
|
|
124
|
+
scope?: 'LINE_ITEM' | 'ORDER';
|
|
125
|
+
}
|
|
126
|
+
export interface OrderServiceCharge {
|
|
127
|
+
name?: string;
|
|
128
|
+
percentage?: string;
|
|
129
|
+
amountMoney?: Money;
|
|
130
|
+
}
|
|
131
|
+
export interface OrderFulfillment {
|
|
132
|
+
type: 'PICKUP' | 'SHIPMENT' | 'DELIVERY';
|
|
133
|
+
state?: string;
|
|
134
|
+
pickupDetails?: PickupDetails;
|
|
135
|
+
shipmentDetails?: ShipmentDetails;
|
|
136
|
+
}
|
|
137
|
+
export interface PickupDetails {
|
|
138
|
+
recipient?: Recipient;
|
|
139
|
+
scheduleType?: 'SCHEDULED' | 'ASAP';
|
|
140
|
+
pickupAt?: string;
|
|
141
|
+
note?: string;
|
|
142
|
+
}
|
|
143
|
+
export interface ShipmentDetails {
|
|
144
|
+
recipient?: Recipient;
|
|
145
|
+
carrier?: string;
|
|
146
|
+
trackingNumber?: string;
|
|
147
|
+
}
|
|
148
|
+
export interface Recipient {
|
|
149
|
+
displayName?: string;
|
|
150
|
+
emailAddress?: string;
|
|
151
|
+
phoneNumber?: string;
|
|
152
|
+
}
|
|
153
|
+
export interface Money {
|
|
154
|
+
amount: number;
|
|
155
|
+
currency?: string;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Customer types
|
|
159
|
+
*/
|
|
160
|
+
export interface CreateCustomerRequest {
|
|
161
|
+
givenName?: string;
|
|
162
|
+
familyName?: string;
|
|
163
|
+
companyName?: string;
|
|
164
|
+
emailAddress?: string;
|
|
165
|
+
phoneNumber?: string;
|
|
166
|
+
address?: Address;
|
|
167
|
+
note?: string;
|
|
168
|
+
referenceId?: string;
|
|
169
|
+
}
|
|
170
|
+
export interface Address {
|
|
171
|
+
addressLine1?: string;
|
|
172
|
+
addressLine2?: string;
|
|
173
|
+
locality?: string;
|
|
174
|
+
administrativeDistrictLevel1?: string;
|
|
175
|
+
postalCode?: string;
|
|
176
|
+
country?: string;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Catalog types
|
|
180
|
+
*/
|
|
181
|
+
export interface CatalogSearchRequest {
|
|
182
|
+
textFilter?: string;
|
|
183
|
+
categoryIds?: string[];
|
|
184
|
+
stockLevels?: string[];
|
|
185
|
+
enabledLocationIds?: string[];
|
|
186
|
+
limit?: number;
|
|
187
|
+
cursor?: string;
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/angular/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,4BAA4B;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,yBAAyB;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,WAAW,CAAC,EAAE,SAAS,GAAG,YAAY,CAAC;IACvC,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4BAA4B;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,Q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AAM,CAAC;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/angular/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAuFH;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { SquareClient } from 'square';
|
|
2
|
+
import type { CurrencyCode, LineItemInput } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Order line item type for internal use
|
|
5
|
+
*/
|
|
6
|
+
interface OrderLineItem {
|
|
7
|
+
quantity: string;
|
|
8
|
+
catalogObjectId?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
basePriceMoney?: {
|
|
11
|
+
amount: bigint;
|
|
12
|
+
currency: CurrencyCode;
|
|
13
|
+
};
|
|
14
|
+
note?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Order type from Square API
|
|
18
|
+
*/
|
|
19
|
+
export interface Order {
|
|
20
|
+
id?: string;
|
|
21
|
+
locationId?: string;
|
|
22
|
+
referenceId?: string;
|
|
23
|
+
customerId?: string;
|
|
24
|
+
lineItems?: OrderLineItem[];
|
|
25
|
+
totalMoney?: {
|
|
26
|
+
amount?: bigint;
|
|
27
|
+
currency?: string;
|
|
28
|
+
};
|
|
29
|
+
state?: string;
|
|
30
|
+
version?: number;
|
|
31
|
+
createdAt?: string;
|
|
32
|
+
updatedAt?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Fluent builder for creating Square orders
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const order = await square.orders
|
|
40
|
+
* .builder()
|
|
41
|
+
* .addItem({ name: 'Latte', amount: 450 })
|
|
42
|
+
* .addItem({ catalogObjectId: 'ITEM_123', quantity: 2 })
|
|
43
|
+
* .withTip(100)
|
|
44
|
+
* .withCustomer('CUST_123')
|
|
45
|
+
* .build();
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare class OrderBuilder {
|
|
49
|
+
private readonly client;
|
|
50
|
+
private readonly locationId;
|
|
51
|
+
private lineItems;
|
|
52
|
+
private customerId?;
|
|
53
|
+
private referenceId?;
|
|
54
|
+
private tipAmount?;
|
|
55
|
+
private currency;
|
|
56
|
+
constructor(client: SquareClient, locationId: string);
|
|
57
|
+
/**
|
|
58
|
+
* Set the currency for the order
|
|
59
|
+
*
|
|
60
|
+
* @param currency - Currency code
|
|
61
|
+
* @returns Builder instance for chaining
|
|
62
|
+
*/
|
|
63
|
+
withCurrency(currency: CurrencyCode): this;
|
|
64
|
+
/**
|
|
65
|
+
* Add a line item to the order
|
|
66
|
+
*
|
|
67
|
+
* @param item - Line item details
|
|
68
|
+
* @returns Builder instance for chaining
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* builder
|
|
73
|
+
* .addItem({ name: 'Coffee', amount: 350 })
|
|
74
|
+
* .addItem({ catalogObjectId: 'ITEM_123', quantity: 2 })
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
addItem(item: LineItemInput): this;
|
|
78
|
+
/**
|
|
79
|
+
* Add multiple line items at once
|
|
80
|
+
*
|
|
81
|
+
* @param items - Array of line items
|
|
82
|
+
* @returns Builder instance for chaining
|
|
83
|
+
*/
|
|
84
|
+
addItems(items: LineItemInput[]): this;
|
|
85
|
+
/**
|
|
86
|
+
* Add a tip to the order
|
|
87
|
+
*
|
|
88
|
+
* @param amount - Tip amount in cents
|
|
89
|
+
* @returns Builder instance for chaining
|
|
90
|
+
*/
|
|
91
|
+
withTip(amount: number): this;
|
|
92
|
+
/**
|
|
93
|
+
* Associate a customer with the order
|
|
94
|
+
*
|
|
95
|
+
* @param customerId - Square customer ID
|
|
96
|
+
* @returns Builder instance for chaining
|
|
97
|
+
*/
|
|
98
|
+
withCustomer(customerId: string): this;
|
|
99
|
+
/**
|
|
100
|
+
* Add a reference ID for external tracking
|
|
101
|
+
*
|
|
102
|
+
* @param referenceId - External reference ID
|
|
103
|
+
* @returns Builder instance for chaining
|
|
104
|
+
*/
|
|
105
|
+
withReference(referenceId: string): this;
|
|
106
|
+
/**
|
|
107
|
+
* Add a note to the order
|
|
108
|
+
*
|
|
109
|
+
* @param note - Order note
|
|
110
|
+
* @returns Builder instance for chaining
|
|
111
|
+
*/
|
|
112
|
+
withNote(_note: string): this;
|
|
113
|
+
/**
|
|
114
|
+
* Build and create the order
|
|
115
|
+
*
|
|
116
|
+
* @returns Created order
|
|
117
|
+
*
|
|
118
|
+
* @throws {SquareValidationError} When validation fails
|
|
119
|
+
* @throws {SquareApiError} When API call fails
|
|
120
|
+
*/
|
|
121
|
+
build(): Promise<Order>;
|
|
122
|
+
/**
|
|
123
|
+
* Preview the order without creating it
|
|
124
|
+
* Returns the order configuration that would be sent
|
|
125
|
+
*/
|
|
126
|
+
preview(): {
|
|
127
|
+
locationId: string;
|
|
128
|
+
lineItems: OrderLineItem[];
|
|
129
|
+
customerId?: string;
|
|
130
|
+
referenceId?: string;
|
|
131
|
+
tipAmount?: bigint;
|
|
132
|
+
currency: CurrencyCode;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Reset the builder to start fresh
|
|
136
|
+
*/
|
|
137
|
+
reset(): this;
|
|
138
|
+
}
|
|
139
|
+
export {};
|
|
140
|
+
//# sourceMappingURL=order.builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order.builder.d.ts","sourceRoot":"","sources":["../../../src/core/builders/order.builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIrE;;GAEG;AACH,UAAU,aAAa;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE;QACf,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,YAAY,CAAC;KACxB,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,aAAa,EAAE,CAAC;IAC5B,UAAU,CAAC,EAAE;QACX,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAY;IAQrB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAR7B,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,UAAU,CAAC,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAC,CAAS;IAC7B,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAuB;gBAGpB,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,MAAM;IAGrC;;;;;OAKG;IACH,YAAY,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI;IAK1C;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI;IA6BlC;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI;IAOtC;;;;;OAKG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK7B;;;;;OAKG;IACH,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAKtC;;;;;OAKG;IACH,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAKxC;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAM7B;;;;;;;OAOG;IACG,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC;IA0B7B;;;OAGG;IACH,OAAO,IAAI;QACT,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,aAAa,EAAE,CAAC;QAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,YAAY,CAAC;KACxB;IAWD;;OAEG;IACH,KAAK,IAAI,IAAI;CAOd"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { parseSquareError, SquareValidationError } from '../errors.js';
|
|
2
|
+
import { createIdempotencyKey } from '../utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* Fluent builder for creating Square orders
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const order = await square.orders
|
|
9
|
+
* .builder()
|
|
10
|
+
* .addItem({ name: 'Latte', amount: 450 })
|
|
11
|
+
* .addItem({ catalogObjectId: 'ITEM_123', quantity: 2 })
|
|
12
|
+
* .withTip(100)
|
|
13
|
+
* .withCustomer('CUST_123')
|
|
14
|
+
* .build();
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export class OrderBuilder {
|
|
18
|
+
client;
|
|
19
|
+
locationId;
|
|
20
|
+
lineItems = [];
|
|
21
|
+
customerId;
|
|
22
|
+
referenceId;
|
|
23
|
+
tipAmount;
|
|
24
|
+
currency = 'USD';
|
|
25
|
+
constructor(client, locationId) {
|
|
26
|
+
this.client = client;
|
|
27
|
+
this.locationId = locationId;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Set the currency for the order
|
|
31
|
+
*
|
|
32
|
+
* @param currency - Currency code
|
|
33
|
+
* @returns Builder instance for chaining
|
|
34
|
+
*/
|
|
35
|
+
withCurrency(currency) {
|
|
36
|
+
this.currency = currency;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Add a line item to the order
|
|
41
|
+
*
|
|
42
|
+
* @param item - Line item details
|
|
43
|
+
* @returns Builder instance for chaining
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* builder
|
|
48
|
+
* .addItem({ name: 'Coffee', amount: 350 })
|
|
49
|
+
* .addItem({ catalogObjectId: 'ITEM_123', quantity: 2 })
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
addItem(item) {
|
|
53
|
+
const quantity = String(item.quantity ?? 1);
|
|
54
|
+
const lineItem = {
|
|
55
|
+
quantity,
|
|
56
|
+
};
|
|
57
|
+
if (item.catalogObjectId) {
|
|
58
|
+
lineItem.catalogObjectId = item.catalogObjectId;
|
|
59
|
+
}
|
|
60
|
+
else if (item.name && item.amount !== undefined) {
|
|
61
|
+
lineItem.name = item.name;
|
|
62
|
+
lineItem.basePriceMoney = {
|
|
63
|
+
amount: BigInt(item.amount),
|
|
64
|
+
currency: this.currency,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
throw new SquareValidationError('Line item must have either catalogObjectId or both name and amount');
|
|
69
|
+
}
|
|
70
|
+
if (item.note) {
|
|
71
|
+
lineItem.note = item.note;
|
|
72
|
+
}
|
|
73
|
+
this.lineItems.push(lineItem);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Add multiple line items at once
|
|
78
|
+
*
|
|
79
|
+
* @param items - Array of line items
|
|
80
|
+
* @returns Builder instance for chaining
|
|
81
|
+
*/
|
|
82
|
+
addItems(items) {
|
|
83
|
+
for (const item of items) {
|
|
84
|
+
this.addItem(item);
|
|
85
|
+
}
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Add a tip to the order
|
|
90
|
+
*
|
|
91
|
+
* @param amount - Tip amount in cents
|
|
92
|
+
* @returns Builder instance for chaining
|
|
93
|
+
*/
|
|
94
|
+
withTip(amount) {
|
|
95
|
+
this.tipAmount = BigInt(amount);
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Associate a customer with the order
|
|
100
|
+
*
|
|
101
|
+
* @param customerId - Square customer ID
|
|
102
|
+
* @returns Builder instance for chaining
|
|
103
|
+
*/
|
|
104
|
+
withCustomer(customerId) {
|
|
105
|
+
this.customerId = customerId;
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Add a reference ID for external tracking
|
|
110
|
+
*
|
|
111
|
+
* @param referenceId - External reference ID
|
|
112
|
+
* @returns Builder instance for chaining
|
|
113
|
+
*/
|
|
114
|
+
withReference(referenceId) {
|
|
115
|
+
this.referenceId = referenceId;
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Add a note to the order
|
|
120
|
+
*
|
|
121
|
+
* @param note - Order note
|
|
122
|
+
* @returns Builder instance for chaining
|
|
123
|
+
*/
|
|
124
|
+
withNote(_note) {
|
|
125
|
+
// Note: Order-level notes are typically handled differently in Square
|
|
126
|
+
// This is preserved for API compatibility
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Build and create the order
|
|
131
|
+
*
|
|
132
|
+
* @returns Created order
|
|
133
|
+
*
|
|
134
|
+
* @throws {SquareValidationError} When validation fails
|
|
135
|
+
* @throws {SquareApiError} When API call fails
|
|
136
|
+
*/
|
|
137
|
+
async build() {
|
|
138
|
+
if (this.lineItems.length === 0) {
|
|
139
|
+
throw new SquareValidationError('Order must have at least one line item');
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
const response = await this.client.orders.create({
|
|
143
|
+
order: {
|
|
144
|
+
locationId: this.locationId,
|
|
145
|
+
lineItems: this.lineItems,
|
|
146
|
+
customerId: this.customerId,
|
|
147
|
+
referenceId: this.referenceId,
|
|
148
|
+
},
|
|
149
|
+
idempotencyKey: createIdempotencyKey(),
|
|
150
|
+
});
|
|
151
|
+
if (!response.order) {
|
|
152
|
+
throw new Error('Order was not created');
|
|
153
|
+
}
|
|
154
|
+
return response.order;
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
throw parseSquareError(error);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Preview the order without creating it
|
|
162
|
+
* Returns the order configuration that would be sent
|
|
163
|
+
*/
|
|
164
|
+
preview() {
|
|
165
|
+
return {
|
|
166
|
+
locationId: this.locationId,
|
|
167
|
+
lineItems: [...this.lineItems],
|
|
168
|
+
customerId: this.customerId,
|
|
169
|
+
referenceId: this.referenceId,
|
|
170
|
+
tipAmount: this.tipAmount,
|
|
171
|
+
currency: this.currency,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Reset the builder to start fresh
|
|
176
|
+
*/
|
|
177
|
+
reset() {
|
|
178
|
+
this.lineItems = [];
|
|
179
|
+
this.customerId = undefined;
|
|
180
|
+
this.referenceId = undefined;
|
|
181
|
+
this.tipAmount = undefined;
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=order.builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order.builder.js","sourceRoot":"","sources":["../../../src/core/builders/order.builder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAmCnD;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,YAAY;IAQJ;IACA;IARX,SAAS,GAAoB,EAAE,CAAC;IAChC,UAAU,CAAU;IACpB,WAAW,CAAU;IACrB,SAAS,CAAU;IACnB,QAAQ,GAAiB,KAAK,CAAC;IAEvC,YACmB,MAAoB,EACpB,UAAkB;QADlB,WAAM,GAAN,MAAM,CAAc;QACpB,eAAU,GAAV,UAAU,CAAQ;IAClC,CAAC;IAEJ;;;;;OAKG;IACH,YAAY,CAAC,QAAsB;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,IAAmB;QACzB,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC;QAE5C,MAAM,QAAQ,GAAkB;YAC9B,QAAQ;SACT,CAAC;QAEF,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,QAAQ,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAClD,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAClD,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;YAC1B,Q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