diff options
author | Florian Dold <florian@dold.me> | 2023-06-02 15:53:46 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-06-02 15:53:46 +0200 |
commit | 1ee9ef80bddcc91a8e542ffc44cd23e056e751d4 (patch) | |
tree | bc4f20b4adc699076c9efdaac8fd5791886c7a03 /packages/taler-wallet-core/src/operations/pay-merchant.ts | |
parent | 2f4f43cc1f5acb37fce00318db1507b407332324 (diff) | |
download | wallet-core-1ee9ef80bddcc91a8e542ffc44cd23e056e751d4.tar.xz |
wallet-core: fix tipping state machine issues
Diffstat (limited to 'packages/taler-wallet-core/src/operations/pay-merchant.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/pay-merchant.ts | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/packages/taler-wallet-core/src/operations/pay-merchant.ts b/packages/taler-wallet-core/src/operations/pay-merchant.ts index dce2a30ed..0097f5bcc 100644 --- a/packages/taler-wallet-core/src/operations/pay-merchant.ts +++ b/packages/taler-wallet-core/src/operations/pay-merchant.ts @@ -532,21 +532,23 @@ async function processDownloadProposal( h: contractTermsHash, contractTermsRaw: proposalResp.contract_terms, }); - if ( + const isResourceFulfillmentUrl = fulfillmentUrl && (fulfillmentUrl.startsWith("http://") || - fulfillmentUrl.startsWith("https://")) - ) { - const differentPurchase = - await tx.purchases.indexes.byFulfillmentUrl.get(fulfillmentUrl); - // FIXME: Adjust this to account for refunds, don't count as repurchase - // if original order is refunded. - if (differentPurchase) { - logger.warn("repurchase detected"); - p.purchaseStatus = PurchaseStatus.RepurchaseDetected; - p.repurchaseProposalId = differentPurchase.proposalId; - await tx.purchases.put(p); - } + fulfillmentUrl.startsWith("https://")); + let otherPurchase: PurchaseRecord | undefined; + if (isResourceFulfillmentUrl) { + otherPurchase = await tx.purchases.indexes.byFulfillmentUrl.get( + fulfillmentUrl, + ); + } + // FIXME: Adjust this to account for refunds, don't count as repurchase + // if original order is refunded. + if (otherPurchase) { + logger.warn("repurchase detected"); + p.purchaseStatus = PurchaseStatus.RepurchaseDetected; + p.repurchaseProposalId = otherPurchase.proposalId; + await tx.purchases.put(p); } else { p.purchaseStatus = PurchaseStatus.DialogProposed; await tx.purchases.put(p); @@ -602,6 +604,7 @@ async function createPurchase( (!noncePriv || oldProposal.noncePriv === noncePriv) && oldProposal.claimToken === claimToken ) { + // FIXME: This lacks proper error handling await processDownloadProposal(ws, oldProposal.proposalId); return oldProposal.proposalId; } |