@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Bates Solutions
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
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
|
+
|
|
4
|
+
<img src="https://img.shields.io/badge/Angular-17+-DD0031?logo=angular&logoColor=white&style=for-the-badge" alt="Angular" height="28">
|
|
5
|
+
|
|
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
|
+
## 📚 Documentation
|
|
79
|
+
|
|
80
|
+
- **[Getting Started](./docs/getting-started/)** - Installation and setup guides
|
|
81
|
+
- **[Guides](./docs/guides/)** - Framework-specific tutorials and examples
|
|
82
|
+
- **[API Reference](./docs/api-reference.md)** - Complete API documentation
|
|
83
|
+
- **[Configuration](./docs/getting-started/configuration.md)** - Environment setup
|
|
84
|
+
|
|
85
|
+
## Quick Start
|
|
86
|
+
|
|
87
|
+
### Backend
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { createSquareClient } from '@bates-solutions/squareup';
|
|
91
|
+
|
|
92
|
+
const client = createSquareClient({
|
|
93
|
+
accessToken: process.env.SQUARE_ACCESS_TOKEN!,
|
|
94
|
+
environment: 'sandbox',
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const payment = await client.payments.create({
|
|
98
|
+
sourceId: 'cnon:card-nonce',
|
|
99
|
+
amount: 1000, // $10.00
|
|
100
|
+
currency: 'USD',
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### React
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
import { SquareProvider, usePayments } from '@bates-solutions/squareup/react';
|
|
108
|
+
|
|
109
|
+
function App() {
|
|
110
|
+
return (
|
|
111
|
+
<SquareProvider applicationId="sq0idp-xxx" locationId="LXXX" environment="sandbox">
|
|
112
|
+
<PaymentForm />
|
|
113
|
+
</SquareProvider>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function PaymentForm() {
|
|
118
|
+
const { processPayment } = usePayments();
|
|
119
|
+
|
|
120
|
+
const handlePayment = async () => {
|
|
121
|
+
const result = await processPayment({
|
|
122
|
+
sourceId: 'cnon:card-nonce',
|
|
123
|
+
amount: 1000, // $10.00
|
|
124
|
+
currency: 'USD',
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
return <button onClick={handlePayment}>Pay $10.00</button>;
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Angular
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { SquareModule } from '@bates-solutions/squareup/angular';
|
|
136
|
+
|
|
137
|
+
@NgModule({
|
|
138
|
+
imports: [
|
|
139
|
+
SquareModule.forRoot({
|
|
140
|
+
accessToken: 'YOUR_ACCESS_TOKEN',
|
|
141
|
+
environment: 'sandbox',
|
|
142
|
+
}),
|
|
143
|
+
],
|
|
144
|
+
})
|
|
145
|
+
export class AppModule {}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Contributing
|
|
149
|
+
|
|
150
|
+
We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md) for details.
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT - see [LICENSE](./LICENSE) for details.
|
package/README.md.backup
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
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
|
+
|
|
4
|
+
<img src="https://img.shields.io/badge/Angular-17+-DD0031?logo=angular&logoColor=white&style=for-the-badge" alt="Angular" height="28">
|
|
5
|
+
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../../src/angular/__tests__/setup.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/angular/__tests__/setup.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,iDAAiD;AACjD,sDAAsD"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/angular/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|