@t-0/provider-starter-ts 0.4.10 → 0.4.13
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/package.json +1 -1
- package/template/package-lock.json +9 -5
- package/template/package.json +1 -1
- package/template/src/service.ts +57 -43
- package/template/src/submit_payment.ts +24 -15
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"version": "1.0.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@t-0/provider-sdk": "^1.0.
|
|
12
|
+
"@t-0/provider-sdk": "^1.0.51",
|
|
13
13
|
"dotenv": "^16.3.1",
|
|
14
14
|
"tiny-invariant": "^1.3.3"
|
|
15
15
|
},
|
|
@@ -23,13 +23,15 @@
|
|
|
23
23
|
"version": "2.10.0",
|
|
24
24
|
"resolved": "https://registry.npmjs.org/@bufbuild/protobuf/-/protobuf-2.10.0.tgz",
|
|
25
25
|
"integrity": "sha512-fdRs9PSrBF7QUntpZpq6BTw58fhgGJojgg39m9oFOJGZT+nip9b0so5cYY1oWl5pvemDLr0cPPsH46vwThEbpQ==",
|
|
26
|
-
"license": "(Apache-2.0 AND BSD-3-Clause)"
|
|
26
|
+
"license": "(Apache-2.0 AND BSD-3-Clause)",
|
|
27
|
+
"peer": true
|
|
27
28
|
},
|
|
28
29
|
"node_modules/@connectrpc/connect": {
|
|
29
30
|
"version": "2.1.0",
|
|
30
31
|
"resolved": "https://registry.npmjs.org/@connectrpc/connect/-/connect-2.1.0.tgz",
|
|
31
32
|
"integrity": "sha512-xhiwnYlJNHzmFsRw+iSPIwXR/xweTvTw8x5HiwWp10sbVtd4OpOXbRgE7V58xs1EC17fzusF1f5uOAy24OkBuA==",
|
|
32
33
|
"license": "Apache-2.0",
|
|
34
|
+
"peer": true,
|
|
33
35
|
"peerDependencies": {
|
|
34
36
|
"@bufbuild/protobuf": "^2.7.0"
|
|
35
37
|
}
|
|
@@ -120,9 +122,9 @@
|
|
|
120
122
|
}
|
|
121
123
|
},
|
|
122
124
|
"node_modules/@t-0/provider-sdk": {
|
|
123
|
-
"version": "1.0.
|
|
124
|
-
"resolved": "https://registry.npmjs.org/@t-0/provider-sdk/-/provider-sdk-1.0.
|
|
125
|
-
"integrity": "sha512-
|
|
125
|
+
"version": "1.0.51",
|
|
126
|
+
"resolved": "https://registry.npmjs.org/@t-0/provider-sdk/-/provider-sdk-1.0.51.tgz",
|
|
127
|
+
"integrity": "sha512-HsC5DUIoV/1GNRIdVHvDP7PHdV6ccw864kjBoX4z6nj0QxyzGG/+UET+gEu6JedrPIdxC5KCSfr/had99cSvQw==",
|
|
126
128
|
"dependencies": {
|
|
127
129
|
"@bufbuild/protobuf": "^2.10.0",
|
|
128
130
|
"@connectrpc/connect": "^2.1.0",
|
|
@@ -166,6 +168,7 @@
|
|
|
166
168
|
"integrity": "sha512-ZsJzA5thDQMSQO788d7IocwwQbI8B5OPzmqNvpf3NY/+MHDAS759Wo0gd2WQeXYt5AAAQjzcrTVC6SKCuYgoCQ==",
|
|
167
169
|
"dev": true,
|
|
168
170
|
"license": "MIT",
|
|
171
|
+
"peer": true,
|
|
169
172
|
"dependencies": {
|
|
170
173
|
"undici-types": "~6.21.0"
|
|
171
174
|
}
|
|
@@ -295,6 +298,7 @@
|
|
|
295
298
|
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
|
296
299
|
"dev": true,
|
|
297
300
|
"license": "Apache-2.0",
|
|
301
|
+
"peer": true,
|
|
298
302
|
"bin": {
|
|
299
303
|
"tsc": "bin/tsc",
|
|
300
304
|
"tsserver": "bin/tsserver"
|
package/template/package.json
CHANGED
package/template/src/service.ts
CHANGED
|
@@ -1,58 +1,72 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
AppendLedgerEntriesRequest,
|
|
3
|
+
AppendLedgerEntriesResponse,
|
|
4
|
+
ApprovePaymentQuoteRequest,
|
|
5
|
+
ApprovePaymentQuoteResponse,
|
|
6
|
+
type Client,
|
|
7
|
+
HandlerContext,
|
|
8
|
+
NetworkService,
|
|
9
|
+
PayoutRequest,
|
|
10
|
+
PayoutResponse,
|
|
11
|
+
UpdateLimitRequest,
|
|
12
|
+
UpdateLimitResponse,
|
|
13
|
+
UpdatePaymentRequest,
|
|
14
|
+
UpdatePaymentResponse,
|
|
11
15
|
} from "@t-0/provider-sdk";
|
|
12
16
|
|
|
13
17
|
/*
|
|
14
18
|
Please refer to docs, proto definition comments or source code comments to understand purpose of fields
|
|
15
19
|
*/
|
|
16
20
|
const CreateProviderService = (networkClient: Client<typeof NetworkService>) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
return {
|
|
22
|
+
async updatePayment(req: UpdatePaymentRequest, _: HandlerContext) {
|
|
23
|
+
// TODO: Step 2.1 implement how you handle updates of payment initiated by you
|
|
24
|
+
console.log(`Received payment update for ${req.paymentId}, payment ${req.result.case}`)
|
|
25
|
+
return {} as UpdatePaymentResponse
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
async payOut(req: PayoutRequest, _: HandlerContext) {
|
|
29
|
+
// TODO: Step 2.4 implement how you do payouts (payments initiated by your counterparts)
|
|
30
|
+
console.log(`Received payout request ${req.payoutId}`)
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
//TODO: confirmPayout should be called when you system notifies that payout has been made successfully
|
|
33
|
+
setInterval(() => {
|
|
34
|
+
networkClient.confirmPayout({
|
|
35
|
+
paymentId: req.paymentId,
|
|
36
|
+
payoutId: req.payoutId,
|
|
37
|
+
})
|
|
38
|
+
}, 2000);
|
|
39
|
+
return {
|
|
40
|
+
result: {
|
|
41
|
+
case: "accepted",
|
|
42
|
+
value: {},
|
|
43
|
+
},
|
|
44
|
+
} as PayoutResponse
|
|
45
|
+
},
|
|
27
46
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
payoutId: req.payoutId,
|
|
33
|
-
})
|
|
34
|
-
}, 2000);
|
|
35
|
-
return {
|
|
36
|
-
result: {
|
|
37
|
-
case: "accepted",
|
|
38
|
-
value: {},
|
|
47
|
+
async updateLimit(req: UpdateLimitRequest, _: HandlerContext) {
|
|
48
|
+
// TODO: optionally implement updates on your limits and limits usage
|
|
49
|
+
console.log(`Received update of limits with provider ${req.limits[0].counterpartId}`)
|
|
50
|
+
return {} as UpdateLimitResponse
|
|
39
51
|
},
|
|
40
|
-
} as PayoutResponse
|
|
41
|
-
},
|
|
42
52
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
async appendLedgerEntries(req: AppendLedgerEntriesRequest, _: HandlerContext) {
|
|
54
|
+
// TODO: optionally implement handling of new ledger transactions and new ledger entries
|
|
55
|
+
console.log(`Received ledger entries for ${req.transactions} transaction(s)`)
|
|
56
|
+
return {} as AppendLedgerEntriesResponse
|
|
57
|
+
},
|
|
48
58
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
async approvePaymentQuote(req: ApprovePaymentQuoteRequest, _: HandlerContext) {
|
|
60
|
+
// TODO: when the payment goes through the Manual AML Check on the pay-out provider side, the provider submitted the payment will have a last look to approve final quote
|
|
61
|
+
console.log(`Received approve payment quote request for ${req.paymentId}`)
|
|
62
|
+
return {
|
|
63
|
+
result: {
|
|
64
|
+
case: "accepted",
|
|
65
|
+
value: {}
|
|
66
|
+
}
|
|
67
|
+
} as ApprovePaymentQuoteResponse
|
|
68
|
+
}
|
|
69
|
+
}
|
|
56
70
|
};
|
|
57
71
|
|
|
58
72
|
export default CreateProviderService;
|
|
@@ -3,22 +3,31 @@ import {toProtoDecimal} from "./lib";
|
|
|
3
3
|
|
|
4
4
|
export default async function submitPayment(networkClient: Client<typeof NetworkService>): Promise<void> {
|
|
5
5
|
// TODO: Step 2.3 replace this with receiving quotes from you systems and publishing them into t-0 Network. We recommend publishing at least once per 5 seconds, but not more than once per second
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const result = await networkClient.createPayment({
|
|
7
|
+
currency: 'GBP',
|
|
8
|
+
amount: {
|
|
8
9
|
amount: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
value: toProtoDecimal(10, 0),
|
|
12
|
-
},
|
|
10
|
+
case: "payOutAmount",
|
|
11
|
+
value: toProtoDecimal(10, 0),
|
|
13
12
|
},
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
},
|
|
14
|
+
paymentDetails: {
|
|
15
|
+
details: {
|
|
16
|
+
case: "sepa",
|
|
17
|
+
value: {
|
|
18
|
+
iban: 'GB12345567890',
|
|
19
|
+
beneficiaryName: 'Max Mustermann',
|
|
21
20
|
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
switch (result.result.case) {
|
|
26
|
+
case 'accepted':
|
|
27
|
+
console.log(`Payment accepted, ${result.result.value.settlementAmount} USD to settle`)
|
|
28
|
+
break;
|
|
29
|
+
case 'failure':
|
|
30
|
+
console.log(`Payment failed with '${result.result.value.reason}'`)
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
24
33
|
}
|