-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebsocket.ts
60 lines (40 loc) · 1.27 KB
/
websocket.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require('dotenv').config()
import { SubscribeOptions, subscribe, events } from './src/lib'
export async function main() {
const subscribeOptions: SubscribeOptions = {
websocket: {
auth: {
token: String(process.env.ANYPAY_AUTH_TOKEN)
}
}
}
if (process.env.ANYPAY_WEBSOCKET_URL) {
subscribeOptions.websocket.url = process.env.ANYPAY_WEBSOCKET_URL
}
subscribe(subscribeOptions)
.onInvoiceCreated((event: events.InvoiceCreatedEvent) => {
console.log(JSON.stringify(event))
})
.onInvoiceCancelled((event: events.InvoiceCancelledEvent) => {
console.log(JSON.stringify(event))
})
.onInvoicePaid((event: events.InvoicePaidEvent) => {
console.log(JSON.stringify(event))
})
.onPaymentConfirming((event: events.PaymentConfirmingEvent) => {
console.log(JSON.stringify(event))
})
.onPaymentConfirmed((event: events.InvoiceCancelledEvent) => {
console.log(JSON.stringify(event))
})
.onPaymentFailed((event: events.PaymentFailedEvent) => {
console.log(JSON.stringify(event))
})
.onWebsocketConnected((event: events.WebsocketConnectedEvent) => {
console.log(JSON.stringify(event))
})
.onError((error: Error) => {
console.error(error)
})
}
main()