protocol changes
This commit is contained in:
parent
1c5a9d2474
commit
ae8a005271
@ -402,10 +402,10 @@ export class ContractTerms {
|
||||
order_id: string;
|
||||
|
||||
/**
|
||||
* URL to post the payment to.
|
||||
* Base URL of the merchant's backend.
|
||||
*/
|
||||
@Checkable.String()
|
||||
pay_url: string;
|
||||
merchant_base_url: string;
|
||||
|
||||
/**
|
||||
* Fulfillment URL to view the product or
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import test from "ava";
|
||||
import { parsePayUri, parseWithdrawUri } from "./taleruri";
|
||||
import { parsePayUri, parseWithdrawUri, parseRefundUri, parseTipUri } from "./taleruri";
|
||||
|
||||
test("taler pay url parsing: http(s)", (t) => {
|
||||
const url1 = "https://example.com/bar?spam=eggs";
|
||||
@ -150,3 +150,57 @@ test("taler withdraw uri parsing", (t) => {
|
||||
}
|
||||
t.is(r1.statusUrl, "https://bank.example.com/api/withdraw-operation/12345");
|
||||
});
|
||||
|
||||
|
||||
test("taler refund uri parsing", (t) => {
|
||||
const url1 = "taler://refund/merchant.example.com/-/-/1234";
|
||||
const r1 = parseRefundUri(url1);
|
||||
if (!r1) {
|
||||
t.fail();
|
||||
return;
|
||||
}
|
||||
t.is(r1.refundUrl, "https://merchant.example.com/public/refund?order_id=1234");
|
||||
});
|
||||
|
||||
|
||||
test("taler refund uri parsing with instance", (t) => {
|
||||
const url1 = "taler://refund/merchant.example.com/-/myinst/1234";
|
||||
const r1 = parseRefundUri(url1);
|
||||
if (!r1) {
|
||||
t.fail();
|
||||
return;
|
||||
}
|
||||
t.is(r1.refundUrl, "https://merchant.example.com/public/instances/myinst/refund?order_id=1234");
|
||||
});
|
||||
|
||||
test("taler tip pickup uri", (t) => {
|
||||
const url1 = "taler://tip/merchant.example.com/-/-/tipid";
|
||||
const r1 = parseTipUri(url1);
|
||||
if (!r1) {
|
||||
t.fail();
|
||||
return;
|
||||
}
|
||||
t.is(r1.tipPickupUrl, "https://merchant.example.com/public/tip-pickup?tip_id=tipid");
|
||||
});
|
||||
|
||||
|
||||
test("taler tip pickup uri with instance", (t) => {
|
||||
const url1 = "taler://tip/merchant.example.com/-/tipm/tipid";
|
||||
const r1 = parseTipUri(url1);
|
||||
if (!r1) {
|
||||
t.fail();
|
||||
return;
|
||||
}
|
||||
t.is(r1.tipPickupUrl, "https://merchant.example.com/public/instances/tipm/tip-pickup?tip_id=tipid");
|
||||
});
|
||||
|
||||
|
||||
test("taler tip pickup uri with instance and prefix", (t) => {
|
||||
const url1 = "taler://tip/merchant.example.com/my%2fpfx/tipm/tipid";
|
||||
const r1 = parseTipUri(url1);
|
||||
if (!r1) {
|
||||
t.fail();
|
||||
return;
|
||||
}
|
||||
t.is(r1.tipPickupUrl, "https://merchant.example.com/my/pfx/instances/tipm/tip-pickup?tip_id=tipid");
|
||||
});
|
||||
|
@ -147,17 +147,18 @@ export function parseTipUri(s: string): TipUriResult | undefined {
|
||||
}
|
||||
|
||||
if (maybePath === "-") {
|
||||
maybePath = "public/tip-pickup";
|
||||
maybePath = "public/";
|
||||
} else {
|
||||
maybePath = decodeURIComponent(maybePath);
|
||||
maybePath = decodeURIComponent(maybePath) + "/";
|
||||
}
|
||||
if (maybeInstance === "-") {
|
||||
maybeInstance = "default";
|
||||
let maybeInstancePath = "";
|
||||
if (maybeInstance !== "-") {
|
||||
maybeInstancePath = `instances/${maybeInstance}/`;
|
||||
}
|
||||
|
||||
const tipPickupUrl = new URI(
|
||||
"https://" + host + "/" + decodeURIComponent(maybePath),
|
||||
).href();
|
||||
"https://" + host + "/" + maybePath + maybeInstancePath + "tip-pickup",
|
||||
).addQuery({ tip_id: tipId }).href();
|
||||
|
||||
return {
|
||||
tipPickupUrl,
|
||||
@ -197,20 +198,20 @@ export function parseRefundUri(s: string): RefundUriResult | undefined {
|
||||
}
|
||||
|
||||
if (maybePath === "-") {
|
||||
maybePath = "public/refund";
|
||||
maybePath = "public/";
|
||||
} else {
|
||||
maybePath = decodeURIComponent(maybePath);
|
||||
maybePath = decodeURIComponent(maybePath) + "/";
|
||||
}
|
||||
if (maybeInstance === "-") {
|
||||
maybeInstance = "default";
|
||||
let maybeInstancePath = "";
|
||||
if (maybeInstance !== "-") {
|
||||
maybeInstancePath = `instances/${maybeInstance}/`;
|
||||
}
|
||||
|
||||
const refundUrl = new URI(
|
||||
"https://" + host + "/" + decodeURIComponent(maybePath),
|
||||
"https://" + host + "/" + maybePath + maybeInstancePath + "refund",
|
||||
)
|
||||
.addQuery({ instance: maybeInstance, order_id: orderId })
|
||||
.addQuery({ order_id: orderId })
|
||||
.href();
|
||||
|
||||
return {
|
||||
refundUrl,
|
||||
};
|
||||
|
@ -115,7 +115,7 @@ test("contract terms validation", (t) => {
|
||||
merchant_pub: "12345",
|
||||
order_id: "test_order",
|
||||
pay_deadline: "Date(12346)",
|
||||
pay_url: "https://example.com/pay",
|
||||
merchant_base_url: "https://example.com/pay",
|
||||
products: [],
|
||||
refund_deadline: "Date(12345)",
|
||||
summary: "hello",
|
||||
|
@ -965,15 +965,17 @@ export class Wallet {
|
||||
let resp;
|
||||
const payReq = { ...purchase.payReq, session_id: sessionId };
|
||||
|
||||
const payUrl = new URI("pay").absoluteTo(purchase.contractTerms.merchant_base_url).href()
|
||||
|
||||
try {
|
||||
resp = await this.http.postJson(purchase.contractTerms.pay_url, payReq);
|
||||
resp = await this.http.postJson(payUrl, payReq);
|
||||
} catch (e) {
|
||||
// Gives the user the option to retry / abort and refresh
|
||||
console.log("payment failed", e);
|
||||
throw e;
|
||||
}
|
||||
const merchantResp = resp.responseJson;
|
||||
console.log("got success from pay_url");
|
||||
console.log("got success from pay URL");
|
||||
|
||||
const merchantPub = purchase.contractTerms.merchant_pub;
|
||||
const valid: boolean = await this.cryptoApi.isValidPaymentSignature(
|
||||
@ -3033,7 +3035,7 @@ export class Wallet {
|
||||
merchant_pub: pub,
|
||||
order_id: "none",
|
||||
pay_deadline: `/Date(${stampSecNow + 60 * 5})/`,
|
||||
pay_url: "",
|
||||
merchant_base_url: "taler://return-to-account",
|
||||
products: [],
|
||||
refund_deadline: `/Date(${stampSecNow + 60 * 5})/`,
|
||||
timestamp: `/Date(${stampSecNow})/`,
|
||||
@ -3466,9 +3468,7 @@ export class Wallet {
|
||||
throw Error("invalid taler://tip URI");
|
||||
}
|
||||
|
||||
const tipStatusUrl = new URI(res.tipPickupUrl)
|
||||
.addQuery({ tip_id: res.tipId })
|
||||
.href();
|
||||
const tipStatusUrl = new URI(res.tipPickupUrl).href();
|
||||
console.log("checking tip status from", tipStatusUrl);
|
||||
const merchantResp = await this.http.get(tipStatusUrl);
|
||||
console.log("resp:", merchantResp.responseJson);
|
||||
@ -3552,8 +3552,10 @@ export class Wallet {
|
||||
|
||||
const abortReq = { ...purchase.payReq, mode: "abort-refund" };
|
||||
|
||||
const payUrl = new URI("pay").absoluteTo(purchase.contractTerms.merchant_base_url).href()
|
||||
|
||||
try {
|
||||
resp = await this.http.postJson(purchase.contractTerms.pay_url, abortReq);
|
||||
resp = await this.http.postJson(payUrl, abortReq);
|
||||
} catch (e) {
|
||||
// Gives the user the option to retry / abort and refresh
|
||||
console.log("aborting payment failed", e);
|
||||
|
@ -53,6 +53,11 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }) {
|
||||
return <span>Loading payment information ...</span>;
|
||||
}
|
||||
|
||||
let insufficientBalance = false;
|
||||
if (payStatus.status == "insufficient-balance") {
|
||||
insufficientBalance = true;
|
||||
}
|
||||
|
||||
if (payStatus.status === "error") {
|
||||
return <span>Error: {payStatus.error}</span>;
|
||||
}
|
||||
@ -93,7 +98,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }) {
|
||||
|
||||
const doPayment = async () => {
|
||||
if (payStatus.status !== "payment-possible") {
|
||||
throw Error("invalid state");
|
||||
throw Error(`invalid state: ${payStatus.status}`);
|
||||
}
|
||||
const proposalId = payStatus.proposalId;
|
||||
setNumTries(numTries + 1);
|
||||
@ -128,6 +133,12 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }) {
|
||||
)}
|
||||
</p>
|
||||
|
||||
{insufficientBalance ? (
|
||||
<div>
|
||||
<p style={{color: "red", fontWeight: "bold"}}>Unable to pay: Your balance is insufficient.</p>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{payErrMsg ? (
|
||||
<div>
|
||||
<p>Payment failed: {payErrMsg}</p>
|
||||
@ -142,6 +153,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }) {
|
||||
<div>
|
||||
<ProgressButton
|
||||
loading={loading}
|
||||
disabled={insufficientBalance}
|
||||
onClick={() => doPayment()}>
|
||||
{i18n.str`Confirm payment`}
|
||||
</ProgressButton>
|
||||
|
@ -86,6 +86,7 @@ async function callBackend<T extends MessageType>(
|
||||
return new Promise<MessageMap[T]["response"]>((resolve, reject) => {
|
||||
chrome.runtime.sendMessage({ type, detail }, (resp) => {
|
||||
if (typeof resp === "object" && resp && resp.error) {
|
||||
console.warn("response error:", resp)
|
||||
const e = new WalletApiError(resp.error.message, resp.error);
|
||||
reject(e);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user