From bc05121da2178cb1347c6564fb582b7cf82d9cd1 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 18 Dec 2015 13:38:22 +0100 Subject: [PATCH] payment --- extension/background/emscriptif.js | 2 -- extension/background/emscriptif.ts | 2 -- extension/background/wallet.js | 18 +++++++++++++----- extension/background/wallet.ts | 23 +++++++++++++++++------ 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/extension/background/emscriptif.js b/extension/background/emscriptif.js index 3d4868b1e..e9e118ed3 100644 --- a/extension/background/emscriptif.js +++ b/extension/background/emscriptif.js @@ -303,7 +303,6 @@ function mixin(obj, method, name) { if (!name) { throw Error("Mixin needs a name."); } - console.log("mixing in", name, "into", obj.name); obj.prototype[method.name] = method; } function mixinStatic(obj, method, name) { @@ -498,7 +497,6 @@ class AbsoluteTimeNbo extends PackedArenaObject { throw Error(); } let n = parseInt(m[1]); - console.log("setting", n); // XXX: This only works up to 54 bit numbers. set64(x.getNative(), n); return x; diff --git a/extension/background/emscriptif.ts b/extension/background/emscriptif.ts index e44747d21..80e62cccc 100644 --- a/extension/background/emscriptif.ts +++ b/extension/background/emscriptif.ts @@ -466,7 +466,6 @@ function mixin(obj, method, name?: string) { if (!name) { throw Error("Mixin needs a name."); } - console.log("mixing in", name, "into", obj.name); obj.prototype[method.name] = method; } @@ -717,7 +716,6 @@ class AbsoluteTimeNbo extends PackedArenaObject { throw Error(); } let n = parseInt(m[1]); - console.log("setting", n); // XXX: This only works up to 54 bit numbers. set64(x.getNative(), n); return x; diff --git a/extension/background/wallet.js b/extension/background/wallet.js index a24ee372b..6e4438a0d 100644 --- a/extension/background/wallet.js +++ b/extension/background/wallet.js @@ -21,12 +21,19 @@ function signDeposit(db, offer, cds) { cds = copy(cds); for (let cd of cds) { let coinSpend; + console.log("amount remaining:", amountRemaining.toJson()); + if (amountRemaining.value == 0 && amountRemaining.fraction == 0) { + console.log("full amount spent"); + break; + } if (amountRemaining.cmp(new Amount(cd.coin.currentAmount)) < 0) { coinSpend = new Amount(amountRemaining.toJson()); } else { coinSpend = new Amount(cd.coin.currentAmount); } + amountSpent.add(coinSpend); + amountRemaining.sub(coinSpend); let d = new DepositRequestPS({ h_contract: HashCode.fromCrock(offer.H_contract), h_wire: HashCode.fromCrock(offer.contract.H_wire), @@ -38,7 +45,6 @@ function signDeposit(db, offer, cds) { timestamp: AbsoluteTimeNbo.fromTalerString(offer.contract.timestamp), transaction_id: UInt64.fromNumber(offer.contract.transaction_id), }); - amountSpent.add(coinSpend); let newAmount = new Amount(cd.coin.currentAmount); newAmount.sub(coinSpend); cd.coin.currentAmount = newAmount.toJson(); @@ -51,7 +57,7 @@ function signDeposit(db, offer, cds) { denom_pub: cd.coin.denomPub, f: amountSpent.toJson(), }; - ret.push({ sig: coinSig, updatedCoin: cd.coin }); + ret.push({ sig: s, updatedCoin: cd.coin }); } return ret; } @@ -141,10 +147,11 @@ function executePay(db, offer, payCoinInfo, merchantBaseUrl, chosenMint) { reqData["H_contract"] = offer.H_contract; reqData["transaction_id"] = offer.contract.transaction_id; reqData["refund_deadline"] = offer.contract.refund_deadline; - reqData["mint"] = chosenMint; + reqData["mint"] = URI(chosenMint).hostname(); reqData["coins"] = payCoinInfo.map((x) => x.sig); - let payUrl = URI(merchantBaseUrl).absoluteTo(merchantBaseUrl); - console.log("Merchant URL", payUrl); + reqData["timestamp"] = offer.contract.timestamp; + let payUrl = URI(offer.contract.pay_url).absoluteTo(merchantBaseUrl); + console.log("Merchant URL", payUrl.href()); let req = new XMLHttpRequest(); req.open('post', payUrl.href()); req.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); @@ -152,6 +159,7 @@ function executePay(db, offer, payCoinInfo, merchantBaseUrl, chosenMint) { req.addEventListener('readystatechange', (e) => { if (req.readyState == XMLHttpRequest.DONE) { if (req.status == 200) { + console.log("Merchant response:", req.responseText); resolve(); } else { diff --git a/extension/background/wallet.ts b/extension/background/wallet.ts index 9a9971f8d..7fee5490e 100644 --- a/extension/background/wallet.ts +++ b/extension/background/wallet.ts @@ -79,12 +79,23 @@ function signDeposit(db: IDBDatabase, cds = copy(cds); for (let cd of cds) { let coinSpend; + + console.log("amount remaining:", amountRemaining.toJson()); + + if (amountRemaining.value == 0 && amountRemaining.fraction == 0) { + console.log("full amount spent"); + break; + } + if (amountRemaining.cmp(new Amount(cd.coin.currentAmount)) < 0) { coinSpend = new Amount(amountRemaining.toJson()); } else { coinSpend = new Amount(cd.coin.currentAmount); } + amountSpent.add(coinSpend); + amountRemaining.sub(coinSpend); + let d = new DepositRequestPS({ h_contract: HashCode.fromCrock(offer.H_contract), h_wire: HashCode.fromCrock(offer.contract.H_wire), @@ -97,8 +108,6 @@ function signDeposit(db: IDBDatabase, transaction_id: UInt64.fromNumber(offer.contract.transaction_id), }); - amountSpent.add(coinSpend); - let newAmount = new Amount(cd.coin.currentAmount); newAmount.sub(coinSpend); cd.coin.currentAmount = newAmount.toJson(); @@ -114,7 +123,7 @@ function signDeposit(db: IDBDatabase, denom_pub: cd.coin.denomPub, f: amountSpent.toJson(), }; - ret.push({sig: coinSig, updatedCoin: cd.coin}); + ret.push({sig: s, updatedCoin: cd.coin}); } return ret; } @@ -223,10 +232,11 @@ function executePay(db, reqData["H_contract"] = offer.H_contract; reqData["transaction_id"] = offer.contract.transaction_id; reqData["refund_deadline"] = offer.contract.refund_deadline; - reqData["mint"] = chosenMint; + reqData["mint"] = URI(chosenMint).hostname(); reqData["coins"] = payCoinInfo.map((x) => x.sig); - let payUrl = URI(merchantBaseUrl).absoluteTo(merchantBaseUrl); - console.log("Merchant URL", payUrl); + reqData["timestamp"] = offer.contract.timestamp; + let payUrl = URI(offer.contract.pay_url).absoluteTo(merchantBaseUrl); + console.log("Merchant URL", payUrl.href()); let req = new XMLHttpRequest(); req.open('post', payUrl.href()); req.setRequestHeader("Content-Type", @@ -235,6 +245,7 @@ function executePay(db, req.addEventListener('readystatechange', (e) => { if (req.readyState == XMLHttpRequest.DONE) { if (req.status == 200) { + console.log("Merchant response:", req.responseText); resolve(); } else { throw Error("bad status " + req.status);