summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/pay.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-03-10 17:11:59 +0100
committerFlorian Dold <florian@dold.me>2021-03-10 17:11:59 +0100
commit1392dc47c6489fca1b3a4c036852873495190c36 (patch)
treeb8b76bff34b7425de602651fec3d86463e4c7599 /packages/taler-wallet-core/src/operations/pay.ts
parentac89c3d277134e49e44d8b0afd4930fd4df934aa (diff)
downloadwallet-core-1392dc47c6489fca1b3a4c036852873495190c36.tar.gz
wallet-core-1392dc47c6489fca1b3a4c036852873495190c36.tar.bz2
wallet-core-1392dc47c6489fca1b3a4c036852873495190c36.zip
finish first complete end-to-end backup/sync test
Diffstat (limited to 'packages/taler-wallet-core/src/operations/pay.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/pay.ts68
1 files changed, 38 insertions, 30 deletions
diff --git a/packages/taler-wallet-core/src/operations/pay.ts b/packages/taler-wallet-core/src/operations/pay.ts
index cccbb3cac..03bf9e119 100644
--- a/packages/taler-wallet-core/src/operations/pay.ts
+++ b/packages/taler-wallet-core/src/operations/pay.ts
@@ -1150,36 +1150,11 @@ async function submitPay(
};
}
-/**
- * Check if a payment for the given taler://pay/ URI is possible.
- *
- * If the payment is possible, the signature are already generated but not
- * yet send to the merchant.
- */
-export async function preparePayForUri(
+export async function checkPaymentByProposalId(
ws: InternalWalletState,
- talerPayUri: string,
+ proposalId: string,
+ sessionId?: string,
): Promise<PreparePayResult> {
- const uriResult = parsePayUri(talerPayUri);
-
- if (!uriResult) {
- throw OperationFailedError.fromCode(
- TalerErrorCode.WALLET_INVALID_TALER_PAY_URI,
- `invalid taler://pay URI (${talerPayUri})`,
- {
- talerPayUri,
- },
- );
- }
-
- let proposalId = await startDownloadProposal(
- ws,
- uriResult.merchantBaseUrl,
- uriResult.orderId,
- uriResult.sessionId,
- uriResult.claimToken,
- );
-
let proposal = await ws.db.get(Stores.proposals, proposalId);
if (!proposal) {
throw Error(`could not get proposal ${proposalId}`);
@@ -1238,7 +1213,7 @@ export async function preparePayForUri(
};
}
- if (purchase.lastSessionId !== uriResult.sessionId) {
+ if (purchase.lastSessionId !== sessionId) {
logger.trace(
"automatically re-submitting payment with different session ID",
);
@@ -1247,7 +1222,7 @@ export async function preparePayForUri(
if (!p) {
return;
}
- p.lastSessionId = uriResult.sessionId;
+ p.lastSessionId = sessionId;
await tx.put(Stores.purchases, p);
});
const r = await guardOperationException(
@@ -1293,6 +1268,39 @@ export async function preparePayForUri(
}
/**
+ * Check if a payment for the given taler://pay/ URI is possible.
+ *
+ * If the payment is possible, the signature are already generated but not
+ * yet send to the merchant.
+ */
+export async function preparePayForUri(
+ ws: InternalWalletState,
+ talerPayUri: string,
+): Promise<PreparePayResult> {
+ const uriResult = parsePayUri(talerPayUri);
+
+ if (!uriResult) {
+ throw OperationFailedError.fromCode(
+ TalerErrorCode.WALLET_INVALID_TALER_PAY_URI,
+ `invalid taler://pay URI (${talerPayUri})`,
+ {
+ talerPayUri,
+ },
+ );
+ }
+
+ let proposalId = await startDownloadProposal(
+ ws,
+ uriResult.merchantBaseUrl,
+ uriResult.orderId,
+ uriResult.sessionId,
+ uriResult.claimToken,
+ );
+
+ return checkPaymentByProposalId(ws, proposalId, uriResult.sessionId);
+}
+
+/**
* Generate deposit permissions for a purchase.
*
* Accesses the database and the crypto worker.