api simplication
This commit is contained in:
parent
5a7269b20d
commit
c3f47e8f58
@ -817,10 +817,6 @@ export interface PurchaseRecord {
|
|||||||
*/
|
*/
|
||||||
timestamp_refund: number;
|
timestamp_refund: number;
|
||||||
|
|
||||||
/**
|
|
||||||
* Last session id that we submitted to /pay (if any).
|
|
||||||
*/
|
|
||||||
lastSessionSig: string | undefined;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Last session signature that we submitted to /pay (if any).
|
* Last session signature that we submitted to /pay (if any).
|
||||||
|
@ -701,7 +701,6 @@ export class Wallet {
|
|||||||
contractTermsHash: proposal.contractTermsHash,
|
contractTermsHash: proposal.contractTermsHash,
|
||||||
finished: false,
|
finished: false,
|
||||||
lastSessionId: undefined,
|
lastSessionId: undefined,
|
||||||
lastSessionSig: undefined,
|
|
||||||
merchantSig: proposal.merchantSig,
|
merchantSig: proposal.merchantSig,
|
||||||
payReq,
|
payReq,
|
||||||
refundsDone: {},
|
refundsDone: {},
|
||||||
@ -1134,25 +1133,6 @@ export class Wallet {
|
|||||||
return { status: "payment-possible", coinSelection: res };
|
return { status: "payment-possible", coinSelection: res };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve information required to pay for a contract, where the
|
|
||||||
* contract is identified via the fulfillment url.
|
|
||||||
*/
|
|
||||||
async queryPaymentByFulfillmentUrl(
|
|
||||||
url: string,
|
|
||||||
): Promise<PurchaseRecord | undefined> {
|
|
||||||
const t = await this.q().getIndexed(
|
|
||||||
Stores.purchases.fulfillmentUrlIndex,
|
|
||||||
url,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!t) {
|
|
||||||
console.log("query for payment failed");
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async sendReserveInfoToBank(reservePub: string) {
|
private async sendReserveInfoToBank(reservePub: string) {
|
||||||
const reserve = await this.q().get<ReserveRecord>(
|
const reserve = await this.q().get<ReserveRecord>(
|
||||||
Stores.reserves,
|
Stores.reserves,
|
||||||
|
@ -261,26 +261,6 @@ export interface HistoryRecord {
|
|||||||
detail: any;
|
detail: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Query payment response when the payment was found.
|
|
||||||
*/
|
|
||||||
export interface QueryPaymentNotFound {
|
|
||||||
found: false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Query payment response when the payment wasn't found.
|
|
||||||
*/
|
|
||||||
export interface QueryPaymentFound {
|
|
||||||
found: true;
|
|
||||||
contractTermsHash: string;
|
|
||||||
contractTerms: ContractTerms;
|
|
||||||
lastSessionSig?: string;
|
|
||||||
lastSessionId?: string;
|
|
||||||
payReq: PayReq;
|
|
||||||
proposalId: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information about all sender wire details known to the wallet,
|
* Information about all sender wire details known to the wallet,
|
||||||
* as well as exchanges that accept these wire types.
|
* as well as exchanges that accept these wire types.
|
||||||
|
@ -73,10 +73,6 @@ export interface MessageMap {
|
|||||||
request: { proposalId: number };
|
request: { proposalId: number };
|
||||||
response: walletTypes.CheckPayResult;
|
response: walletTypes.CheckPayResult;
|
||||||
};
|
};
|
||||||
"query-payment": {
|
|
||||||
request: {};
|
|
||||||
response: dbTypes.PurchaseRecord;
|
|
||||||
};
|
|
||||||
"exchange-info": {
|
"exchange-info": {
|
||||||
request: { baseUrl: string };
|
request: { baseUrl: string };
|
||||||
response: dbTypes.ExchangeRecord;
|
response: dbTypes.ExchangeRecord;
|
||||||
@ -97,10 +93,6 @@ export interface MessageMap {
|
|||||||
request: {};
|
request: {};
|
||||||
response: walletTypes.HistoryRecord[];
|
response: walletTypes.HistoryRecord[];
|
||||||
};
|
};
|
||||||
"get-proposal": {
|
|
||||||
request: { proposalId: number };
|
|
||||||
response: dbTypes.ProposalDownloadRecord | undefined;
|
|
||||||
};
|
|
||||||
"get-coins": {
|
"get-coins": {
|
||||||
request: { exchangeBaseUrl: string };
|
request: { exchangeBaseUrl: string };
|
||||||
response: any;
|
response: any;
|
||||||
@ -169,10 +161,6 @@ export interface MessageMap {
|
|||||||
request: { contractTermsHash: string };
|
request: { contractTermsHash: string };
|
||||||
response: dbTypes.PurchaseRecord;
|
response: dbTypes.PurchaseRecord;
|
||||||
};
|
};
|
||||||
"get-full-refund-fees": {
|
|
||||||
request: { refundPermissions: talerTypes.MerchantRefundPermission[] };
|
|
||||||
response: AmountJson;
|
|
||||||
};
|
|
||||||
"accept-tip": {
|
"accept-tip": {
|
||||||
request: { talerTipUri: string };
|
request: { talerTipUri: string };
|
||||||
response: void;
|
response: void;
|
||||||
@ -185,10 +173,6 @@ export interface MessageMap {
|
|||||||
request: {};
|
request: {};
|
||||||
response: void;
|
response: void;
|
||||||
};
|
};
|
||||||
"taler-pay": {
|
|
||||||
request: any;
|
|
||||||
response: void;
|
|
||||||
};
|
|
||||||
"download-proposal": {
|
"download-proposal": {
|
||||||
request: { url: string };
|
request: { url: string };
|
||||||
response: number;
|
response: number;
|
||||||
|
@ -215,13 +215,6 @@ export function payback(coinPub: string): Promise<void> {
|
|||||||
return callBackend("payback-coin", { coinPub });
|
return callBackend("payback-coin", { coinPub });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a proposal stored in the wallet by its proposal id.
|
|
||||||
*/
|
|
||||||
export function getProposal(proposalId: number): Promise<ProposalDownloadRecord | undefined> {
|
|
||||||
return callBackend("get-proposal", { proposalId });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if payment is possible or already done.
|
* Check if payment is possible or already done.
|
||||||
*/
|
*/
|
||||||
@ -257,13 +250,6 @@ export function confirmReserve(reservePub: string): Promise<void> {
|
|||||||
return callBackend("confirm-reserve", { reservePub });
|
return callBackend("confirm-reserve", { reservePub });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Query for a payment by fulfillment URL.
|
|
||||||
*/
|
|
||||||
export function queryPaymentByFulfillmentUrl(url: string): Promise<PurchaseRecord> {
|
|
||||||
return callBackend("query-payment", { url });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check upgrade information
|
* Check upgrade information
|
||||||
*/
|
*/
|
||||||
@ -336,14 +322,6 @@ export function getPurchase(contractTermsHash: string): Promise<PurchaseRecord>
|
|||||||
return callBackend("get-purchase", { contractTermsHash });
|
return callBackend("get-purchase", { contractTermsHash });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the refund fees for a refund permission, including
|
|
||||||
* subsequent refresh and unrefreshable coins.
|
|
||||||
*/
|
|
||||||
export function getFullRefundFees(args: { refundPermissions: MerchantRefundPermission[] }): Promise<AmountJson> {
|
|
||||||
return callBackend("get-full-refund-fees", { refundPermissions: args.refundPermissions });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the status of processing a tip.
|
* Get the status of processing a tip.
|
||||||
@ -367,12 +345,6 @@ export function clearNotification(): Promise<void> {
|
|||||||
return callBackend("clear-notification", { });
|
return callBackend("clear-notification", { });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Trigger taler payment processing (for payment, tipping and refunds).
|
|
||||||
*/
|
|
||||||
export function talerPay(msg: any): Promise<void> {
|
|
||||||
return callBackend("taler-pay", msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download a contract.
|
* Download a contract.
|
||||||
|
@ -139,21 +139,6 @@ function handleMessage(
|
|||||||
}
|
}
|
||||||
return needsWallet().checkPay(detail.proposalId);
|
return needsWallet().checkPay(detail.proposalId);
|
||||||
}
|
}
|
||||||
case "query-payment": {
|
|
||||||
if (sender.tab && sender.tab.id) {
|
|
||||||
rateLimitCache[sender.tab.id]++;
|
|
||||||
if (rateLimitCache[sender.tab.id] > 10) {
|
|
||||||
console.warn("rate limit for query-payment exceeded");
|
|
||||||
const msg = {
|
|
||||||
error: "rate limit exceeded for query-payment",
|
|
||||||
hint: "Check for redirect loops",
|
|
||||||
rateLimitExceeded: true,
|
|
||||||
};
|
|
||||||
return Promise.resolve(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return needsWallet().queryPaymentByFulfillmentUrl(detail.url);
|
|
||||||
}
|
|
||||||
case "exchange-info": {
|
case "exchange-info": {
|
||||||
if (!detail.baseUrl) {
|
if (!detail.baseUrl) {
|
||||||
return Promise.resolve({ error: "bad url" });
|
return Promise.resolve({ error: "bad url" });
|
||||||
@ -187,9 +172,6 @@ function handleMessage(
|
|||||||
// TODO: limit history length
|
// TODO: limit history length
|
||||||
return needsWallet().getHistory();
|
return needsWallet().getHistory();
|
||||||
}
|
}
|
||||||
case "get-proposal": {
|
|
||||||
return needsWallet().getProposal(detail.proposalId);
|
|
||||||
}
|
|
||||||
case "get-exchanges": {
|
case "get-exchanges": {
|
||||||
return needsWallet().getExchanges();
|
return needsWallet().getExchanges();
|
||||||
}
|
}
|
||||||
@ -289,8 +271,6 @@ function handleMessage(
|
|||||||
}
|
}
|
||||||
return needsWallet().getPurchase(contractTermsHash);
|
return needsWallet().getPurchase(contractTermsHash);
|
||||||
}
|
}
|
||||||
case "get-full-refund-fees":
|
|
||||||
return needsWallet().getFullRefundFees(detail.refundPermissions);
|
|
||||||
case "accept-refund":
|
case "accept-refund":
|
||||||
return needsWallet().applyRefund(detail.refundUrl);
|
return needsWallet().applyRefund(detail.refundUrl);
|
||||||
case "get-tip-status": {
|
case "get-tip-status": {
|
||||||
@ -311,25 +291,6 @@ function handleMessage(
|
|||||||
}
|
}
|
||||||
return needsWallet().abortFailedPayment(detail.contractTermsHash);
|
return needsWallet().abortFailedPayment(detail.contractTermsHash);
|
||||||
}
|
}
|
||||||
case "taler-pay": {
|
|
||||||
const senderUrl = sender.url;
|
|
||||||
if (!senderUrl) {
|
|
||||||
console.log("can't trigger payment, no sender URL");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const tab = sender.tab;
|
|
||||||
if (!tab) {
|
|
||||||
console.log("can't trigger payment, no sender tab");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const tabId = tab.id;
|
|
||||||
if (typeof tabId !== "string") {
|
|
||||||
console.log("can't trigger payment, no sender tab id");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
talerPay(detail, senderUrl, tabId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case "benchmark-crypto": {
|
case "benchmark-crypto": {
|
||||||
if (!detail.repetitions) {
|
if (!detail.repetitions) {
|
||||||
throw Error("repetitions not given");
|
throw Error("repetitions not given");
|
||||||
@ -418,66 +379,6 @@ class ChromeNotifier implements Notifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function talerPay(
|
|
||||||
fields: any,
|
|
||||||
url: string,
|
|
||||||
tabId: number,
|
|
||||||
): Promise<string | undefined> {
|
|
||||||
if (!currentWallet) {
|
|
||||||
console.log("can't handle payment, no wallet");
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const w = currentWallet;
|
|
||||||
|
|
||||||
const goToPayment = (p: PurchaseRecord): string => {
|
|
||||||
const nextUrl = new URI(p.contractTerms.fulfillment_url);
|
|
||||||
nextUrl.addSearch("order_id", p.contractTerms.order_id);
|
|
||||||
if (p.lastSessionSig) {
|
|
||||||
nextUrl.addSearch("session_sig", p.lastSessionSig);
|
|
||||||
}
|
|
||||||
return nextUrl.href();
|
|
||||||
};
|
|
||||||
|
|
||||||
if (fields.resource_url) {
|
|
||||||
const p = await w.queryPaymentByFulfillmentUrl(fields.resource_url);
|
|
||||||
console.log("query for resource url", fields.resource_url, "result", p);
|
|
||||||
if (
|
|
||||||
p &&
|
|
||||||
(fields.session_id === undefined || fields.session_id === p.lastSessionId)
|
|
||||||
) {
|
|
||||||
return goToPayment(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fields.contract_url) {
|
|
||||||
const proposalId = await w.downloadProposal(fields.contract_url);
|
|
||||||
const uri = new URI(
|
|
||||||
chrome.extension.getURL("/src/webex/pages/confirm-contract.html"),
|
|
||||||
);
|
|
||||||
if (fields.session_id) {
|
|
||||||
uri.addSearch("sessionId", fields.session_id);
|
|
||||||
}
|
|
||||||
uri.addSearch("proposalId", proposalId);
|
|
||||||
const redirectUrl = uri.href();
|
|
||||||
return redirectUrl;
|
|
||||||
}
|
|
||||||
if (fields.offer_url) {
|
|
||||||
return fields.offer_url;
|
|
||||||
}
|
|
||||||
if (fields.refund_url) {
|
|
||||||
console.log("processing refund");
|
|
||||||
const uri = new URI(
|
|
||||||
chrome.extension.getURL("/src/webex/pages/refund.html"),
|
|
||||||
);
|
|
||||||
return uri.query({ refundUrl: fields.refund_url }).href();
|
|
||||||
}
|
|
||||||
if (fields.tip) {
|
|
||||||
const uri = new URI(chrome.extension.getURL("/src/webex/pages/tip.html"));
|
|
||||||
return uri.query({ tip_token: fields.tip }).href();
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTab(tabId: number): Promise<chrome.tabs.Tab> {
|
function getTab(tabId: number): Promise<chrome.tabs.Tab> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
chrome.tabs.get(tabId, (tab: chrome.tabs.Tab) => resolve(tab));
|
chrome.tabs.get(tabId, (tab: chrome.tabs.Tab) => resolve(tab));
|
||||||
|
Loading…
Reference in New Issue
Block a user