Skip to content

Commit 2079eb3

Browse files
change type of payments id field (#234)
* change type of payments id field * make body required
1 parent 3a9d6ef commit 2079eb3

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@0xpolygonid/js-sdk",
3-
"version": "1.14.0",
3+
"version": "1.14.1",
44
"description": "SDK to work with Polygon ID",
55
"main": "dist/node/cjs/index.js",
66
"module": "dist/node/esm/index.js",

src/iden3comm/handlers/payment.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export class PaymentHandler
191191
throw new Error(`failed request. empty 'from' field`);
192192
}
193193

194-
if (!paymentRequest.body?.payments?.length) {
194+
if (!paymentRequest.body.payments?.length) {
195195
throw new Error(`failed request. no 'payments' in body`);
196196
}
197197

@@ -285,13 +285,13 @@ export class PaymentHandler
285285
);
286286
}
287287

288-
if (!payment.body?.payments.length) {
288+
if (!payment.body.payments.length) {
289289
throw new Error(`failed request. empty 'payments' field in body`);
290290
}
291291

292292
for (let i = 0; i < payment.body.payments.length; i++) {
293-
const p = payment.body?.payments[i];
294-
const paymentRequestData = opts.paymentRequest.body?.payments.find((r) => r.data.id === p.id);
293+
const p = payment.body.payments[i];
294+
const paymentRequestData = opts.paymentRequest.body.payments.find((r) => r.data.id === p.id);
295295
if (!paymentRequestData) {
296296
throw new Error(`can't find payment request for payment id ${p.id}`);
297297
}

src/iden3comm/types/protocol/payment.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { PaymentRequestDataType, PaymentRequestType, PaymentType } from '../../.
33

44
/** @beta PaymentRequestMessage is struct the represents payment-request message */
55
export type PaymentRequestMessage = BasicMessage & {
6-
body?: PaymentRequestMessageBody;
6+
body: PaymentRequestMessageBody;
77
};
88

99
/** @beta PaymentRequestMessageBody is struct the represents body for payment-request */
@@ -28,16 +28,16 @@ export type PaymentRequestInfo = {
2828
export type PaymentRequestDataInfo = {
2929
type: PaymentRequestDataType;
3030
amount: string;
31-
id: number;
32-
chainId: number;
31+
id: string;
32+
chainId: string;
3333
address: string;
3434
currency: string;
3535
signature?: string;
3636
};
3737

3838
/** @beta PaymentMessage is struct the represents payment message */
3939
export type PaymentMessage = BasicMessage & {
40-
body?: PaymentMessageBody;
40+
body: PaymentMessageBody;
4141
};
4242

4343
/** @beta PaymentMessageBody is struct the represents body for payment message */
@@ -47,7 +47,7 @@ export type PaymentMessageBody = {
4747

4848
/** @beta PaymentInfo is struct the represents payment info for payment */
4949
export type PaymentInfo = {
50-
id: number;
50+
id: string;
5151
type: PaymentType;
5252
paymentData: {
5353
txId: string;

tests/handlers/payment.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ describe('payment-request handler', () => {
133133
data: {
134134
type: PaymentRequestDataType.Iden3PaymentRequestCryptoV1,
135135
amount: '0.001',
136-
id: 12432,
137-
chainId: 80002,
136+
id: '12432',
137+
chainId: '80002',
138138
address: '0x2C2007d72f533FfD409F0D9f515983e95bF14992',
139139
currency: 'ETH'
140140
},
@@ -232,7 +232,7 @@ describe('payment-request handler', () => {
232232
const paymentRequest = createPaymentRequest(issuerDID, userDID, agent, [paymentReqInfo]);
233233
const payment = createPayment(userDID, issuerDID, [
234234
{
235-
id: paymentRequest.body?.payments[0].data.id || 0,
235+
id: paymentRequest.body.payments[0].data.id,
236236
type: PaymentType.Iden3PaymentCryptoV1,
237237
paymentData: {
238238
txId: '0x312312334'
@@ -272,7 +272,7 @@ describe('payment-request handler', () => {
272272
const paymentRequest = createPaymentRequest(issuerDID, userDID, agent, [paymentReqInfo]);
273273
const payment = createPayment(userDID, issuerDID, [
274274
{
275-
id: paymentRequest.body?.payments[0].data.id || 0,
275+
id: paymentRequest.body.payments[0].data.id,
276276
type: PaymentType.Iden3PaymentCryptoV1,
277277
paymentData: {
278278
txId: '0xe9bea8e7adfe1092a8a4ca2cd75f4d21cc54b9b7a31bd8374b558d11b58a6a1a'

0 commit comments

Comments
 (0)