Skip to content

Commit

Permalink
improve payment flow. (#232)
Browse files Browse the repository at this point in the history
make expiration similar to proposal for now.
  • Loading branch information
vmidyllic authored May 15, 2024
1 parent e31fa28 commit 83fae42
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/iden3comm/types/protocol/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export type PaymentRequestInfo = {
}[];
type: PaymentRequestType;
data: PaymentRequestDataInfo;
expiration: number;
description: string;
expiration?: string;
description?: string;
};

/** @beta PaymentRequestDataInfo is struct the represents payment data info for payment-request */
Expand All @@ -31,6 +31,7 @@ export type PaymentRequestDataInfo = {
id: number;
chainId: number;
address: string;
currency: string;
signature?: string;
};

Expand Down
15 changes: 12 additions & 3 deletions src/verifiable/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export enum RefreshServiceType {

/**
* PaymentRequestType type for payment requests
*
* @beta
* @enum {string}
*/
export enum PaymentRequestType {
Expand All @@ -122,7 +122,7 @@ export enum PaymentRequestType {

/**
* PaymentRequestDataType type for payment requests
*
* @beta
* @enum {string}
*/
export enum PaymentRequestDataType {
Expand All @@ -131,9 +131,18 @@ export enum PaymentRequestDataType {

/**
* PaymentType type for payment responses
*
* @beta
* @enum {string}
*/
export enum PaymentType {
Iden3PaymentCryptoV1 = 'Iden3PaymentCryptoV1'
}

/**
* Media types for Payment supported currencies
* @beta
* @enum {number}
*/
export enum SupportedCurrencies {
ETH = 'ETH'
}
15 changes: 10 additions & 5 deletions tests/handlers/payment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
byteEncoder,
PaymentType,
BasicMessage,
createProposal
createProposal,
SupportedCurrencies
} from '../../src';

import {
Expand Down Expand Up @@ -102,7 +103,10 @@ describe('payment-request handler', () => {
const rpcProvider = new JsonRpcProvider(RPC_URL);
const ethSigner = new ethers.Wallet(WALLET_KEY, rpcProvider);
const payContract = new Contract(data.address, payContractAbi, ethSigner);
const options = { value: data.amount };
if (data.currency !== SupportedCurrencies.ETH) {
throw new Error('integration can only pay in eth currency');
}
const options = { value: ethers.formatUnits(data.amount, 'ether') };
const txData = await payContract.pay(sessionId, did, options);
return txData.hash;
};
Expand All @@ -128,12 +132,13 @@ describe('payment-request handler', () => {
type: PaymentRequestType.PaymentRequest,
data: {
type: PaymentRequestDataType.Iden3PaymentRequestCryptoV1,
amount: '1000000000000000',
amount: '0.1',
id: 12432,
chainId: 80002,
address: '0x2C2007d72f533FfD409F0D9f515983e95bF14992'
address: '0x2C2007d72f533FfD409F0D9f515983e95bF14992',
currency: 'eth'
},
expiration: 2125558127,
expiration: '2125558127',
description: 'payment-request integration test'
};

Expand Down

0 comments on commit 83fae42

Please sign in to comment.