From 530f0b3f2e6a44840a2069b84ac9e5a438d01e8e Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 24 Jul 2020 14:42:35 +0530 Subject: implement merchant API changes --- src/types/talerTypes.ts | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src/types/talerTypes.ts') diff --git a/src/types/talerTypes.ts b/src/types/talerTypes.ts index b2d8f6a37..2730da4b2 100644 --- a/src/types/talerTypes.ts +++ b/src/types/talerTypes.ts @@ -41,6 +41,7 @@ import { makeCodecForUnion, makeCodecForConstTrue, makeCodecForConstFalse, + makeCodecForConstString, } from "../util/codec"; import { Timestamp, @@ -690,7 +691,7 @@ export class Proposal { * Response from the internal merchant API. */ export class CheckPaymentResponse { - paid: boolean; + order_status: string; refunded: boolean | undefined; refunded_amount: string | undefined; contract_terms: any | undefined; @@ -846,7 +847,7 @@ interface MerchantOrderStatusPaid { /** * Has the payment for this order (ever) been completed? */ - paid: true; + order_status: "paid"; /** * Was the payment refunded (even partially, via refund or abort)? @@ -874,7 +875,7 @@ export type MerchantCoinRefundStatus = | MerchantCoinRefundFailureStatus; export interface MerchantCoinRefundSuccessStatus { - success: true; + type: "success"; // HTTP status of the exchange request, 200 (integer) required for refund confirmations. exchange_status: 200; @@ -904,7 +905,7 @@ export interface MerchantCoinRefundSuccessStatus { } export interface MerchantCoinRefundFailureStatus { - success: false; + type: "failure"; // HTTP status of the exchange request, must NOT be 200. exchange_status: number; @@ -932,7 +933,7 @@ export interface MerchantOrderStatusUnpaid { /** * Has the payment for this order (ever) been completed? */ - paid: false; + order_status: "unpaid"; /** * URI that the wallet must process to complete the payment. @@ -1141,7 +1142,7 @@ export const codecForProposal = (): Codec => export const codecForCheckPaymentResponse = (): Codec => makeCodecForObject() - .property("paid", codecForBoolean) + .property("order_status", codecForString) .property("refunded", makeCodecOptional(codecForBoolean)) .property("refunded_amount", makeCodecOptional(codecForString)) .property("contract_terms", makeCodecOptional(codecForAny)) @@ -1212,7 +1213,7 @@ export const codecForMerchantCoinRefundSuccessStatus = (): Codec< MerchantCoinRefundSuccessStatus > => makeCodecForObject() - .property("success", makeCodecForConstTrue()) + .property("type", makeCodecForConstString("success")) .property("coin_pub", codecForString) .property("exchange_status", makeCodecForConstNumber(200)) .property("exchange_sig", codecForString) @@ -1226,7 +1227,7 @@ export const codecForMerchantCoinRefundFailureStatus = (): Codec< MerchantCoinRefundFailureStatus > => makeCodecForObject() - .property("success", makeCodecForConstFalse()) + .property("type", makeCodecForConstString("failure")) .property("coin_pub", codecForString) .property("exchange_status", makeCodecForConstNumber(200)) .property("rtransaction_id", codecForNumber) @@ -1240,16 +1241,16 @@ export const codecForMerchantCoinRefundStatus = (): Codec< MerchantCoinRefundStatus > => makeCodecForUnion() - .discriminateOn("success") - .alternative(true, codecForMerchantCoinRefundSuccessStatus()) - .alternative(false, codecForMerchantCoinRefundFailureStatus()) + .discriminateOn("type") + .alternative("success", codecForMerchantCoinRefundSuccessStatus()) + .alternative("failure", codecForMerchantCoinRefundFailureStatus()) .build("MerchantCoinRefundStatus"); export const codecForMerchantOrderStatusPaid = (): Codec< MerchantOrderStatusPaid > => makeCodecForObject() - .property("paid", makeCodecForConstTrue()) + .property("order_status", makeCodecForConstString("paid")) .property("merchant_pub", codecForString) .property("refund_amount", codecForString) .property("refunded", codecForBoolean) @@ -1260,14 +1261,14 @@ export const codecForMerchantOrderStatusUnpaid = (): Codec< MerchantOrderStatusUnpaid > => makeCodecForObject() - .property("paid", makeCodecForConstFalse()) + .property("order_status", makeCodecForConstString("unpaid")) .property("taler_pay_uri", codecForString) .property("already_paid_order_id", makeCodecOptional(codecForString)) .build("MerchantOrderStatusUnpaid"); export const codecForMerchantOrderStatus = (): Codec => makeCodecForUnion() - .discriminateOn("paid") - .alternative(true, codecForMerchantOrderStatusPaid()) - .alternative(false, codecForMerchantOrderStatusUnpaid()) + .discriminateOn("order_status") + .alternative("paid", codecForMerchantOrderStatusPaid()) + .alternative("unpaid", codecForMerchantOrderStatusUnpaid()) .build("MerchantOrderStatus"); -- cgit v1.2.3