Skip to content

Commit 83fae42

Browse files
authored
improve payment flow. (#232)
make expiration similar to proposal for now.
1 parent e31fa28 commit 83fae42

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

src/iden3comm/types/protocol/payment.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export type PaymentRequestInfo = {
2020
}[];
2121
type: PaymentRequestType;
2222
data: PaymentRequestDataInfo;
23-
expiration: number;
24-
description: string;
23+
expiration?: string;
24+
description?: string;
2525
};
2626

2727
/** @beta PaymentRequestDataInfo is struct the represents payment data info for payment-request */
@@ -31,6 +31,7 @@ export type PaymentRequestDataInfo = {
3131
id: number;
3232
chainId: number;
3333
address: string;
34+
currency: string;
3435
signature?: string;
3536
};
3637

src/verifiable/constants.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export enum RefreshServiceType {
113113

114114
/**
115115
* PaymentRequestType type for payment requests
116-
*
116+
* @beta
117117
* @enum {string}
118118
*/
119119
export enum PaymentRequestType {
@@ -122,7 +122,7 @@ export enum PaymentRequestType {
122122

123123
/**
124124
* PaymentRequestDataType type for payment requests
125-
*
125+
* @beta
126126
* @enum {string}
127127
*/
128128
export enum PaymentRequestDataType {
@@ -131,9 +131,18 @@ export enum PaymentRequestDataType {
131131

132132
/**
133133
* PaymentType type for payment responses
134-
*
134+
* @beta
135135
* @enum {string}
136136
*/
137137
export enum PaymentType {
138138
Iden3PaymentCryptoV1 = 'Iden3PaymentCryptoV1'
139139
}
140+
141+
/**
142+
* Media types for Payment supported currencies
143+
* @beta
144+
* @enum {number}
145+
*/
146+
export enum SupportedCurrencies {
147+
ETH = 'ETH'
148+
}

tests/handlers/payment.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
byteEncoder,
1616
PaymentType,
1717
BasicMessage,
18-
createProposal
18+
createProposal,
19+
SupportedCurrencies
1920
} from '../../src';
2021

2122
import {
@@ -102,7 +103,10 @@ describe('payment-request handler', () => {
102103
const rpcProvider = new JsonRpcProvider(RPC_URL);
103104
const ethSigner = new ethers.Wallet(WALLET_KEY, rpcProvider);
104105
const payContract = new Contract(data.address, payContractAbi, ethSigner);
105-
const options = { value: data.amount };
106+
if (data.currency !== SupportedCurrencies.ETH) {
107+
throw new Error('integration can only pay in eth currency');
108+
}
109+
const options = { value: ethers.formatUnits(data.amount, 'ether') };
106110
const txData = await payContract.pay(sessionId, did, options);
107111
return txData.hash;
108112
};
@@ -128,12 +132,13 @@ describe('payment-request handler', () => {
128132
type: PaymentRequestType.PaymentRequest,
129133
data: {
130134
type: PaymentRequestDataType.Iden3PaymentRequestCryptoV1,
131-
amount: '1000000000000000',
135+
amount: '0.1',
132136
id: 12432,
133137
chainId: 80002,
134-
address: '0x2C2007d72f533FfD409F0D9f515983e95bF14992'
138+
address: '0x2C2007d72f533FfD409F0D9f515983e95bF14992',
139+
currency: 'eth'
135140
},
136-
expiration: 2125558127,
141+
expiration: '2125558127',
137142
description: 'payment-request integration test'
138143
};
139144

0 commit comments

Comments
 (0)