summaryrefslogtreecommitdiff
path: root/src/operations/pay.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-07-20 17:46:49 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-07-20 17:46:49 +0530
commitdd2efc3d78f2dfda44f8182f9638723dcb839781 (patch)
tree9cfbd31607f044fb80da80d8f740ae5eaa21a2f4 /src/operations/pay.ts
parent5a8931d90320ebc8454969ea133c48b6998ad60a (diff)
downloadwallet-core-dd2efc3d78f2dfda44f8182f9638723dcb839781.tar.gz
wallet-core-dd2efc3d78f2dfda44f8182f9638723dcb839781.tar.bz2
wallet-core-dd2efc3d78f2dfda44f8182f9638723dcb839781.zip
nicer HTTP helper in preparation for better error handling
Diffstat (limited to 'src/operations/pay.ts')
-rw-r--r--src/operations/pay.ts43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/operations/pay.ts b/src/operations/pay.ts
index a16190743..abcb2ad1d 100644
--- a/src/operations/pay.ts
+++ b/src/operations/pay.ts
@@ -52,12 +52,13 @@ import {
import * as Amounts from "../util/amounts";
import { AmountJson } from "../util/amounts";
import { Logger } from "../util/logging";
-import { getOrderDownloadUrl, parsePayUri } from "../util/taleruri";
+import { parsePayUri } from "../util/taleruri";
import { guardOperationException } from "./errors";
import { createRefreshGroup, getTotalRefreshCost } from "./refresh";
import { InternalWalletState } from "./state";
import { getTimestampNow, timestampAddDuration } from "../util/time";
import { strcmp, canonicalJson } from "../util/helpers";
+import { httpPostTalerJson } from "../util/http";
/**
* Logger.
@@ -534,7 +535,9 @@ async function incrementProposalRetry(
pr.lastError = err;
await tx.put(Stores.proposals, pr);
});
- ws.notify({ type: NotificationType.ProposalOperationError });
+ if (err) {
+ ws.notify({ type: NotificationType.ProposalOperationError, error: err });
+ }
}
async function incrementPurchasePayRetry(
@@ -600,25 +603,25 @@ async function processDownloadProposalImpl(
return;
}
- const parsedUrl = new URL(
- getOrderDownloadUrl(proposal.merchantBaseUrl, proposal.orderId),
- );
- parsedUrl.searchParams.set("nonce", proposal.noncePub);
- const urlWithNonce = parsedUrl.href;
- console.log("downloading contract from '" + urlWithNonce + "'");
- let resp;
- try {
- resp = await ws.http.get(urlWithNonce);
- } catch (e) {
- console.log("contract download failed", e);
- throw e;
- }
-
- if (resp.status !== 200) {
- throw Error(`contract download failed with status ${resp.status}`);
- }
+ const orderClaimUrl = new URL(
+ `orders/${proposal.orderId}/claim`,
+ proposal.merchantBaseUrl,
+ ).href;
+ logger.trace("downloading contract from '" + orderClaimUrl + "'");
+
+
+ const proposalResp = await httpPostTalerJson({
+ url: orderClaimUrl,
+ body: {
+ nonce: proposal.noncePub,
+ },
+ codec: codecForProposal(),
+ http: ws.http,
+ });
- const proposalResp = codecForProposal().decode(await resp.json());
+ // The proposalResp contains the contract terms as raw JSON,
+ // as the coded to parse them doesn't necessarily round-trip.
+ // We need this raw JSON to compute the contract terms hash.
const contractTermsHash = await ws.cryptoApi.hashString(
canonicalJson(proposalResp.contract_terms),