respond with contract terms as JSON (instead of string) in the wallet API

This commit is contained in:
Florian Dold 2020-07-31 00:34:31 +05:30
parent b51932cc85
commit 119c1c708f
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
4 changed files with 11 additions and 13 deletions

View File

@ -924,7 +924,7 @@ export async function preparePayForUri(
logger.info("not confirming payment, insufficient coins"); logger.info("not confirming payment, insufficient coins");
return { return {
status: PreparePayResultType.InsufficientBalance, status: PreparePayResultType.InsufficientBalance,
contractTerms: d.contractTermsRaw, contractTerms: JSON.parse(d.contractTermsRaw),
proposalId: proposal.proposalId, proposalId: proposal.proposalId,
}; };
} }
@ -935,7 +935,7 @@ export async function preparePayForUri(
return { return {
status: PreparePayResultType.PaymentPossible, status: PreparePayResultType.PaymentPossible,
contractTerms: d.contractTermsRaw, contractTerms: JSON.parse(d.contractTermsRaw),
proposalId: proposal.proposalId, proposalId: proposal.proposalId,
amountEffective: Amounts.stringify(costInfo.totalCost), amountEffective: Amounts.stringify(costInfo.totalCost),
amountRaw: Amounts.stringify(res.paymentAmount), amountRaw: Amounts.stringify(res.paymentAmount),
@ -957,20 +957,20 @@ export async function preparePayForUri(
const r = await submitPay(ws, proposalId); const r = await submitPay(ws, proposalId);
return { return {
status: PreparePayResultType.AlreadyConfirmed, status: PreparePayResultType.AlreadyConfirmed,
contractTerms: purchase.contractTermsRaw, contractTerms: JSON.parse(purchase.contractTermsRaw),
paid: true, paid: true,
nextUrl: r.nextUrl, nextUrl: r.nextUrl,
}; };
} else if (!purchase.timestampFirstSuccessfulPay) { } else if (!purchase.timestampFirstSuccessfulPay) {
return { return {
status: PreparePayResultType.AlreadyConfirmed, status: PreparePayResultType.AlreadyConfirmed,
contractTerms: purchase.contractTermsRaw, contractTerms: JSON.parse(purchase.contractTermsRaw),
paid: false, paid: false,
}; };
} else if (purchase.paymentSubmitPending) { } else if (purchase.paymentSubmitPending) {
return { return {
status: PreparePayResultType.AlreadyConfirmed, status: PreparePayResultType.AlreadyConfirmed,
contractTerms: purchase.contractTermsRaw, contractTerms: JSON.parse(purchase.contractTermsRaw),
paid: false, paid: false,
}; };
} }

View File

@ -329,7 +329,7 @@ export type PreparePayResult =
export interface PreparePayResultPaymentPossible { export interface PreparePayResultPaymentPossible {
status: PreparePayResultType.PaymentPossible; status: PreparePayResultType.PaymentPossible;
proposalId: string; proposalId: string;
contractTerms: string; contractTerms: Record<string, unknown>;
amountRaw: string; amountRaw: string;
amountEffective: string; amountEffective: string;
} }
@ -337,12 +337,12 @@ export interface PreparePayResultPaymentPossible {
export interface PreparePayResultInsufficientBalance { export interface PreparePayResultInsufficientBalance {
status: PreparePayResultType.InsufficientBalance; status: PreparePayResultType.InsufficientBalance;
proposalId: string; proposalId: string;
contractTerms: any; contractTerms: Record<string, unknown>;
} }
export interface PreparePayResultAlreadyConfirmed { export interface PreparePayResultAlreadyConfirmed {
status: PreparePayResultType.AlreadyConfirmed; status: PreparePayResultType.AlreadyConfirmed;
contractTerms: any; contractTerms: Record<string, unknown>;
paid: boolean; paid: boolean;
// Only specified if paid. // Only specified if paid.
nextUrl?: string; nextUrl?: string;
@ -368,7 +368,7 @@ export interface AcceptWithdrawalResponse {
* Details about a purchase, including refund status. * Details about a purchase, including refund status.
*/ */
export interface PurchaseDetails { export interface PurchaseDetails {
contractTerms: any; contractTerms: Record<string, undefined>;
hasRefund: boolean; hasRefund: boolean;
totalRefundAmount: AmountJson; totalRefundAmount: AmountJson;
totalRefundAndRefreshFees: AmountJson; totalRefundAndRefreshFees: AmountJson;

View File

@ -791,7 +791,7 @@ export class Wallet {
]).amount; ]).amount;
const totalFees = totalRefundFees; const totalFees = totalRefundFees;
return { return {
contractTerms: purchase.contractTermsRaw, contractTerms: JSON.parse(purchase.contractTermsRaw),
hasRefund: purchase.timestampLastRefundStatus !== undefined, hasRefund: purchase.timestampLastRefundStatus !== undefined,
totalRefundAmount: totalRefundAmount, totalRefundAmount: totalRefundAmount,
totalRefundAndRefreshFees: totalFees, totalRefundAndRefreshFees: totalFees,

View File

@ -74,9 +74,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }): JSX.Element {
let contractTerms: ContractTerms; let contractTerms: ContractTerms;
try { try {
contractTerms = codecForContractTerms().decode( contractTerms = codecForContractTerms().decode(payStatus.contractTerms);
JSON.parse(payStatus.contractTerms),
);
} catch (e) { } catch (e) {
// This should never happen, as the wallet is supposed to check the contract terms // This should never happen, as the wallet is supposed to check the contract terms
// before storing them. // before storing them.