From 5c742afbdf9aaa767c3e4617c48a98439e400fa2 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 8 Nov 2022 13:00:34 -0300 Subject: feature: 7440 add expiration to p2p --- packages/taler-util/src/payto.ts | 11 +++--- packages/taler-util/src/taler-types.ts | 11 ++++-- packages/taler-util/src/types-test.ts | 2 +- packages/taler-util/src/wallet-types.ts | 59 +++++++++++++++++++++++++-------- 4 files changed, 61 insertions(+), 22 deletions(-) (limited to 'packages/taler-util/src') diff --git a/packages/taler-util/src/payto.ts b/packages/taler-util/src/payto.ts index 3073b991c..8eb0b88a8 100644 --- a/packages/taler-util/src/payto.ts +++ b/packages/taler-util/src/payto.ts @@ -139,12 +139,13 @@ export function parsePaytoUri(s: string): PaytoUri | undefined { let iban: string | undefined = undefined; let bic: string | undefined = undefined; if (parts.length === 1) { - iban = parts[0] - } if (parts.length === 2) { - bic = parts[0] - iban = parts[1] + iban = parts[0]; + } + if (parts.length === 2) { + bic = parts[0]; + iban = parts[1]; } else { - iban = targetPath + iban = targetPath; } return { isKnown: true, diff --git a/packages/taler-util/src/taler-types.ts b/packages/taler-util/src/taler-types.ts index d4f96f5cd..292ace94b 100644 --- a/packages/taler-util/src/taler-types.ts +++ b/packages/taler-util/src/taler-types.ts @@ -1297,7 +1297,7 @@ export const codecForProduct = (): Codec => .property("price", codecOptional(codecForString())) .build("Tax"); -export const codecForContractTerms = (): Codec => +export const codecForMerchantContractTerms = (): Codec => buildCodecForObject() .property("order_id", codecForString()) .property("fulfillment_url", codecOptional(codecForString())) @@ -1329,7 +1329,14 @@ export const codecForContractTerms = (): Codec => .property("products", codecOptional(codecForList(codecForProduct()))) .property("extra", codecForAny()) .property("minimum_age", codecOptional(codecForNumber())) - .build("ContractTerms"); + .build("MerchantContractTerms"); + +export const codecForPeerContractTerms = (): Codec => + buildCodecForObject() + .property("summary", codecForString()) + .property("amount", codecForString()) + .property("purse_expiration", codecForTimestamp) + .build("PeerContractTerms"); export const codecForMerchantRefundPermission = (): Codec => diff --git a/packages/taler-util/src/types-test.ts b/packages/taler-util/src/types-test.ts index 2915106c2..6acd2c26e 100644 --- a/packages/taler-util/src/types-test.ts +++ b/packages/taler-util/src/types-test.ts @@ -15,7 +15,7 @@ */ import test from "ava"; -import { codecForContractTerms } from "./taler-types.js"; +import { codecForMerchantContractTerms as codecForContractTerms } from "./taler-types.js"; test("contract terms validation", (t) => { const c = { diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index daeac73fd..4e1563e27 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -53,13 +53,15 @@ import { TalerErrorCode } from "./taler-error-codes.js"; import { AmountString, AuditorDenomSig, - codecForContractTerms, + codecForMerchantContractTerms, CoinEnvelope, MerchantContractTerms, + PeerContractTerms, DenominationPubKey, DenomKeyType, ExchangeAuditor, UnblindedSignature, + codecForPeerContractTerms, } from "./taler-types.js"; import { AbsoluteTime, @@ -253,7 +255,7 @@ export const codecForConfirmPayResultDone = (): Codec => buildCodecForObject() .property("type", codecForConstString(ConfirmPayResultType.Done)) .property("transactionId", codecForString()) - .property("contractTerms", codecForContractTerms()) + .property("contractTerms", codecForMerchantContractTerms()) .build("ConfirmPayResultDone"); export const codecForConfirmPayResult = (): Codec => @@ -383,7 +385,7 @@ export const codecForPreparePayResultPaymentPossible = buildCodecForObject() .property("amountEffective", codecForAmountString()) .property("amountRaw", codecForAmountString()) - .property("contractTerms", codecForContractTerms()) + .property("contractTerms", codecForMerchantContractTerms()) .property("proposalId", codecForString()) .property("contractTermsHash", codecForString()) .property("noncePriv", codecForString()) @@ -1738,9 +1740,26 @@ export interface PayCoinSelection { customerDepositFees: AmountString; } -export interface InitiatePeerPushPaymentRequest { +export interface PreparePeerPushPaymentRequest { + exchangeBaseUrl?: string; amount: AmountString; - partialContractTerms: any; +} + +export const codecForPreparePeerPushPaymentRequest = + (): Codec => + buildCodecForObject() + .property("exchangeBaseUrl", codecOptional(codecForString())) + .property("amount", codecForAmountString()) + .build("InitiatePeerPushPaymentRequest"); + +export interface PreparePeerPushPaymentResponse { + amountRaw: AmountString; + amountEffective: AmountString; +} + +export interface InitiatePeerPushPaymentRequest { + exchangeBaseUrl?: string; + partialContractTerms: PeerContractTerms; } export interface InitiatePeerPushPaymentResponse { @@ -1755,8 +1774,7 @@ export interface InitiatePeerPushPaymentResponse { export const codecForInitiatePeerPushPaymentRequest = (): Codec => buildCodecForObject() - .property("amount", codecForAmountString()) - .property("partialContractTerms", codecForAny()) + .property("partialContractTerms", codecForPeerContractTerms()) .build("InitiatePeerPushPaymentRequest"); export interface CheckPeerPushPaymentRequest { @@ -1768,13 +1786,13 @@ export interface CheckPeerPullPaymentRequest { } export interface CheckPeerPushPaymentResponse { - contractTerms: any; + contractTerms: PeerContractTerms; amount: AmountString; peerPushPaymentIncomingId: string; } export interface CheckPeerPullPaymentResponse { - contractTerms: any; + contractTerms: PeerContractTerms; amount: AmountString; peerPullPaymentIncomingId: string; } @@ -1843,21 +1861,34 @@ export const codecForAcceptPeerPullPaymentRequest = .property("peerPullPaymentIncomingId", codecForString()) .build("AcceptPeerPllPaymentRequest"); +export interface PreparePeerPullPaymentRequest { + exchangeBaseUrl: string; + amount: AmountString; +} +export const codecForPreparePeerPullPaymentRequest = + (): Codec => + buildCodecForObject() + .property("amount", codecForAmountString()) + .property("exchangeBaseUrl", codecForString()) + .build("PreparePeerPullPaymentRequest"); + +export interface PreparePeerPullPaymentResponse { + amountRaw: AmountString; + amountEffective: AmountString; +} export interface InitiatePeerPullPaymentRequest { /** * FIXME: Make this optional? */ exchangeBaseUrl: string; - amount: AmountString; - partialContractTerms: any; + partialContractTerms: PeerContractTerms; } export const codecForInitiatePeerPullPaymentRequest = (): Codec => buildCodecForObject() - .property("partialContractTerms", codecForAny()) - .property("amount", codecForAmountString()) - .property("exchangeBaseUrl", codecForAmountString()) + .property("partialContractTerms", codecForPeerContractTerms()) + .property("exchangeBaseUrl", codecForString()) .build("InitiatePeerPullPaymentRequest"); export interface InitiatePeerPullPaymentResponse { -- cgit v1.2.3