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