@t-0/provider-sdk 1.0.25 → 1.0.26
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/lib/cjs/client/client.js +46 -0
- package/lib/cjs/client/signer.js +69 -0
- package/lib/cjs/common/gen/tzero/v1/common/common_pb.js +56 -0
- package/lib/cjs/common/gen/tzero/v1/common/payment_method_pb.js +60 -0
- package/lib/cjs/common/gen/tzero/v1/payment/network_pb.js +147 -0
- package/lib/cjs/common/gen/tzero/v1/payment/provider_pb.js +206 -0
- package/lib/cjs/common/gen/tzero/v1/payment_intent/provider/provider_pb.js +87 -0
- package/lib/cjs/common/gen/tzero/v1/payment_intent/recipient/recipient_pb.js +62 -0
- package/lib/cjs/common/gen/tzero/v1/public/public_pb.js +88 -0
- package/lib/cjs/common/headers.js +10 -0
- package/lib/cjs/examples/payment_intent/pay-in-provider-flow.d.ts +4 -0
- package/lib/cjs/examples/payment_intent/pay-in-provider-flow.js +56 -0
- package/lib/cjs/examples/payment_intent/service.d.ts +1 -0
- package/lib/cjs/examples/payment_intent/service.js +68 -0
- package/lib/cjs/examples/server.d.ts +4 -0
- package/lib/cjs/examples/server.js +93 -0
- package/lib/cjs/examples/update-quote.d.ts +4 -0
- package/lib/cjs/examples/update-quote.js +42 -0
- package/lib/cjs/index.js +50 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/payment_intent/provider/index.js +17 -0
- package/lib/cjs/payment_intent/recipient/index.js +17 -0
- package/lib/cjs/service/node.js +15 -0
- package/lib/cjs/service/service.js +112 -0
- package/lib/esm/client/client.d.ts +16 -0
- package/lib/esm/client/signer.d.ts +3 -0
- package/lib/esm/common/gen/tzero/v1/common/common_pb.d.ts +64 -0
- package/lib/esm/common/gen/tzero/v1/common/payment_method_pb.d.ts +122 -0
- package/lib/esm/common/gen/tzero/v1/payment/network_pb.d.ts +567 -0
- package/lib/esm/common/gen/tzero/v1/payment/provider_pb.d.ts +641 -0
- package/lib/esm/common/gen/tzero/v1/payment_intent/provider/provider_pb.d.ts +296 -0
- package/lib/esm/common/gen/tzero/v1/payment_intent/recipient/recipient_pb.d.ts +214 -0
- package/lib/esm/common/gen/tzero/v1/public/public_pb.d.ts +234 -0
- package/lib/esm/common/headers.d.ts +6 -0
- package/lib/esm/examples/payment_intent/pay-in-provider-flow.d.ts +4 -0
- package/lib/esm/examples/payment_intent/pay-in-provider-flow.js +51 -0
- package/lib/esm/examples/payment_intent/service.d.ts +1 -0
- package/lib/esm/examples/payment_intent/service.js +30 -0
- package/lib/esm/examples/server.d.ts +4 -0
- package/lib/esm/examples/server.js +55 -0
- package/lib/esm/examples/update-quote.d.ts +4 -0
- package/lib/esm/examples/update-quote.js +37 -0
- package/lib/esm/index.d.ts +11 -0
- package/lib/esm/payment_intent/provider/index.js +1 -0
- package/lib/esm/payment_intent/recipient/index.js +1 -0
- package/lib/esm/service/node.d.ts +3 -0
- package/lib/esm/service/service.d.ts +15 -0
- package/lib/{service → esm/service}/service.js +2 -2
- package/lib/tsconfig.cjs.tsbuildinfo +1 -0
- package/lib/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +16 -7
- /package/lib/{client → cjs/client}/client.d.ts +0 -0
- /package/lib/{client → cjs/client}/signer.d.ts +0 -0
- /package/lib/{common → cjs/common}/gen/tzero/v1/common/common_pb.d.ts +0 -0
- /package/lib/{common → cjs/common}/gen/tzero/v1/common/payment_method_pb.d.ts +0 -0
- /package/lib/{common → cjs/common}/gen/tzero/v1/payment/network_pb.d.ts +0 -0
- /package/lib/{common → cjs/common}/gen/tzero/v1/payment/provider_pb.d.ts +0 -0
- /package/lib/{common → cjs/common}/gen/tzero/v1/payment_intent/provider/provider_pb.d.ts +0 -0
- /package/lib/{common → cjs/common}/gen/tzero/v1/payment_intent/recipient/recipient_pb.d.ts +0 -0
- /package/lib/{common → cjs/common}/gen/tzero/v1/public/public_pb.d.ts +0 -0
- /package/lib/{common → cjs/common}/headers.d.ts +0 -0
- /package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/lib/{payment_intent → cjs/payment_intent}/provider/index.d.ts +0 -0
- /package/lib/{payment_intent → cjs/payment_intent}/recipient/index.d.ts +0 -0
- /package/lib/{service → cjs/service}/node.d.ts +0 -0
- /package/lib/{service → cjs/service}/service.d.ts +0 -0
- /package/lib/{client → esm/client}/client.js +0 -0
- /package/lib/{client → esm/client}/signer.js +0 -0
- /package/lib/{common → esm/common}/gen/tzero/v1/common/common_pb.js +0 -0
- /package/lib/{common → esm/common}/gen/tzero/v1/common/payment_method_pb.js +0 -0
- /package/lib/{common → esm/common}/gen/tzero/v1/payment/network_pb.js +0 -0
- /package/lib/{common → esm/common}/gen/tzero/v1/payment/provider_pb.js +0 -0
- /package/lib/{common → esm/common}/gen/tzero/v1/payment_intent/provider/provider_pb.js +0 -0
- /package/lib/{common → esm/common}/gen/tzero/v1/payment_intent/recipient/recipient_pb.js +0 -0
- /package/lib/{common → esm/common}/gen/tzero/v1/public/public_pb.js +0 -0
- /package/lib/{common → esm/common}/headers.js +0 -0
- /package/lib/{index.js → esm/index.js} +0 -0
- /package/lib/{payment_intent/provider/index.js → esm/payment_intent/provider/index.d.ts} +0 -0
- /package/lib/{payment_intent/recipient/index.js → esm/payment_intent/recipient/index.d.ts} +0 -0
- /package/lib/{service → esm/service}/node.js +0 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import type { GenFile, GenMessage, GenService } from "@bufbuild/protobuf/codegenv2";
|
|
2
|
+
import type { Message } from "@bufbuild/protobuf";
|
|
3
|
+
/**
|
|
4
|
+
* Describes the file tzero/v1/public/public.proto.
|
|
5
|
+
*/
|
|
6
|
+
export declare const file_tzero_v1_public_public: GenFile;
|
|
7
|
+
/**
|
|
8
|
+
* @generated from message tzero.v1.public.GetPaymentQuoteRequest
|
|
9
|
+
*/
|
|
10
|
+
export type GetPaymentQuoteRequest = Message<"tzero.v1.public.GetPaymentQuoteRequest"> & {};
|
|
11
|
+
/**
|
|
12
|
+
* Describes the message tzero.v1.public.GetPaymentQuoteRequest.
|
|
13
|
+
* Use `create(GetPaymentQuoteRequestSchema)` to create a new message.
|
|
14
|
+
*/
|
|
15
|
+
export declare const GetPaymentQuoteRequestSchema: GenMessage<GetPaymentQuoteRequest>;
|
|
16
|
+
/**
|
|
17
|
+
* @generated from message tzero.v1.public.GetPaymentQuoteResponse
|
|
18
|
+
*/
|
|
19
|
+
export type GetPaymentQuoteResponse = Message<"tzero.v1.public.GetPaymentQuoteResponse"> & {};
|
|
20
|
+
/**
|
|
21
|
+
* Describes the message tzero.v1.public.GetPaymentQuoteResponse.
|
|
22
|
+
* Use `create(GetPaymentQuoteResponseSchema)` to create a new message.
|
|
23
|
+
*/
|
|
24
|
+
export declare const GetPaymentQuoteResponseSchema: GenMessage<GetPaymentQuoteResponse>;
|
|
25
|
+
/**
|
|
26
|
+
* @generated from message tzero.v1.public.CreatePaymentIntentRequest
|
|
27
|
+
*/
|
|
28
|
+
export type CreatePaymentIntentRequest = Message<"tzero.v1.public.CreatePaymentIntentRequest"> & {};
|
|
29
|
+
/**
|
|
30
|
+
* Describes the message tzero.v1.public.CreatePaymentIntentRequest.
|
|
31
|
+
* Use `create(CreatePaymentIntentRequestSchema)` to create a new message.
|
|
32
|
+
*/
|
|
33
|
+
export declare const CreatePaymentIntentRequestSchema: GenMessage<CreatePaymentIntentRequest>;
|
|
34
|
+
/**
|
|
35
|
+
* @generated from message tzero.v1.public.CreatePaymentIntentResponse
|
|
36
|
+
*/
|
|
37
|
+
export type CreatePaymentIntentResponse = Message<"tzero.v1.public.CreatePaymentIntentResponse"> & {};
|
|
38
|
+
/**
|
|
39
|
+
* Describes the message tzero.v1.public.CreatePaymentIntentResponse.
|
|
40
|
+
* Use `create(CreatePaymentIntentResponseSchema)` to create a new message.
|
|
41
|
+
*/
|
|
42
|
+
export declare const CreatePaymentIntentResponseSchema: GenMessage<CreatePaymentIntentResponse>;
|
|
43
|
+
/**
|
|
44
|
+
* @generated from message tzero.v1.public.GetPayInDetailsRequest
|
|
45
|
+
*/
|
|
46
|
+
export type GetPayInDetailsRequest = Message<"tzero.v1.public.GetPayInDetailsRequest"> & {
|
|
47
|
+
/**
|
|
48
|
+
* @generated from field: string payment_id = 10;
|
|
49
|
+
*/
|
|
50
|
+
paymentId: string;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Describes the message tzero.v1.public.GetPayInDetailsRequest.
|
|
54
|
+
* Use `create(GetPayInDetailsRequestSchema)` to create a new message.
|
|
55
|
+
*/
|
|
56
|
+
export declare const GetPayInDetailsRequestSchema: GenMessage<GetPayInDetailsRequest>;
|
|
57
|
+
/**
|
|
58
|
+
* @generated from message tzero.v1.public.GetPayInDetailsResponse
|
|
59
|
+
*/
|
|
60
|
+
export type GetPayInDetailsResponse = Message<"tzero.v1.public.GetPayInDetailsResponse"> & {};
|
|
61
|
+
/**
|
|
62
|
+
* Describes the message tzero.v1.public.GetPayInDetailsResponse.
|
|
63
|
+
* Use `create(GetPayInDetailsResponseSchema)` to create a new message.
|
|
64
|
+
*/
|
|
65
|
+
export declare const GetPayInDetailsResponseSchema: GenMessage<GetPayInDetailsResponse>;
|
|
66
|
+
/**
|
|
67
|
+
* @generated from message tzero.v1.public.GetPaymentsRequest
|
|
68
|
+
*/
|
|
69
|
+
export type GetPaymentsRequest = Message<"tzero.v1.public.GetPaymentsRequest"> & {};
|
|
70
|
+
/**
|
|
71
|
+
* Describes the message tzero.v1.public.GetPaymentsRequest.
|
|
72
|
+
* Use `create(GetPaymentsRequestSchema)` to create a new message.
|
|
73
|
+
*/
|
|
74
|
+
export declare const GetPaymentsRequestSchema: GenMessage<GetPaymentsRequest>;
|
|
75
|
+
/**
|
|
76
|
+
* @generated from message tzero.v1.public.GetPaymentsResponse
|
|
77
|
+
*/
|
|
78
|
+
export type GetPaymentsResponse = Message<"tzero.v1.public.GetPaymentsResponse"> & {};
|
|
79
|
+
/**
|
|
80
|
+
* Describes the message tzero.v1.public.GetPaymentsResponse.
|
|
81
|
+
* Use `create(GetPaymentsResponseSchema)` to create a new message.
|
|
82
|
+
*/
|
|
83
|
+
export declare const GetPaymentsResponseSchema: GenMessage<GetPaymentsResponse>;
|
|
84
|
+
/**
|
|
85
|
+
* @generated from message tzero.v1.public.GetCurrentUserRequest
|
|
86
|
+
*/
|
|
87
|
+
export type GetCurrentUserRequest = Message<"tzero.v1.public.GetCurrentUserRequest"> & {};
|
|
88
|
+
/**
|
|
89
|
+
* Describes the message tzero.v1.public.GetCurrentUserRequest.
|
|
90
|
+
* Use `create(GetCurrentUserRequestSchema)` to create a new message.
|
|
91
|
+
*/
|
|
92
|
+
export declare const GetCurrentUserRequestSchema: GenMessage<GetCurrentUserRequest>;
|
|
93
|
+
/**
|
|
94
|
+
* @generated from message tzero.v1.public.GetCurrentUserResponse
|
|
95
|
+
*/
|
|
96
|
+
export type GetCurrentUserResponse = Message<"tzero.v1.public.GetCurrentUserResponse"> & {
|
|
97
|
+
/**
|
|
98
|
+
* @generated from field: string id = 10;
|
|
99
|
+
*/
|
|
100
|
+
id: string;
|
|
101
|
+
/**
|
|
102
|
+
* @generated from oneof tzero.v1.public.GetCurrentUserResponse.kyc_status
|
|
103
|
+
*/
|
|
104
|
+
kycStatus: {
|
|
105
|
+
/**
|
|
106
|
+
* @generated from field: tzero.v1.public.GetCurrentUserResponse.KycStatusRequired required = 100;
|
|
107
|
+
*/
|
|
108
|
+
value: GetCurrentUserResponse_KycStatusRequired;
|
|
109
|
+
case: "required";
|
|
110
|
+
} | {
|
|
111
|
+
/**
|
|
112
|
+
* @generated from field: tzero.v1.public.GetCurrentUserResponse.KycStatusPending pending = 110;
|
|
113
|
+
*/
|
|
114
|
+
value: GetCurrentUserResponse_KycStatusPending;
|
|
115
|
+
case: "pending";
|
|
116
|
+
} | {
|
|
117
|
+
/**
|
|
118
|
+
* @generated from field: tzero.v1.public.GetCurrentUserResponse.KycStatusDone done = 120;
|
|
119
|
+
*/
|
|
120
|
+
value: GetCurrentUserResponse_KycStatusDone;
|
|
121
|
+
case: "done";
|
|
122
|
+
} | {
|
|
123
|
+
case: undefined;
|
|
124
|
+
value?: undefined;
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Describes the message tzero.v1.public.GetCurrentUserResponse.
|
|
129
|
+
* Use `create(GetCurrentUserResponseSchema)` to create a new message.
|
|
130
|
+
*/
|
|
131
|
+
export declare const GetCurrentUserResponseSchema: GenMessage<GetCurrentUserResponse>;
|
|
132
|
+
/**
|
|
133
|
+
* @generated from message tzero.v1.public.GetCurrentUserResponse.KycStatusDone
|
|
134
|
+
*/
|
|
135
|
+
export type GetCurrentUserResponse_KycStatusDone = Message<"tzero.v1.public.GetCurrentUserResponse.KycStatusDone"> & {};
|
|
136
|
+
/**
|
|
137
|
+
* Describes the message tzero.v1.public.GetCurrentUserResponse.KycStatusDone.
|
|
138
|
+
* Use `create(GetCurrentUserResponse_KycStatusDoneSchema)` to create a new message.
|
|
139
|
+
*/
|
|
140
|
+
export declare const GetCurrentUserResponse_KycStatusDoneSchema: GenMessage<GetCurrentUserResponse_KycStatusDone>;
|
|
141
|
+
/**
|
|
142
|
+
* @generated from message tzero.v1.public.GetCurrentUserResponse.KycStatusRequired
|
|
143
|
+
*/
|
|
144
|
+
export type GetCurrentUserResponse_KycStatusRequired = Message<"tzero.v1.public.GetCurrentUserResponse.KycStatusRequired"> & {
|
|
145
|
+
/**
|
|
146
|
+
* @generated from field: string url = 10;
|
|
147
|
+
*/
|
|
148
|
+
url: string;
|
|
149
|
+
/**
|
|
150
|
+
* or failed ... // to may be Kyc needs to be re-verified
|
|
151
|
+
*
|
|
152
|
+
* @generated from field: bool retry = 20;
|
|
153
|
+
*/
|
|
154
|
+
retry: boolean;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Describes the message tzero.v1.public.GetCurrentUserResponse.KycStatusRequired.
|
|
158
|
+
* Use `create(GetCurrentUserResponse_KycStatusRequiredSchema)` to create a new message.
|
|
159
|
+
*/
|
|
160
|
+
export declare const GetCurrentUserResponse_KycStatusRequiredSchema: GenMessage<GetCurrentUserResponse_KycStatusRequired>;
|
|
161
|
+
/**
|
|
162
|
+
* @generated from message tzero.v1.public.GetCurrentUserResponse.KycStatusPending
|
|
163
|
+
*/
|
|
164
|
+
export type GetCurrentUserResponse_KycStatusPending = Message<"tzero.v1.public.GetCurrentUserResponse.KycStatusPending"> & {};
|
|
165
|
+
/**
|
|
166
|
+
* Describes the message tzero.v1.public.GetCurrentUserResponse.KycStatusPending.
|
|
167
|
+
* Use `create(GetCurrentUserResponse_KycStatusPendingSchema)` to create a new message.
|
|
168
|
+
*/
|
|
169
|
+
export declare const GetCurrentUserResponse_KycStatusPendingSchema: GenMessage<GetCurrentUserResponse_KycStatusPending>;
|
|
170
|
+
/**
|
|
171
|
+
* this service is available as a part of public API
|
|
172
|
+
*
|
|
173
|
+
* @generated from service tzero.v1.public.PaymentService
|
|
174
|
+
*/
|
|
175
|
+
export declare const PaymentService: GenService<{
|
|
176
|
+
/**
|
|
177
|
+
* available without authentication. This will find a pair of best PayIn nad PayOut providers in order to
|
|
178
|
+
* provide best quote for payment
|
|
179
|
+
* TODO: should quote have a life time?
|
|
180
|
+
*
|
|
181
|
+
* @generated from rpc tzero.v1.public.PaymentService.GetPaymentQuote
|
|
182
|
+
*/
|
|
183
|
+
getPaymentQuote: {
|
|
184
|
+
methodKind: "unary";
|
|
185
|
+
input: typeof GetPaymentQuoteRequestSchema;
|
|
186
|
+
output: typeof GetPaymentQuoteResponseSchema;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Creates a payment details containing all the required attributes for PayOut
|
|
190
|
+
* requires authentication and completed KYC
|
|
191
|
+
*
|
|
192
|
+
* @generated from rpc tzero.v1.public.PaymentService.CreatePaymentIntent
|
|
193
|
+
*/
|
|
194
|
+
createPaymentIntent: {
|
|
195
|
+
methodKind: "unary";
|
|
196
|
+
input: typeof CreatePaymentIntentRequestSchema;
|
|
197
|
+
output: typeof CreatePaymentIntentResponseSchema;
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Returns pay in details for the corresponding Payment
|
|
201
|
+
*
|
|
202
|
+
* @generated from rpc tzero.v1.public.PaymentService.GetPayInDetails
|
|
203
|
+
*/
|
|
204
|
+
getPayInDetails: {
|
|
205
|
+
methodKind: "unary";
|
|
206
|
+
input: typeof GetPayInDetailsRequestSchema;
|
|
207
|
+
output: typeof GetPayInDetailsResponseSchema;
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Returns history of payments
|
|
211
|
+
*
|
|
212
|
+
* @generated from rpc tzero.v1.public.PaymentService.GetPayments
|
|
213
|
+
*/
|
|
214
|
+
getPayments: {
|
|
215
|
+
methodKind: "unary";
|
|
216
|
+
input: typeof GetPaymentsRequestSchema;
|
|
217
|
+
output: typeof GetPaymentsResponseSchema;
|
|
218
|
+
};
|
|
219
|
+
}>;
|
|
220
|
+
/**
|
|
221
|
+
* this service is available as a part of public API
|
|
222
|
+
*
|
|
223
|
+
* @generated from service tzero.v1.public.UserService
|
|
224
|
+
*/
|
|
225
|
+
export declare const UserService: GenService<{
|
|
226
|
+
/**
|
|
227
|
+
* @generated from rpc tzero.v1.public.UserService.GetCurrentUser
|
|
228
|
+
*/
|
|
229
|
+
getCurrentUser: {
|
|
230
|
+
methodKind: "unary";
|
|
231
|
+
input: typeof GetCurrentUserRequestSchema;
|
|
232
|
+
output: typeof GetCurrentUserResponseSchema;
|
|
233
|
+
};
|
|
234
|
+
}>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Example on how to interact with network using SDK
|
|
3
|
+
*/
|
|
4
|
+
import { Blockchain, createClient, DecimalSchema, DEFAULT_ENDPOINT, PaymentMethodType } from "../../index.js";
|
|
5
|
+
import { NetworkService } from "../../payment_intent/provider/index.js";
|
|
6
|
+
import dotenv from 'dotenv';
|
|
7
|
+
import { create } from "@bufbuild/protobuf";
|
|
8
|
+
const toProtoDecimal = (unscaled, exponent) => {
|
|
9
|
+
return create(DecimalSchema, {
|
|
10
|
+
unscaled: BigInt(unscaled),
|
|
11
|
+
exponent: exponent,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
async function main() {
|
|
15
|
+
dotenv.config();
|
|
16
|
+
const privateKeyHex = process.env.PROVIDER_PRIVATE_KEY;
|
|
17
|
+
const endpoint = process.env.TZERO_ENDPOINT || DEFAULT_ENDPOINT;
|
|
18
|
+
// PayIn provider will interact with the network using the NetworkServiceClient.
|
|
19
|
+
// It will use ConfirmPayment/RejectPaymentIntent rpcs to notify the network about the payment intent status.
|
|
20
|
+
// ConfirmSettlement rpc should be used to notify the network about the settlement transfer (in case of pre-settlement).
|
|
21
|
+
const networkClient = createClient(privateKeyHex, endpoint, NetworkService);
|
|
22
|
+
// PayIn provider will also implement the ProviderServiceHandler interface
|
|
23
|
+
// which has only 2 methods:
|
|
24
|
+
// 1. CreatePaymentIntent - to create a payment intent and return the list of
|
|
25
|
+
// available payment methods along with the URL to redirect user to make the payment.
|
|
26
|
+
// 2. ConfirmPayout - to confirm the payout after the payment is completed successfully.
|
|
27
|
+
// Initialize a provider service handler using your implementation of the
|
|
28
|
+
// ProviderServiceHandler interface.
|
|
29
|
+
// The flow starts when the network call the CreatePaymentIntent method of the PayIn provider.
|
|
30
|
+
// Pay-in provider will return the list of available payment methods, and when it receives the payment from the payer,
|
|
31
|
+
// it will call the ConfirmPayout method to confirm the payout.
|
|
32
|
+
const updateResponse = await networkClient.confirmPayment({
|
|
33
|
+
paymentIntentId: 123n, // Example payment intent ID
|
|
34
|
+
paymentMethod: PaymentMethodType.CARD
|
|
35
|
+
});
|
|
36
|
+
// if the payment collection was not successful, the provider will call RejectPaymentIntent method to notify
|
|
37
|
+
//the network about the failure.
|
|
38
|
+
const rejectResponse = await networkClient.rejectPaymentIntent({
|
|
39
|
+
paymentIntentId: 123n, // Example payment intent ID
|
|
40
|
+
reason: 'Payment failed' // Example reason for rejection
|
|
41
|
+
});
|
|
42
|
+
// Next step would be to transfer the settlement amount to the pay-out provider, and
|
|
43
|
+
// then call the ConfirmSettlement endpoint
|
|
44
|
+
const resp = await networkClient.confirmSettlement({
|
|
45
|
+
paymentIntentId: [123n], // Example payment intent ID
|
|
46
|
+
blockchain: Blockchain.TRON, // Example blockchain
|
|
47
|
+
txHash: '0x123456' // Example transaction hash
|
|
48
|
+
});
|
|
49
|
+
// And the last step - ConfirmPayout rpc will be called by Network to finalize the process.
|
|
50
|
+
}
|
|
51
|
+
void main();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Example on how to implement network notifications with SDK
|
|
3
|
+
*/
|
|
4
|
+
import { ProviderService } from "../../payment_intent/provider/index.js";
|
|
5
|
+
import * as http from "http";
|
|
6
|
+
import { createService, nodeAdapter } from "../../index.js";
|
|
7
|
+
import { signatureValidation } from "../../index.js";
|
|
8
|
+
import dotenv from "dotenv";
|
|
9
|
+
/*
|
|
10
|
+
Providers must implement this. Please refer to docs or proto definition comments
|
|
11
|
+
*/
|
|
12
|
+
const CreatePaymentIntentProviderService = () => {
|
|
13
|
+
return {
|
|
14
|
+
async createPaymentIntent(req, context) {
|
|
15
|
+
// Implement your logic to create a payment intent
|
|
16
|
+
return {};
|
|
17
|
+
},
|
|
18
|
+
async confirmPayout(req, context) {
|
|
19
|
+
// Implement your logic to confirm a payout
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
async function main() {
|
|
25
|
+
dotenv.config();
|
|
26
|
+
const networkPublicKeyHex = process.env.TZERO_PUBLIC_KEY;
|
|
27
|
+
const server = http.createServer(signatureValidation(nodeAdapter(createService(networkPublicKeyHex, r => r.service(ProviderService, CreatePaymentIntentProviderService()))))).listen(8080);
|
|
28
|
+
console.log("server is listening at", server.address());
|
|
29
|
+
}
|
|
30
|
+
void main();
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Example on how to implement network notifications with SDK
|
|
3
|
+
*/
|
|
4
|
+
import { createService, ProviderService } from "../index.js";
|
|
5
|
+
import { ProviderService as PaymentIntentProviderService } from "../payment_intent/provider/index.js";
|
|
6
|
+
import * as http from "http";
|
|
7
|
+
import { nodeAdapter } from "../index.js";
|
|
8
|
+
import { signatureValidation } from "../index.js";
|
|
9
|
+
import dotenv from "dotenv";
|
|
10
|
+
/*
|
|
11
|
+
Providers must implement this. Please refer to docs or proto definition comments
|
|
12
|
+
*/
|
|
13
|
+
const CreateProviderService = () => {
|
|
14
|
+
return {
|
|
15
|
+
async payOut(req, context) {
|
|
16
|
+
return {};
|
|
17
|
+
},
|
|
18
|
+
async updatePayment(req, context) {
|
|
19
|
+
return {};
|
|
20
|
+
},
|
|
21
|
+
async updateLimit(req, context) {
|
|
22
|
+
return {};
|
|
23
|
+
},
|
|
24
|
+
async appendLedgerEntries(req, context) {
|
|
25
|
+
return {};
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/*
|
|
30
|
+
Providers must implement this. Please refer to docs or proto definition comments
|
|
31
|
+
*/
|
|
32
|
+
const CreatePaymentIntentProviderService = () => {
|
|
33
|
+
return {
|
|
34
|
+
async createPaymentIntent(req, context) {
|
|
35
|
+
console.log(`${req.$typeName}`);
|
|
36
|
+
// Implement your logic to create a payment intent
|
|
37
|
+
return {};
|
|
38
|
+
},
|
|
39
|
+
async confirmPayout(req, context) {
|
|
40
|
+
console.log(`${req.$typeName}`);
|
|
41
|
+
// Implement your logic to confirm a payout
|
|
42
|
+
return {};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
async function main() {
|
|
47
|
+
dotenv.config();
|
|
48
|
+
const networkPublicKeyHex = process.env.TZERO_PUBLIC_KEY;
|
|
49
|
+
const server = http.createServer(signatureValidation(nodeAdapter(createService(networkPublicKeyHex, (r) => {
|
|
50
|
+
r.service(ProviderService, CreateProviderService());
|
|
51
|
+
r.service(PaymentIntentProviderService, CreatePaymentIntentProviderService());
|
|
52
|
+
})))).listen(8080);
|
|
53
|
+
console.log("server is listening at", server.address());
|
|
54
|
+
}
|
|
55
|
+
void main();
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Example on how to interact with network using SDK
|
|
3
|
+
*/
|
|
4
|
+
import { createClient, DecimalSchema, DEFAULT_ENDPOINT, NetworkService, PaymentMethodType, QuoteType } from "../index.js";
|
|
5
|
+
import dotenv from 'dotenv';
|
|
6
|
+
import { create } from "@bufbuild/protobuf";
|
|
7
|
+
import { randomUUID } from "node:crypto";
|
|
8
|
+
import { timestampFromDate, timestampNow } from "@bufbuild/protobuf/wkt";
|
|
9
|
+
async function main() {
|
|
10
|
+
dotenv.config();
|
|
11
|
+
const privateKeyHex = process.env.PROVIDER_PRIVATE_KEY;
|
|
12
|
+
const endpoint = process.env.TZERO_ENDPOINT || DEFAULT_ENDPOINT;
|
|
13
|
+
const networkClient = createClient(privateKeyHex, endpoint, NetworkService);
|
|
14
|
+
const toProtoDecimal = (unscaled, exponent) => {
|
|
15
|
+
return create(DecimalSchema, {
|
|
16
|
+
unscaled: BigInt(unscaled),
|
|
17
|
+
exponent: exponent,
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
// Update the quote
|
|
21
|
+
const updateResponse = await networkClient.updateQuote({
|
|
22
|
+
payIn: [{
|
|
23
|
+
bands: [{
|
|
24
|
+
rate: toProtoDecimal(123, 2), // Example rate
|
|
25
|
+
maxAmount: toProtoDecimal(1000, 0), // Example maximum amount
|
|
26
|
+
clientQuoteId: randomUUID(),
|
|
27
|
+
}],
|
|
28
|
+
currency: 'USD', // Example currency
|
|
29
|
+
expiration: timestampFromDate(new Date(Date.now() + 60 * 1000)), // Example expiration time (1 minute from now)
|
|
30
|
+
quoteType: QuoteType.REALTIME, // Example quote type
|
|
31
|
+
paymentMethod: PaymentMethodType.CARD,
|
|
32
|
+
timestamp: timestampNow(), // Current timestamp
|
|
33
|
+
}]
|
|
34
|
+
});
|
|
35
|
+
console.log('Update Quote Response:', updateResponse);
|
|
36
|
+
}
|
|
37
|
+
void main();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./client/client.js";
|
|
2
|
+
export * from "./service/service.js";
|
|
3
|
+
export * from "./service/node.js";
|
|
4
|
+
export { connectNodeAdapter as nodeAdapter } from "@connectrpc/connect-node";
|
|
5
|
+
export type { HandlerContext } from "@connectrpc/connect";
|
|
6
|
+
export * from './common/gen/tzero/v1/common/common_pb.js';
|
|
7
|
+
export * from './common/gen/tzero/v1/common/payment_method_pb.js';
|
|
8
|
+
export * from './common/gen/tzero/v1/payment/provider_pb.js';
|
|
9
|
+
export * from './common/gen/tzero/v1/payment/network_pb.js';
|
|
10
|
+
export * as PaymentIntentProvider from './common/gen/tzero/v1/payment_intent/provider/provider_pb.js';
|
|
11
|
+
export * as PaymentIntentRecipient from './common/gen/tzero/v1/payment_intent/recipient/recipient_pb.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../common/gen/tzero/v1/payment_intent/provider/provider_pb.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../common/gen/tzero/v1/payment_intent/recipient/recipient_pb.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConnectRouter } from "@connectrpc/connect";
|
|
2
|
+
import type { Interceptor } from "@connectrpc/connect";
|
|
3
|
+
import type { DescService } from "@bufbuild/protobuf";
|
|
4
|
+
import type { ServiceImpl } from "@connectrpc/connect";
|
|
5
|
+
export declare const REQUEST_VALIDITY_MILLIS = 60000;
|
|
6
|
+
interface Router {
|
|
7
|
+
service: <T extends DescService>(service: T, implementation: Partial<ServiceImpl<T>>) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const createService: (networkPublicKey: string | Buffer, registerRoutes: (router: Router) => void) => {
|
|
10
|
+
routes: (router: ConnectRouter) => void;
|
|
11
|
+
interceptors: Interceptor[];
|
|
12
|
+
grpcWeb: boolean;
|
|
13
|
+
contextValues: (req: any) => import("@connectrpc/connect").ContextValues;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Code, ConnectError, createContextKey, createContextValues } from "@connectrpc/connect";
|
|
2
2
|
import NetworkHeaders from "../common/headers.js";
|
|
3
3
|
import * as secp from '@noble/secp256k1';
|
|
4
|
-
export const REQUEST_VALIDITY_MILLIS =
|
|
4
|
+
export const REQUEST_VALIDITY_MILLIS = 60000;
|
|
5
5
|
const createSignatureVerification = (networkPublicKey) => (next) => async (req) => {
|
|
6
6
|
const ts = decodeNum(getHeader(req, NetworkHeaders.SignatureTimestamp));
|
|
7
|
-
if (Date.now() - ts >
|
|
7
|
+
if (Date.now() - ts > 60000) {
|
|
8
8
|
throw new ConnectError(`${NetworkHeaders.SignatureTimestamp} must be within ${REQUEST_VALIDITY_MILLIS} milliseconds from now`, Code.InvalidArgument);
|
|
9
9
|
}
|
|
10
10
|
const publicKey = decodeHex(getHeader(req, NetworkHeaders.PublicKey));
|