api simplication
This commit is contained in:
parent
5a7269b20d
commit
c3f47e8f58
@ -817,10 +817,6 @@ export interface PurchaseRecord {
|
||||
*/
|
||||
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).
|
||||
|
@ -701,7 +701,6 @@ export class Wallet {
|
||||
contractTermsHash: proposal.contractTermsHash,
|
||||
finished: false,
|
||||
lastSessionId: undefined,
|
||||
lastSessionSig: undefined,
|
||||
merchantSig: proposal.merchantSig,
|
||||
payReq,
|
||||
refundsDone: {},
|
||||
@ -1134,25 +1133,6 @@ export class Wallet {
|
||||
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) {
|
||||
const reserve = await this.q().get<ReserveRecord>(
|
||||
Stores.reserves,
|
||||
|
@ -261,26 +261,6 @@ export interface HistoryRecord {
|
||||
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,
|
||||
* as well as exchanges that accept these wire types.
|
||||
|
@ -73,10 +73,6 @@ export interface MessageMap {
|
||||
request: { proposalId: number };
|
||||
response: walletTypes.CheckPayResult;
|
||||
};
|
||||
"query-payment": {
|
||||
request: {};
|
||||
response: dbTypes.PurchaseRecord;
|
||||
};
|
||||
"exchange-info": {
|
||||
request: { baseUrl: string };
|
||||
response: dbTypes.ExchangeRecord;
|
||||
@ -97,10 +93,6 @@ export interface MessageMap {
|
||||
request: {};
|
||||
response: walletTypes.HistoryRecord[];
|
||||
};
|
||||
"get-proposal": {
|
||||
request: { proposalId: number };
|
||||
response: dbTypes.ProposalDownloadRecord | undefined;
|
||||
};
|
||||
"get-coins": {
|
||||
request: { exchangeBaseUrl: string };
|
||||
response: any;
|
||||
@ -169,10 +161,6 @@ export interface MessageMap {
|
||||
request: { contractTermsHash: string };
|
||||
response: dbTypes.PurchaseRecord;
|
||||
};
|
||||
"get-full-refund-fees": {
|
||||
request: { refundPermissions: talerTypes.MerchantRefundPermission[] };
|
||||
response: AmountJson;
|
||||
};
|
||||
"accept-tip": {
|
||||
request: { talerTipUri: string };
|
||||
response: void;
|
||||
@ -185,10 +173,6 @@ export interface MessageMap {
|
||||
request: {};
|
||||
response: void;
|
||||
};
|
||||
"taler-pay": {
|
||||
request: any;
|
||||
response: void;
|
||||
};
|
||||
"download-proposal": {
|
||||
request: { url: string };
|
||||
response: number;
|
||||
|
@ -215,13 +215,6 @@ export function payback(coinPub: string): Promise<void> {
|
||||
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.
|
||||
*/
|
||||
@ -257,13 +250,6 @@ export function confirmReserve(reservePub: string): Promise<void> {
|
||||
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
|
||||
*/
|
||||
@ -336,14 +322,6 @@ export function getPurchase(contractTermsHash: string): Promise<PurchaseRecord>
|
||||
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.
|
||||
@ -367,12 +345,6 @@ export function clearNotification(): Promise<void> {
|
||||
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.
|
||||
|
@ -139,21 +139,6 @@ function handleMessage(
|
||||
}
|
||||
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": {
|
||||
if (!detail.baseUrl) {
|
||||
return Promise.resolve({ error: "bad url" });
|
||||
@ -187,9 +172,6 @@ function handleMessage(
|
||||
// TODO: limit history length
|
||||
return needsWallet().getHistory();
|
||||
}
|
||||
case "get-proposal": {
|
||||
return needsWallet().getProposal(detail.proposalId);
|
||||
}
|
||||
case "get-exchanges": {
|
||||
return needsWallet().getExchanges();
|
||||
}
|
||||
@ -289,8 +271,6 @@ function handleMessage(
|
||||
}
|
||||
return needsWallet().getPurchase(contractTermsHash);
|
||||
}
|
||||
case "get-full-refund-fees":
|
||||
return needsWallet().getFullRefundFees(detail.refundPermissions);
|
||||
case "accept-refund":
|
||||
return needsWallet().applyRefund(detail.refundUrl);
|
||||
case "get-tip-status": {
|
||||
@ -311,25 +291,6 @@ function handleMessage(
|
||||
}
|
||||
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": {
|
||||
if (!detail.repetitions) {
|
||||
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> {
|
||||
return new Promise((resolve, reject) => {
|
||||
chrome.tabs.get(tabId, (tab: chrome.tabs.Tab) => resolve(tab));
|
||||
|
Loading…
Reference in New Issue
Block a user