Skip to content

Commit

Permalink
change type of payments id field (#234)
Browse files Browse the repository at this point in the history
* change type of payments id field

* make body required
  • Loading branch information
volodymyr-basiuk authored May 17, 2024
1 parent 3a9d6ef commit 2079eb3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0xpolygonid/js-sdk",
"version": "1.14.0",
"version": "1.14.1",
"description": "SDK to work with Polygon ID",
"main": "dist/node/cjs/index.js",
"module": "dist/node/esm/index.js",
Expand Down
8 changes: 4 additions & 4 deletions src/iden3comm/handlers/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class PaymentHandler
throw new Error(`failed request. empty 'from' field`);
}

if (!paymentRequest.body?.payments?.length) {
if (!paymentRequest.body.payments?.length) {
throw new Error(`failed request. no 'payments' in body`);
}

Expand Down Expand Up @@ -285,13 +285,13 @@ export class PaymentHandler
);
}

if (!payment.body?.payments.length) {
if (!payment.body.payments.length) {
throw new Error(`failed request. empty 'payments' field in body`);
}

for (let i = 0; i < payment.body.payments.length; i++) {
const p = payment.body?.payments[i];
const paymentRequestData = opts.paymentRequest.body?.payments.find((r) => r.data.id === p.id);
const p = payment.body.payments[i];
const paymentRequestData = opts.paymentRequest.body.payments.find((r) => r.data.id === p.id);
if (!paymentRequestData) {
throw new Error(`can't find payment request for payment id ${p.id}`);
}
Expand Down
10 changes: 5 additions & 5 deletions src/iden3comm/types/protocol/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PaymentRequestDataType, PaymentRequestType, PaymentType } from '../../.

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

/** @beta PaymentRequestMessageBody is struct the represents body for payment-request */
Expand All @@ -28,16 +28,16 @@ export type PaymentRequestInfo = {
export type PaymentRequestDataInfo = {
type: PaymentRequestDataType;
amount: string;
id: number;
chainId: number;
id: string;
chainId: string;
address: string;
currency: string;
signature?: string;
};

/** @beta PaymentMessage is struct the represents payment message */
export type PaymentMessage = BasicMessage & {
body?: PaymentMessageBody;
body: PaymentMessageBody;
};

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

/** @beta PaymentInfo is struct the represents payment info for payment */
export type PaymentInfo = {
id: number;
id: string;
type: PaymentType;
paymentData: {
txId: string;
Expand Down
8 changes: 4 additions & 4 deletions tests/handlers/payment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ describe('payment-request handler', () => {
data: {
type: PaymentRequestDataType.Iden3PaymentRequestCryptoV1,
amount: '0.001',
id: 12432,
chainId: 80002,
id: '12432',
chainId: '80002',
address: '0x2C2007d72f533FfD409F0D9f515983e95bF14992',
currency: 'ETH'
},
Expand Down Expand Up @@ -232,7 +232,7 @@ describe('payment-request handler', () => {
const paymentRequest = createPaymentRequest(issuerDID, userDID, agent, [paymentReqInfo]);
const payment = createPayment(userDID, issuerDID, [
{
id: paymentRequest.body?.payments[0].data.id || 0,
id: paymentRequest.body.payments[0].data.id,
type: PaymentType.Iden3PaymentCryptoV1,
paymentData: {
txId: '0x312312334'
Expand Down Expand Up @@ -272,7 +272,7 @@ describe('payment-request handler', () => {
const paymentRequest = createPaymentRequest(issuerDID, userDID, agent, [paymentReqInfo]);
const payment = createPayment(userDID, issuerDID, [
{
id: paymentRequest.body?.payments[0].data.id || 0,
id: paymentRequest.body.payments[0].data.id,
type: PaymentType.Iden3PaymentCryptoV1,
paymentData: {
txId: '0xe9bea8e7adfe1092a8a4ca2cd75f4d21cc54b9b7a31bd8374b558d11b58a6a1a'
Expand Down

0 comments on commit 2079eb3

Please sign in to comment.