@bates-solutions/squareup 0.1.0 → 1.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.
Files changed (144) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +167 -154
  3. package/package.json +87 -118
  4. package/README.md.backup +0 -292
  5. package/dist/angular/__tests__/setup.d.ts +0 -1
  6. package/dist/angular/__tests__/setup.d.ts.map +0 -1
  7. package/dist/angular/__tests__/setup.js +0 -5
  8. package/dist/angular/__tests__/setup.js.map +0 -1
  9. package/dist/angular/components/index.d.ts +0 -2
  10. package/dist/angular/components/index.d.ts.map +0 -1
  11. package/dist/angular/components/index.js +0 -2
  12. package/dist/angular/components/index.js.map +0 -1
  13. package/dist/angular/components/payment-button.component.d.ts +0 -49
  14. package/dist/angular/components/payment-button.component.d.ts.map +0 -1
  15. package/dist/angular/components/payment-button.component.js +0 -176
  16. package/dist/angular/components/payment-button.component.js.map +0 -1
  17. package/dist/angular/directives/index.d.ts +0 -2
  18. package/dist/angular/directives/index.d.ts.map +0 -1
  19. package/dist/angular/directives/index.js +0 -2
  20. package/dist/angular/directives/index.js.map +0 -1
  21. package/dist/angular/directives/square-card.directive.d.ts +0 -52
  22. package/dist/angular/directives/square-card.directive.d.ts.map +0 -1
  23. package/dist/angular/directives/square-card.directive.js +0 -98
  24. package/dist/angular/directives/square-card.directive.js.map +0 -1
  25. package/dist/angular/index.d.ts +0 -42
  26. package/dist/angular/index.d.ts.map +0 -1
  27. package/dist/angular/index.js +0 -45
  28. package/dist/angular/index.js.map +0 -1
  29. package/dist/angular/services/index.d.ts +0 -6
  30. package/dist/angular/services/index.d.ts.map +0 -1
  31. package/dist/angular/services/index.js +0 -6
  32. package/dist/angular/services/index.js.map +0 -1
  33. package/dist/angular/services/square-catalog.service.d.ts +0 -60
  34. package/dist/angular/services/square-catalog.service.d.ts.map +0 -1
  35. package/dist/angular/services/square-catalog.service.js +0 -152
  36. package/dist/angular/services/square-catalog.service.js.map +0 -1
  37. package/dist/angular/services/square-customers.service.d.ts +0 -77
  38. package/dist/angular/services/square-customers.service.d.ts.map +0 -1
  39. package/dist/angular/services/square-customers.service.js +0 -187
  40. package/dist/angular/services/square-customers.service.js.map +0 -1
  41. package/dist/angular/services/square-orders.service.d.ts +0 -66
  42. package/dist/angular/services/square-orders.service.d.ts.map +0 -1
  43. package/dist/angular/services/square-orders.service.js +0 -170
  44. package/dist/angular/services/square-orders.service.js.map +0 -1
  45. package/dist/angular/services/square-payments.service.d.ts +0 -73
  46. package/dist/angular/services/square-payments.service.d.ts.map +0 -1
  47. package/dist/angular/services/square-payments.service.js +0 -167
  48. package/dist/angular/services/square-payments.service.js.map +0 -1
  49. package/dist/angular/services/square-sdk.service.d.ts +0 -45
  50. package/dist/angular/services/square-sdk.service.d.ts.map +0 -1
  51. package/dist/angular/services/square-sdk.service.js +0 -133
  52. package/dist/angular/services/square-sdk.service.js.map +0 -1
  53. package/dist/angular/square.module.d.ts +0 -36
  54. package/dist/angular/square.module.d.ts.map +0 -1
  55. package/dist/angular/square.module.js +0 -75
  56. package/dist/angular/square.module.js.map +0 -1
  57. package/dist/angular/types.d.ts +0 -189
  58. package/dist/angular/types.d.ts.map +0 -1
  59. package/dist/angular/types.js +0 -8
  60. package/dist/angular/types.js.map +0 -1
  61. package/dist/react/SquareProvider.d.ts +0 -50
  62. package/dist/react/SquareProvider.d.ts.map +0 -1
  63. package/dist/react/SquareProvider.js +0 -134
  64. package/dist/react/SquareProvider.js.map +0 -1
  65. package/dist/react/__tests__/CardInput.test.d.ts +0 -2
  66. package/dist/react/__tests__/CardInput.test.d.ts.map +0 -1
  67. package/dist/react/__tests__/CardInput.test.js +0 -218
  68. package/dist/react/__tests__/CardInput.test.js.map +0 -1
  69. package/dist/react/__tests__/PaymentButton.test.d.ts +0 -2
  70. package/dist/react/__tests__/PaymentButton.test.d.ts.map +0 -1
  71. package/dist/react/__tests__/PaymentButton.test.js +0 -400
  72. package/dist/react/__tests__/PaymentButton.test.js.map +0 -1
  73. package/dist/react/__tests__/SquareProvider.test.d.ts +0 -2
  74. package/dist/react/__tests__/SquareProvider.test.d.ts.map +0 -1
  75. package/dist/react/__tests__/SquareProvider.test.js +0 -126
  76. package/dist/react/__tests__/SquareProvider.test.js.map +0 -1
  77. package/dist/react/__tests__/setup.d.ts +0 -2
  78. package/dist/react/__tests__/setup.d.ts.map +0 -1
  79. package/dist/react/__tests__/setup.js +0 -3
  80. package/dist/react/__tests__/setup.js.map +0 -1
  81. package/dist/react/__tests__/useCatalog.test.d.ts +0 -2
  82. package/dist/react/__tests__/useCatalog.test.d.ts.map +0 -1
  83. package/dist/react/__tests__/useCatalog.test.js +0 -277
  84. package/dist/react/__tests__/useCatalog.test.js.map +0 -1
  85. package/dist/react/__tests__/useCustomers.test.d.ts +0 -2
  86. package/dist/react/__tests__/useCustomers.test.d.ts.map +0 -1
  87. package/dist/react/__tests__/useCustomers.test.js +0 -312
  88. package/dist/react/__tests__/useCustomers.test.js.map +0 -1
  89. package/dist/react/__tests__/useOrders.test.d.ts +0 -2
  90. package/dist/react/__tests__/useOrders.test.d.ts.map +0 -1
  91. package/dist/react/__tests__/useOrders.test.js +0 -216
  92. package/dist/react/__tests__/useOrders.test.js.map +0 -1
  93. package/dist/react/__tests__/usePayments.test.d.ts +0 -2
  94. package/dist/react/__tests__/usePayments.test.d.ts.map +0 -1
  95. package/dist/react/__tests__/usePayments.test.js +0 -235
  96. package/dist/react/__tests__/usePayments.test.js.map +0 -1
  97. package/dist/react/__tests__/useSquarePayment.test.d.ts +0 -2
  98. package/dist/react/__tests__/useSquarePayment.test.d.ts.map +0 -1
  99. package/dist/react/__tests__/useSquarePayment.test.js +0 -447
  100. package/dist/react/__tests__/useSquarePayment.test.js.map +0 -1
  101. package/dist/react/components/CardInput.d.ts +0 -69
  102. package/dist/react/components/CardInput.d.ts.map +0 -1
  103. package/dist/react/components/CardInput.js +0 -58
  104. package/dist/react/components/CardInput.js.map +0 -1
  105. package/dist/react/components/PaymentButton.d.ts +0 -71
  106. package/dist/react/components/PaymentButton.d.ts.map +0 -1
  107. package/dist/react/components/PaymentButton.js +0 -140
  108. package/dist/react/components/PaymentButton.js.map +0 -1
  109. package/dist/react/components/index.d.ts +0 -5
  110. package/dist/react/components/index.d.ts.map +0 -1
  111. package/dist/react/components/index.js +0 -3
  112. package/dist/react/components/index.js.map +0 -1
  113. package/dist/react/hooks/index.d.ts +0 -11
  114. package/dist/react/hooks/index.d.ts.map +0 -1
  115. package/dist/react/hooks/index.js +0 -6
  116. package/dist/react/hooks/index.js.map +0 -1
  117. package/dist/react/hooks/useCatalog.d.ts +0 -98
  118. package/dist/react/hooks/useCatalog.d.ts.map +0 -1
  119. package/dist/react/hooks/useCatalog.js +0 -134
  120. package/dist/react/hooks/useCatalog.js.map +0 -1
  121. package/dist/react/hooks/useCustomers.d.ts +0 -105
  122. package/dist/react/hooks/useCustomers.d.ts.map +0 -1
  123. package/dist/react/hooks/useCustomers.js +0 -174
  124. package/dist/react/hooks/useCustomers.js.map +0 -1
  125. package/dist/react/hooks/useOrders.d.ts +0 -112
  126. package/dist/react/hooks/useOrders.d.ts.map +0 -1
  127. package/dist/react/hooks/useOrders.js +0 -115
  128. package/dist/react/hooks/useOrders.js.map +0 -1
  129. package/dist/react/hooks/usePayments.d.ts +0 -98
  130. package/dist/react/hooks/usePayments.d.ts.map +0 -1
  131. package/dist/react/hooks/usePayments.js +0 -89
  132. package/dist/react/hooks/usePayments.js.map +0 -1
  133. package/dist/react/hooks/useSquarePayment.d.ts +0 -52
  134. package/dist/react/hooks/useSquarePayment.d.ts.map +0 -1
  135. package/dist/react/hooks/useSquarePayment.js +0 -146
  136. package/dist/react/hooks/useSquarePayment.js.map +0 -1
  137. package/dist/react/index.d.ts +0 -8
  138. package/dist/react/index.d.ts.map +0 -1
  139. package/dist/react/index.js +0 -7
  140. package/dist/react/index.js.map +0 -1
  141. package/dist/react/types.d.ts +0 -183
  142. package/dist/react/types.d.ts.map +0 -1
  143. package/dist/react/types.js +0 -2
  144. package/dist/react/types.js.map +0 -1
package/README.md.backup DELETED
@@ -1,292 +0,0 @@
1
- <p align="center">
2
- <img src="https://img.shields.io/badge/React-18+-61DAFB?logo=react&logoColor=white&style=for-the-badge" alt="React" height="28">
3
- &nbsp;&nbsp;&nbsp;&nbsp;
4
- <img src="https://img.shields.io/badge/Angular-17+-DD0031?logo=angular&logoColor=white&style=for-the-badge" alt="Angular" height="28">
5
- &nbsp;&nbsp;&nbsp;&nbsp;
6
- <img src="https://img.shields.io/badge/Square-Payments-0066CC?logo=data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiByeD0iNCIgZmlsbD0iIzAwNjZDQyIvPgo8cGF0aCBkPSJNOC41IDEySDE1LjVWMTMuNUgxMC41VjE1SDE1LjVWMTYuNUgxMC41VjE4SDE1LjVWMTlIMFYxMkg4LjVWMTJIMFYxMkg4LjVWMTJaIiBmaWxsPSJ3aGl0ZSIvPgo8L3N2Zz4K&style=for-the-badge" alt="Square" height="28">
7
- </p>
8
-
9
- <h1 align="center">@bates-solutions/squareup</h1>
10
-
11
- <p align="center">
12
- <strong>The modern TypeScript SDK for Square payments</strong><br>
13
- Build payment experiences in React and Angular with type-safe APIs, fluent builders, and framework-native integrations.
14
- </p>
15
-
16
- <p align="center">
17
- <img src="https://img.shields.io/badge/version-0.1.0-blue.svg" alt="version 0.1.0">
18
- <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
19
- <a href="https://typescriptlang.org"><img src="https://img.shields.io/badge/TypeScript-5.0+-blue.svg" alt="TypeScript"></a>
20
- <br>
21
- <img src="https://img.shields.io/badge/tests-329%20passed-brightgreen.svg" alt="Tests">
22
- <img src="https://img.shields.io/badge/coverage-99.84%25-brightgreen.svg" alt="Coverage">
23
- <img src="https://img.shields.io/badge/React-110%20tests-blue.svg" alt="React Tests">
24
- <img src="https://img.shields.io/badge/Angular-133%20tests-red.svg" alt="Angular Tests">
25
- </p>
26
-
27
- ---
28
-
29
- Stop wrestling with Square's low-level APIs. **squareup** gives you React hooks, Angular services, and a fluent builder API that makes payment integration feel native to your framework. Tokenize cards, process payments, manage orders, and handle webhooks—all with full TypeScript support and zero boilerplate.
30
-
31
- ## Features
32
-
33
- - **Simplified APIs** - Less boilerplate, more productivity
34
- - **React Integration** - Hooks and components for payments
35
- - **Angular Integration** - Services with RxJS Observables
36
- - **Server Utilities** - Webhook verification and middleware
37
- - **Type-Safe** - Full TypeScript support with strict types
38
- - **Fluent Builders** - Chainable order and payment construction
39
-
40
- ## 🧪 Testing & Quality
41
-
42
- **329 comprehensive tests** with **99.84% code coverage** ensure reliability and maintainability:
43
-
44
- - **React Tests (110)**: Complete coverage of hooks, components, and integrations
45
- - **Angular Tests (133)**: Full service testing with RxJS observables
46
- - **Core Tests (86)**: API clients, builders, and utilities
47
- - **Coverage Breakdown**:
48
- - Statements: **99.84%**
49
- - Branches: **95.99%**
50
- - Functions: **100%**
51
- - Lines: **99.84%**
52
-
53
- Run tests with:
54
-
55
- ```bash
56
- npm test # All tests
57
- npm run test:react # React tests only
58
- npm run test:angular # Angular tests only
59
- npm run test:coverage # With coverage report
60
- ```
61
-
62
- ## Installation
63
-
64
- ```bash
65
- npm install @bates-solutions/squareup square
66
- ```
67
-
68
- ### Peer Dependencies
69
-
70
- ```bash
71
- # For React integration
72
- npm install react
73
-
74
- # For Angular integration
75
- npm install @angular/core @angular/common rxjs
76
- ```
77
-
78
- ## Quick Start
79
-
80
- ### Core (Node.js/Backend)
81
-
82
- ```typescript
83
- import { createSquareClient } from '@bates-solutions/squareup';
84
-
85
- const square = createSquareClient({
86
- accessToken: process.env.SQUARE_ACCESS_TOKEN!,
87
- environment: 'sandbox',
88
- });
89
-
90
- // Create a payment
91
- const payment = await square.payments.create({
92
- sourceId: 'cnon:card-nonce-ok',
93
- amount: 1000, // $10.00 in cents
94
- currency: 'USD',
95
- });
96
-
97
- // Build an order with fluent API
98
- const order = await square.orders
99
- .builder()
100
- .addItem({ name: 'Latte', amount: 450 })
101
- .addItem({ catalogId: 'ITEM_123', quantity: 2 })
102
- .withTip(100)
103
- .build();
104
- ```
105
-
106
- ### React
107
-
108
- ```tsx
109
- import { SquareProvider, useSquarePayment, useOrders } from '@bates-solutions/squareup/react';
110
-
111
- function App() {
112
- return (
113
- <SquareProvider applicationId="sq0idp-xxx" locationId="LXXX" environment="sandbox">
114
- <Checkout />
115
- </SquareProvider>
116
- );
117
- }
118
-
119
- function Checkout() {
120
- const { cardRef, tokenize, ready, error } = useSquarePayment();
121
- const { create: createOrder } = useOrders();
122
-
123
- const handlePay = async () => {
124
- const token = await tokenize();
125
- await createOrder({
126
- lineItems: [{ name: 'Coffee', amount: 500 }],
127
- paymentToken: token,
128
- });
129
- };
130
-
131
- return (
132
- <div>
133
- <div ref={cardRef} />
134
- <button onClick={handlePay} disabled={!ready}>
135
- Pay $5.00
136
- </button>
137
- {error && <p>{error.message}</p>}
138
- </div>
139
- );
140
- }
141
- ```
142
-
143
- ### Angular
144
-
145
- ```typescript
146
- import { SquareModule } from '@bates-solutions/squareup/angular';
147
-
148
- @NgModule({
149
- imports: [
150
- SquareModule.forRoot({
151
- applicationId: 'sq0idp-xxx',
152
- locationId: 'LXXX',
153
- environment: 'sandbox',
154
- })
155
- ]
156
- })
157
- export class AppModule {}
158
-
159
- @Component({...})
160
- export class CheckoutComponent {
161
- constructor(private square: SquarePaymentsService) {}
162
-
163
- pay$ = () => this.square.tokenize().pipe(
164
- switchMap(token => this.square.createPayment({
165
- sourceId: token,
166
- amount: 1000
167
- }))
168
- );
169
- }
170
- ```
171
-
172
- ### Server (Webhooks)
173
-
174
- ```typescript
175
- import { createNextWebhookHandler } from '@bates-solutions/squareup/server';
176
-
177
- // Next.js App Router
178
- export const POST = createNextWebhookHandler({
179
- signatureKey: process.env.SQUARE_WEBHOOK_KEY!,
180
- handlers: {
181
- 'payment.completed': async (event) => {
182
- console.log('Payment received:', event.data.id);
183
- },
184
- 'order.fulfillment.updated': async (event) => {
185
- await notifyCustomer(event.data.object);
186
- },
187
- },
188
- });
189
- ```
190
-
191
- ## API Reference
192
-
193
- ### Core Module
194
-
195
- | Export | Description |
196
- | ---------------------- | -------------------------------------- |
197
- | `createSquareClient` | Factory for creating Square API client |
198
- | `PaymentsService` | Payment processing operations |
199
- | `OrdersService` | Order management with fluent builder |
200
- | `CustomersService` | Customer CRUD and search |
201
- | `CatalogService` | Product catalog operations |
202
- | `InventoryService` | Stock tracking and adjustments |
203
- | `SubscriptionsService` | Recurring billing management |
204
- | `InvoicesService` | Invoice generation and sending |
205
- | `LoyaltyService` | Loyalty program management |
206
-
207
- ### React Module (`@bates-solutions/squareup/react`)
208
-
209
- | Export | Description |
210
- | ------------------ | --------------------------------------- |
211
- | `SquareProvider` | Context provider for SDK initialization |
212
- | `useSquare` | Access Square context |
213
- | `useSquarePayment` | Card tokenization hook |
214
- | `usePayments` | Payments API hook |
215
- | `useOrders` | Orders API hook |
216
- | `useCustomers` | Customers API hook |
217
- | `useCatalog` | Catalog API hook |
218
- | `CardInput` | Pre-built card input component |
219
- | `PaymentButton` | Google Pay / Apple Pay button |
220
-
221
- ### Angular Module (`@bates-solutions/squareup/angular`)
222
-
223
- | Export | Description |
224
- | ------------------------ | --------------------------------------- |
225
- | `SquareModule` | NgModule with `forRoot()` configuration |
226
- | `SquareSdkService` | SDK loading service |
227
- | `SquarePaymentsService` | Payment operations |
228
- | `SquareOrdersService` | Order operations |
229
- | `SquareCustomersService` | Customer operations |
230
- | `SquareCatalogService` | Catalog operations |
231
- | `SquareCardDirective` | Card input directive |
232
- | `PaymentButtonComponent` | Digital wallet component |
233
-
234
- ### Server Module (`@bates-solutions/squareup/server`)
235
-
236
- | Export | Description |
237
- | ------------------------------- | ---------------------------------- |
238
- | `verifySignature` | HMAC-SHA256 signature verification |
239
- | `createExpressWebhookHandler` | Express middleware |
240
- | `createNextWebhookHandler` | Next.js App Router handler |
241
- | `createNextPagesWebhookHandler` | Next.js Pages Router handler |
242
- | `parseNextWebhook` | Manual webhook parsing |
243
-
244
- ## Money Utilities
245
-
246
- ```typescript
247
- import { toCents, fromCents, formatMoney } from '@bates-solutions/squareup';
248
-
249
- toCents(10.99); // 1099
250
- fromCents(1099); // 10.99
251
- formatMoney(1099, 'USD'); // '$10.99'
252
- ```
253
-
254
- ## Error Handling
255
-
256
- ```typescript
257
- import {
258
- SquareApiError,
259
- SquareValidationError,
260
- SquareNetworkError,
261
- SquareAuthenticationError
262
- } from '@bates-solutions/squareup';
263
-
264
- try {
265
- await square.payments.create({ ... });
266
- } catch (error) {
267
- if (error instanceof SquareValidationError) {
268
- console.log('Invalid input:', error.errors);
269
- } else if (error instanceof SquareAuthenticationError) {
270
- console.log('Check your access token');
271
- } else if (error instanceof SquareNetworkError) {
272
- console.log('Network issue, retry later');
273
- }
274
- }
275
- ```
276
-
277
- ## Configuration
278
-
279
- | Option | Type | Required | Description |
280
- | --------------- | --------------------------- | ------------- | -------------------------------------- |
281
- | `accessToken` | `string` | Yes | Square API access token |
282
- | `environment` | `'sandbox' \| 'production'` | No | API environment (default: `'sandbox'`) |
283
- | `applicationId` | `string` | React/Angular | Web Payments SDK application ID |
284
- | `locationId` | `string` | React/Angular | Square location ID |
285
-
286
- ## Contributing
287
-
288
- Contributions are welcome! Please read our contributing guidelines before submitting a PR.
289
-
290
- ## License
291
-
292
- MIT
@@ -1 +0,0 @@
1
- //# sourceMappingURL=setup.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../../src/angular/__tests__/setup.ts"],"names":[],"mappings":""}
@@ -1,5 +0,0 @@
1
- "use strict";
2
- // Angular tests use direct instantiation and mocked NgZone,
3
- // so Zone.js is not required for our test setup.
4
- // Keeping Zone.js out avoids hanging processes in CI.
5
- //# sourceMappingURL=setup.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/angular/__tests__/setup.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,iDAAiD;AACjD,sDAAsD"}
@@ -1,2 +0,0 @@
1
- export { PaymentButtonComponent } from './payment-button.component.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/angular/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC"}
@@ -1,2 +0,0 @@
1
- export { PaymentButtonComponent } from './payment-button.component.js';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/angular/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC"}
@@ -1,49 +0,0 @@
1
- import { EventEmitter, OnInit, OnDestroy, ChangeDetectorRef } from '@angular/core';
2
- import { SquareSdkService } from '../services/square-sdk.service.js';
3
- import type { DigitalWalletOptions } from '../types.js';
4
- /**
5
- * Payment button component for Google Pay / Apple Pay
6
- *
7
- * @example
8
- * ```html
9
- * <square-payment-button
10
- * type="googlePay"
11
- * (payment)="onPayment($event)"
12
- * (error)="onError($event)"
13
- * ></square-payment-button>
14
- *
15
- * <square-payment-button
16
- * type="applePay"
17
- * [buttonOptions]="{ buttonColor: 'black' }"
18
- * (payment)="onPayment($event)"
19
- * ></square-payment-button>
20
- * ```
21
- */
22
- export declare class PaymentButtonComponent implements OnInit, OnDestroy {
23
- private sdk;
24
- private cdr;
25
- /** Payment method type */
26
- type: 'googlePay' | 'applePay';
27
- /** Button styling options */
28
- buttonOptions?: DigitalWalletOptions;
29
- /** Emits when button is ready */
30
- buttonReady: EventEmitter<void>;
31
- /** Emits payment token on success */
32
- payment: EventEmitter<string>;
33
- /** Emits when an error occurs */
34
- error: EventEmitter<Error>;
35
- /** Emits when payment is cancelled */
36
- cancel: EventEmitter<void>;
37
- private containerRef;
38
- private paymentMethod;
39
- private subscription?;
40
- ready: boolean;
41
- loading: boolean;
42
- constructor(sdk: SquareSdkService, cdr: ChangeDetectorRef);
43
- ngOnInit(): void;
44
- ngOnDestroy(): void;
45
- handleClick(): void;
46
- private initializePaymentMethod;
47
- private tokenize;
48
- }
49
- //# sourceMappingURL=payment-button.component.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"payment-button.component.d.ts","sourceRoot":"","sources":["../../../src/angular/components/payment-button.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,YAAY,EAEZ,MAAM,EACN,SAAS,EAGT,iBAAiB,EAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,KAAK,EAAuB,oBAAoB,EAAe,MAAM,aAAa,CAAC;AAE1F;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAkBa,sBAAuB,YAAW,MAAM,EAAE,SAAS;IA6B5D,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,GAAG;IA7Bb,0BAA0B;IACjB,IAAI,EAAE,WAAW,GAAG,UAAU,CAAe;IAEtD,6BAA6B;IACpB,aAAa,CAAC,EAAE,oBAAoB,CAAC;IAE9C,iCAAiC;IACvB,WAAW,qBAA4B;IAEjD,qCAAqC;IAC3B,OAAO,uBAA8B;IAE/C,iCAAiC;IACvB,KAAK,sBAA6B;IAE5C,sCAAsC;IAC5B,MAAM,qBAA4B;IAG5C,OAAO,CAAC,YAAY,CAA2B;IAE/C,OAAO,CAAC,aAAa,CAAqC;IAC1D,OAAO,CAAC,YAAY,CAAC,CAAe;IAEpC,KAAK,UAAS;IACd,OAAO,UAAS;gBAGN,GAAG,EAAE,gBAAgB,EACrB,GAAG,EAAE,iBAAiB;IAGhC,QAAQ,IAAI,IAAI;IAWhB,WAAW,IAAI,IAAI;IAQnB,WAAW,IAAI,IAAI;YAQL,uBAAuB;YAyBvB,QAAQ;CA4BvB"}
@@ -1,176 +0,0 @@
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
- import { Component, Input, Output, EventEmitter, ElementRef, ViewChild, ChangeDetectionStrategy, ChangeDetectorRef, } from '@angular/core';
11
- import { SquareSdkService } from '../services/square-sdk.service.js';
12
- /**
13
- * Payment button component for Google Pay / Apple Pay
14
- *
15
- * @example
16
- * ```html
17
- * <square-payment-button
18
- * type="googlePay"
19
- * (payment)="onPayment($event)"
20
- * (error)="onError($event)"
21
- * ></square-payment-button>
22
- *
23
- * <square-payment-button
24
- * type="applePay"
25
- * [buttonOptions]="{ buttonColor: 'black' }"
26
- * (payment)="onPayment($event)"
27
- * ></square-payment-button>
28
- * ```
29
- */
30
- let PaymentButtonComponent = class PaymentButtonComponent {
31
- sdk;
32
- cdr;
33
- /** Payment method type */
34
- type = 'googlePay';
35
- /** Button styling options */
36
- buttonOptions;
37
- /** Emits when button is ready */
38
- buttonReady = new EventEmitter();
39
- /** Emits payment token on success */
40
- payment = new EventEmitter();
41
- /** Emits when an error occurs */
42
- error = new EventEmitter();
43
- /** Emits when payment is cancelled */
44
- cancel = new EventEmitter();
45
- containerRef;
46
- paymentMethod = null;
47
- subscription;
48
- ready = false;
49
- loading = false;
50
- constructor(sdk, cdr) {
51
- this.sdk = sdk;
52
- this.cdr = cdr;
53
- }
54
- ngOnInit() {
55
- this.subscription = this.sdk.whenReady().subscribe({
56
- next: (payments) => {
57
- void this.initializePaymentMethod(payments);
58
- },
59
- error: (err) => {
60
- this.error.emit(err);
61
- },
62
- });
63
- }
64
- ngOnDestroy() {
65
- this.subscription?.unsubscribe();
66
- if (this.paymentMethod) {
67
- void this.paymentMethod.destroy();
68
- this.paymentMethod = null;
69
- }
70
- }
71
- handleClick() {
72
- if (!this.paymentMethod || this.loading) {
73
- return;
74
- }
75
- void this.tokenize();
76
- }
77
- async initializePaymentMethod(payments) {
78
- try {
79
- if (this.type === 'googlePay') {
80
- this.paymentMethod = await payments.googlePay({});
81
- }
82
- else {
83
- this.paymentMethod = await payments.applePay({});
84
- }
85
- await this.paymentMethod.attach(this.containerRef.nativeElement, this.buttonOptions);
86
- this.ready = true;
87
- this.buttonReady.emit();
88
- this.cdr.markForCheck();
89
- }
90
- catch (err) {
91
- const error = err instanceof Error ? err : new Error(`Failed to initialize ${this.type}`);
92
- this.error.emit(error);
93
- this.cdr.markForCheck();
94
- }
95
- }
96
- async tokenize() {
97
- if (!this.paymentMethod) {
98
- return;
99
- }
100
- this.loading = true;
101
- this.cdr.markForCheck();
102
- try {
103
- const result = await this.paymentMethod.tokenize();
104
- if (result.status === 'OK' && result.token) {
105
- this.payment.emit(result.token);
106
- }
107
- else if (result.status === 'Cancel') {
108
- this.cancel.emit();
109
- }
110
- else {
111
- const errorMessage = result.errors?.map((e) => e.message).join(', ') ?? 'Payment failed';
112
- throw new Error(errorMessage);
113
- }
114
- }
115
- catch (err) {
116
- const error = err instanceof Error ? err : new Error('Payment failed');
117
- this.error.emit(error);
118
- }
119
- finally {
120
- this.loading = false;
121
- this.cdr.markForCheck();
122
- }
123
- }
124
- };
125
- __decorate([
126
- Input(),
127
- __metadata("design:type", String)
128
- ], PaymentButtonComponent.prototype, "type", void 0);
129
- __decorate([
130
- Input(),
131
- __metadata("design:type", Object)
132
- ], PaymentButtonComponent.prototype, "buttonOptions", void 0);
133
- __decorate([
134
- Output(),
135
- __metadata("design:type", Object)
136
- ], PaymentButtonComponent.prototype, "buttonReady", void 0);
137
- __decorate([
138
- Output(),
139
- __metadata("design:type", Object)
140
- ], PaymentButtonComponent.prototype, "payment", void 0);
141
- __decorate([
142
- Output(),
143
- __metadata("design:type", Object)
144
- ], PaymentButtonComponent.prototype, "error", void 0);
145
- __decorate([
146
- Output(),
147
- __metadata("design:type", Object)
148
- ], PaymentButtonComponent.prototype, "cancel", void 0);
149
- __decorate([
150
- ViewChild('buttonContainer', { static: true }),
151
- __metadata("design:type", ElementRef)
152
- ], PaymentButtonComponent.prototype, "containerRef", void 0);
153
- PaymentButtonComponent = __decorate([
154
- Component({
155
- selector: 'square-payment-button',
156
- standalone: true,
157
- template: `
158
- <div
159
- #buttonContainer
160
- [style.minHeight.px]="48"
161
- [style.cursor]="ready && !loading ? 'pointer' : 'default'"
162
- [style.opacity]="loading ? 0.7 : 1"
163
- (click)="handleClick()"
164
- role="button"
165
- [attr.tabindex]="ready ? 0 : -1"
166
- [attr.aria-disabled]="!ready || loading"
167
- [attr.aria-label]="'Pay with ' + (type === 'googlePay' ? 'Google Pay' : 'Apple Pay')"
168
- ></div>
169
- `,
170
- changeDetection: ChangeDetectionStrategy.OnPush,
171
- }),
172
- __metadata("design:paramtypes", [SquareSdkService,
173
- ChangeDetectorRef])
174
- ], PaymentButtonComponent);
175
- export { PaymentButtonComponent };
176
- //# sourceMappingURL=payment-button.component.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"payment-button.component.js","sourceRoot":"","sources":["../../../src/angular/components/payment-button.component.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,SAAS,EACT,KAAK,EACL,MAAM,EACN,YAAY,EACZ,UAAU,EAGV,SAAS,EACT,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AAEv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mC;AAGpC;IADP,SAAS,CAAC,iBAAiB,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;8BACxB,UAAU;4DAAc;AApBpC,sBAAsB;IAlBlC,SAAS,CAAC;QACT,QAAQ,EAAE,uBAAuB;QACjC,UAAU,EAAE,IAAI;QAChB,QAAQ,EAAE;;;;;;;;;;;;GAYT;QACD,eAAe,EAAE,uBAAuB,CAAC,MAAM;KAChD,CAAC;qCA8Be,gBAAgB;QAChB,iBAAiB;GA9BrB,sBAAsB,CAiHlC"}
@@ -1,2 +0,0 @@
1
- export { SquareCardDirective } from './square-card.directive.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/angular/directives/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC"}
@@ -1,2 +0,0 @@
1
- export { SquareCardDirective } from './square-card.directive.js';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/angular/directives/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC"}
@@ -1,52 +0,0 @@
1
- import { ElementRef, OnInit, OnDestroy, EventEmitter } from '@angular/core';
2
- import { SquarePaymentsService } from '../services/square-payments.service.js';
3
- import type { CardOptions } from '../types.js';
4
- /**
5
- * Directive for attaching Square card input to an element
6
- *
7
- * @example
8
- * ```html
9
- * <div
10
- * squareCard
11
- * [cardOptions]="{ style: { input: { fontSize: '16px' } } }"
12
- * (cardReady)="onCardReady()"
13
- * (cardError)="onCardError($event)"
14
- * ></div>
15
- *
16
- * <button (click)="pay()" [disabled]="!cardReady">Pay</button>
17
- * ```
18
- *
19
- * ```typescript
20
- * @Component({...})
21
- * export class CheckoutComponent {
22
- * cardReady = false;
23
- *
24
- * constructor(private payments: SquarePaymentsService) {}
25
- *
26
- * onCardReady() {
27
- * this.cardReady = true;
28
- * }
29
- *
30
- * pay() {
31
- * this.payments.tokenize().subscribe(token => {
32
- * console.log('Token:', token);
33
- * });
34
- * }
35
- * }
36
- * ```
37
- */
38
- export declare class SquareCardDirective implements OnInit, OnDestroy {
39
- private elementRef;
40
- private payments;
41
- /** Card styling options */
42
- cardOptions?: CardOptions;
43
- /** Emits when card input is ready */
44
- cardReady: EventEmitter<void>;
45
- /** Emits when an error occurs */
46
- cardError: EventEmitter<Error>;
47
- private subscription?;
48
- constructor(elementRef: ElementRef<HTMLElement>, payments: SquarePaymentsService);
49
- ngOnInit(): void;
50
- ngOnDestroy(): void;
51
- }
52
- //# sourceMappingURL=square-card.directive.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"square-card.directive.d.ts","sourceRoot":"","sources":["../../../src/angular/directives/square-card.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,MAAM,EACN,SAAS,EAET,YAAY,EAEb,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAIa,mBAAoB,YAAW,MAAM,EAAE,SAAS;IAazD,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,QAAQ;IAblB,2BAA2B;IAClB,WAAW,CAAC,EAAE,WAAW,CAAC;IAEnC,qCAAqC;IAC3B,SAAS,qBAA4B;IAE/C,iCAAiC;IACvB,SAAS,sBAA6B;IAEhD,OAAO,CAAC,YAAY,CAAC,CAAe;gBAG1B,UAAU,EAAE,UAAU,CAAC,WAAW,CAAC,EACnC,QAAQ,EAAE,qBAAqB;IAGzC,QAAQ,IAAI,IAAI;IAahB,WAAW,IAAI,IAAI;CAIpB"}