diff options
-rw-r--r-- | src/operations/pay.ts | 21 | ||||
-rw-r--r-- | src/types/dbTypes.ts | 2 | ||||
-rw-r--r-- | src/util/taleruri-test.ts | 11 | ||||
-rw-r--r-- | src/util/taleruri.ts | 4 | ||||
-rw-r--r-- | tests/test_payments.py | 4 |
5 files changed, 34 insertions, 8 deletions
diff --git a/src/operations/pay.ts b/src/operations/pay.ts index c2877da64..4a8c2144f 100644 --- a/src/operations/pay.ts +++ b/src/operations/pay.ts @@ -603,11 +603,17 @@ async function processDownloadProposalImpl( ).href; logger.trace("downloading contract from '" + orderClaimUrl + "'"); - const reqestBody = { + const requestBody: { + nonce: string, + token?: string; + } = { nonce: proposal.noncePub, }; + if (proposal.claimToken) { + requestBody.token = proposal.claimToken; + } - const resp = await ws.http.postJson(orderClaimUrl, reqestBody); + const resp = await ws.http.postJson(orderClaimUrl, requestBody); const proposalResp = await readSuccessResponseJsonOrThrow( resp, codecForProposal(), @@ -715,6 +721,7 @@ async function startDownloadProposal( merchantBaseUrl: string, orderId: string, sessionId: string | undefined, + claimToken: string | undefined, ): Promise<string> { const oldProposal = await ws.db.getIndexed( Stores.proposals.urlAndOrderIdIndex, @@ -732,6 +739,7 @@ async function startDownloadProposal( download: undefined, noncePriv: priv, noncePub: pub, + claimToken, timestamp: getTimestampNow(), merchantBaseUrl, orderId, @@ -865,7 +873,7 @@ export async function preparePayForUri( `invalid taler://pay URI (${talerPayUri})`, { talerPayUri, - } + }, ); } @@ -874,6 +882,7 @@ export async function preparePayForUri( uriResult.merchantBaseUrl, uriResult.orderId, uriResult.sessionId, + uriResult.claimToken, ); let proposal = await ws.db.get(Stores.proposals, proposalId); @@ -912,7 +921,7 @@ export async function preparePayForUri( const res = await getCoinsForPayment(ws, contractData); if (!res) { - console.log("not confirming payment, insufficient coins"); + logger.info("not confirming payment, insufficient coins"); return { status: PreparePayResultType.InsufficientBalance, contractTerms: d.contractTermsRaw, @@ -957,7 +966,7 @@ export async function preparePayForUri( status: PreparePayResultType.AlreadyConfirmed, contractTerms: purchase.contractTermsRaw, paid: false, - }; + }; } else if (purchase.paymentSubmitPending) { return { status: PreparePayResultType.AlreadyConfirmed, @@ -1020,7 +1029,7 @@ export async function confirmPay( if (!res) { // Should not happen, since checkPay should be called first - console.log("not confirming payment, insufficient coins"); + logger.warn("not confirming payment, insufficient coins"); throw Error("insufficient balance"); } diff --git a/src/types/dbTypes.ts b/src/types/dbTypes.ts index f75d5babe..e03d46417 100644 --- a/src/types/dbTypes.ts +++ b/src/types/dbTypes.ts @@ -873,6 +873,8 @@ export interface ProposalRecord { */ noncePub: string; + claimToken: string | undefined; + proposalStatus: ProposalStatus; repurchaseProposalId: string | undefined; diff --git a/src/util/taleruri-test.ts b/src/util/taleruri-test.ts index 314a981fd..44edbe1c1 100644 --- a/src/util/taleruri-test.ts +++ b/src/util/taleruri-test.ts @@ -63,6 +63,17 @@ test("taler pay url parsing: instance", (t) => { t.is(r1.orderId, "myorder"); }); +test("taler pay url parsing (claim token)", (t) => { + const url1 = "taler://pay/example.com/instances/myinst/myorder/?c=ASDF"; + const r1 = parsePayUri(url1); + if (!r1) { + t.fail(); + return; + } + t.is(r1.merchantBaseUrl, "https://example.com/instances/myinst/"); + t.is(r1.orderId, "myorder"); + t.is(r1.claimToken, "ASDF"); +}); test("taler refund uri parsing: non-https #1", (t) => { const url1 = "taler+http://refund/example.com/myorder"; diff --git a/src/util/taleruri.ts b/src/util/taleruri.ts index fd2cca6ce..c26c4a5db 100644 --- a/src/util/taleruri.ts +++ b/src/util/taleruri.ts @@ -18,6 +18,7 @@ export interface PayUriResult { merchantBaseUrl: string; orderId: string; sessionId: string; + claimToken: string | undefined; } export interface WithdrawUriResult { @@ -136,6 +137,8 @@ export function parsePayUri(s: string): PayUriResult | undefined { return undefined; } const c = pi?.rest.split("?"); + const q = new URLSearchParams(c[1] ?? ""); + const claimToken = q.get("c") ?? undefined; const parts = c[0].split("/"); if (parts.length < 3) { return undefined; @@ -151,6 +154,7 @@ export function parsePayUri(s: string): PayUriResult | undefined { merchantBaseUrl, orderId, sessionId: sessionId, + claimToken, }; } diff --git a/tests/test_payments.py b/tests/test_payments.py index b73d7f791..20cec9295 100644 --- a/tests/test_payments.py +++ b/tests/test_payments.py @@ -7,5 +7,5 @@ def test_payments(exchange, bank, merchant, wallet): pay_uri = merchant.gen_pay_uri("TESTKUDOS:2") # TODO fix - # result = wallet.cmd("preparePay", {"talerPayUri": pay_uri}) - # print_json(result) + result = wallet.cmd("preparePay", {"talerPayUri": pay_uri}) + print_json(result) |