payment
This commit is contained in:
parent
3ddfad1973
commit
bc05121da2
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user