summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/transactions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/operations/transactions.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/transactions.ts146
1 files changed, 78 insertions, 68 deletions
diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts
index a89557c1d..551e495dc 100644
--- a/packages/taler-wallet-core/src/operations/transactions.ts
+++ b/packages/taler-wallet-core/src/operations/transactions.ts
@@ -31,6 +31,8 @@ import {
PeerContractTerms,
RefundInfoShort,
RefundPaymentInfo,
+ stringifyPayPullUri,
+ stringifyPayPushUri,
TalerErrorCode,
TalerProtocolTimestamp,
Transaction,
@@ -94,8 +96,17 @@ import {
extractContractData,
processPurchasePay,
} from "./pay-merchant.js";
-import { computePeerPullCreditTransactionState, computePeerPullDebitTransactionState, computePeerPushCreditTransactionState, computePeerPushDebitTransactionState, processPeerPullCredit } from "./pay-peer.js";
-import { computeRefreshTransactionState, processRefreshGroup } from "./refresh.js";
+import {
+ computePeerPullCreditTransactionState,
+ computePeerPullDebitTransactionState,
+ computePeerPushCreditTransactionState,
+ computePeerPushDebitTransactionState,
+ processPeerPullCredit,
+} from "./pay-peer.js";
+import {
+ computeRefreshTransactionState,
+ processRefreshGroup,
+} from "./refresh.js";
import { computeTipTransactionStatus, processTip } from "./tip.js";
import {
abortWithdrawalTransaction,
@@ -378,14 +389,14 @@ function buildTransactionForPushPaymentDebit(
: ExtendedStatus.Done,
pending: pi.status != PeerPushPaymentInitiationStatus.Done,
timestamp: pi.timestampCreated,
- talerUri: constructPayPushUri({
+ talerUri: stringifyPayPushUri({
exchangeBaseUrl: pi.exchangeBaseUrl,
contractPriv: pi.contractPriv,
}),
- transactionId: makeTransactionId(
- TransactionType.PeerPushDebit,
- pi.pursePub,
- ),
+ transactionId: constructTransactionIdentifier({
+ tag: TransactionType.PeerPushDebit,
+ pursePub: pi.pursePub,
+ }),
...(ort?.lastError ? { error: ort.lastError } : {}),
};
}
@@ -410,10 +421,10 @@ function buildTransactionForPullPaymentDebit(
summary: pi.contractTerms.summary,
},
timestamp: pi.timestampCreated,
- transactionId: makeTransactionId(
- TransactionType.PeerPullDebit,
- pi.peerPullPaymentIncomingId,
- ),
+ transactionId: constructTransactionIdentifier({
+ tag: TransactionType.PeerPullDebit,
+ peerPullPaymentIncomingId: pi.peerPullPaymentIncomingId,
+ }),
...(ort?.lastError ? { error: ort.lastError } : {}),
};
}
@@ -460,14 +471,14 @@ function buildTransactionForPeerPullCredit(
expiration: wsr.wgInfo.contractTerms.purse_expiration,
summary: wsr.wgInfo.contractTerms.summary,
},
- talerUri: constructPayPullUri({
+ talerUri: stringifyPayPullUri({
exchangeBaseUrl: wsr.exchangeBaseUrl,
contractPriv: wsr.wgInfo.contractPriv,
}),
- transactionId: makeTransactionId(
- TransactionType.PeerPullCredit,
- pullCredit.pursePub,
- ),
+ transactionId: constructTransactionIdentifier({
+ tag: TransactionType.PeerPullCredit,
+ pursePub: pullCredit.pursePub,
+ }),
frozen: false,
...(wsrOrt?.lastError
? {
@@ -493,14 +504,14 @@ function buildTransactionForPeerPullCredit(
expiration: peerContractTerms.purse_expiration,
summary: peerContractTerms.summary,
},
- talerUri: constructPayPullUri({
+ talerUri: stringifyPayPullUri({
exchangeBaseUrl: pullCredit.exchangeBaseUrl,
contractPriv: pullCredit.contractPriv,
}),
- transactionId: makeTransactionId(
- TransactionType.PeerPullCredit,
- pullCredit.pursePub,
- ),
+ transactionId: constructTransactionIdentifier({
+ tag: TransactionType.PeerPullCredit,
+ pursePub: pullCredit.pursePub,
+ }),
frozen: false,
...(pullCreditOrt?.lastError ? { error: pullCreditOrt.lastError } : {}),
};
@@ -533,10 +544,10 @@ function buildTransactionForPeerPushCredit(
: ExtendedStatus.Pending,
pending: !wsr.timestampFinish,
timestamp: wsr.timestampStart,
- transactionId: makeTransactionId(
- TransactionType.PeerPushCredit,
- pushInc.peerPushPaymentIncomingId,
- ),
+ transactionId: constructTransactionIdentifier({
+ tag: TransactionType.PeerPushCredit,
+ peerPushPaymentIncomingId: pushInc.peerPushPaymentIncomingId,
+ }),
frozen: false,
...(wsrOrt?.lastError ? { error: wsrOrt.lastError } : {}),
};
@@ -556,10 +567,10 @@ function buildTransactionForPeerPushCredit(
extendedStatus: ExtendedStatus.Pending,
pending: true,
timestamp: pushInc.timestamp,
- transactionId: makeTransactionId(
- TransactionType.PeerPushCredit,
- pushInc.peerPushPaymentIncomingId,
- ),
+ transactionId: constructTransactionIdentifier({
+ tag: TransactionType.PeerPushCredit,
+ peerPushPaymentIncomingId: pushInc.peerPushPaymentIncomingId,
+ }),
frozen: false,
...(pushOrt?.lastError ? { error: pushOrt.lastError } : {}),
};
@@ -592,10 +603,10 @@ function buildTransactionForBankIntegratedWithdraw(
: ExtendedStatus.Pending,
pending: !wgRecord.timestampFinish,
timestamp: wgRecord.timestampStart,
- transactionId: makeTransactionId(
- TransactionType.Withdrawal,
- wgRecord.withdrawalGroupId,
- ),
+ transactionId: constructTransactionIdentifier({
+ tag: TransactionType.Withdrawal,
+ withdrawalGroupId: wgRecord.withdrawalGroupId,
+ }),
frozen: false,
...(ort?.lastError ? { error: ort.lastError } : {}),
};
@@ -639,10 +650,10 @@ function buildTransactionForManualWithdraw(
: ExtendedStatus.Pending,
pending: !withdrawalGroup.timestampFinish,
timestamp: withdrawalGroup.timestampStart,
- transactionId: makeTransactionId(
- TransactionType.Withdrawal,
- withdrawalGroup.withdrawalGroupId,
- ),
+ transactionId: constructTransactionIdentifier({
+ tag: TransactionType.Withdrawal,
+ withdrawalGroupId: withdrawalGroup.withdrawalGroupId,
+ }),
frozen: false,
...(ort?.lastError ? { error: ort.lastError } : {}),
};
@@ -668,7 +679,7 @@ function buildTransactionForRefund(
amountRaw: refundRecord.amountRaw,
refundedTransactionId: constructTransactionIdentifier({
tag: TransactionType.Payment,
- proposalId: refundRecord.proposalId
+ proposalId: refundRecord.proposalId,
}),
timestamp: refundRecord.timestampCreated,
transactionId: constructTransactionIdentifier({
@@ -680,7 +691,7 @@ function buildTransactionForRefund(
frozen: false,
pending: false,
paymentInfo,
- }
+ };
}
function buildTransactionForRefresh(
@@ -726,10 +737,10 @@ function buildTransactionForRefresh(
: ExtendedStatus.Pending,
pending: extendedStatus == ExtendedStatus.Pending,
timestamp: refreshGroupRecord.timestampCreated,
- transactionId: makeTransactionId(
- TransactionType.Refresh,
- refreshGroupRecord.refreshGroupId,
- ),
+ transactionId: constructTransactionIdentifier({
+ tag: TransactionType.Refresh,
+ refreshGroupId: refreshGroupRecord.refreshGroupId,
+ }),
frozen: false,
...(ort?.lastError ? { error: ort.lastError } : {}),
};
@@ -759,10 +770,10 @@ function buildTransactionForDeposit(
timestamp: dg.timestampCreated,
targetPaytoUri: dg.wire.payto_uri,
wireTransferDeadline: dg.contractTermsRaw.wire_transfer_deadline,
- transactionId: makeTransactionId(
- TransactionType.Deposit,
- dg.depositGroupId,
- ),
+ transactionId: constructTransactionIdentifier({
+ tag: TransactionType.Deposit,
+ depositGroupId: dg.depositGroupId,
+ }),
wireTransferProgress:
(100 *
dg.transactionPerCoin.reduce(
@@ -794,16 +805,15 @@ function buildTransactionForTip(
pending: !tipRecord.pickedUpTimestamp,
frozen: false,
timestamp: tipRecord.acceptedTimestamp,
- transactionId: makeTransactionId(
- TransactionType.Tip,
- tipRecord.walletTipId,
- ),
+ transactionId: constructTransactionIdentifier({
+ tag: TransactionType.Tip,
+ walletTipId: tipRecord.walletTipId,
+ }),
merchantBaseUrl: tipRecord.merchantBaseUrl,
...(ort?.lastError ? { error: ort.lastError } : {}),
};
}
-
async function buildTransactionForPurchase(
purchaseRecord: PurchaseRecord,
contractData: WalletContractData,
@@ -876,17 +886,17 @@ async function buildTransactionForPurchase(
refunds,
posConfirmation: purchaseRecord.posConfirmation,
timestamp,
- transactionId: makeTransactionId(
- TransactionType.Payment,
- purchaseRecord.proposalId,
- ),
+ transactionId: constructTransactionIdentifier({
+ tag: TransactionType.Payment,
+ proposalId: purchaseRecord.proposalId,
+ }),
proposalId: purchaseRecord.proposalId,
info,
refundQueryActive:
purchaseRecord.purchaseStatus === PurchaseStatus.QueryingRefund,
frozen:
- purchaseRecord.purchaseStatus === PurchaseStatus.AbortedIncompletePayment ??
- false,
+ purchaseRecord.purchaseStatus ===
+ PurchaseStatus.AbortedIncompletePayment ?? false,
...(ort?.lastError ? { error: ort.lastError } : {}),
};
}
@@ -1253,25 +1263,25 @@ export function constructTransactionIdentifier(
): TransactionIdStr {
switch (pTxId.tag) {
case TransactionType.Deposit:
- return `txn:${pTxId.tag}:${pTxId.depositGroupId}`;
+ return `txn:${pTxId.tag}:${pTxId.depositGroupId}` as TransactionIdStr;
case TransactionType.Payment:
- return `txn:${pTxId.tag}:${pTxId.proposalId}`;
+ return `txn:${pTxId.tag}:${pTxId.proposalId}` as TransactionIdStr;
case TransactionType.PeerPullCredit:
- return `txn:${pTxId.tag}:${pTxId.pursePub}`;
+ return `txn:${pTxId.tag}:${pTxId.pursePub}` as TransactionIdStr;
case TransactionType.PeerPullDebit:
- return `txn:${pTxId.tag}:${pTxId.peerPullPaymentIncomingId}`;
+ return `txn:${pTxId.tag}:${pTxId.peerPullPaymentIncomingId}` as TransactionIdStr;
case TransactionType.PeerPushCredit:
- return `txn:${pTxId.tag}:${pTxId.peerPushPaymentIncomingId}`;
+ return `txn:${pTxId.tag}:${pTxId.peerPushPaymentIncomingId}` as TransactionIdStr;
case TransactionType.PeerPushDebit:
- return `txn:${pTxId.tag}:${pTxId.pursePub}`;
+ return `txn:${pTxId.tag}:${pTxId.pursePub}` as TransactionIdStr;
case TransactionType.Refresh:
- return `txn:${pTxId.tag}:${pTxId.refreshGroupId}`;
+ return `txn:${pTxId.tag}:${pTxId.refreshGroupId}` as TransactionIdStr;
case TransactionType.Refund:
- return `txn:${pTxId.tag}:${pTxId.refundGroupId}`;
+ return `txn:${pTxId.tag}:${pTxId.refundGroupId}` as TransactionIdStr;
case TransactionType.Tip:
- return `txn:${pTxId.tag}:${pTxId.walletTipId}`;
+ return `txn:${pTxId.tag}:${pTxId.walletTipId}` as TransactionIdStr;
case TransactionType.Withdrawal:
- return `txn:${pTxId.tag}:${pTxId.withdrawalGroupId}`;
+ return `txn:${pTxId.tag}:${pTxId.withdrawalGroupId}` as TransactionIdStr;
default:
assertUnreachable(pTxId);
}