summaryrefslogtreecommitdiff
path: root/packages/taler-util/src/http-client/types.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-03-19 15:39:06 -0300
committerSebastian <sebasjm@gmail.com>2024-03-19 15:39:06 -0300
commit7c7086e11f641100e0dd06364a97503df348e2b2 (patch)
tree2f8ad2705fcf242e315e728642af3005b24e30b5 /packages/taler-util/src/http-client/types.ts
parent3c03ac5de448880b428b61e8c4fba1d393caf054 (diff)
downloadwallet-core-7c7086e11f641100e0dd06364a97503df348e2b2.tar.gz
wallet-core-7c7086e11f641100e0dd06364a97503df348e2b2.tar.bz2
wallet-core-7c7086e11f641100e0dd06364a97503df348e2b2.zip
wip
Diffstat (limited to 'packages/taler-util/src/http-client/types.ts')
-rw-r--r--packages/taler-util/src/http-client/types.ts281
1 files changed, 251 insertions, 30 deletions
diff --git a/packages/taler-util/src/http-client/types.ts b/packages/taler-util/src/http-client/types.ts
index 67ac289d6..7e4e2f84c 100644
--- a/packages/taler-util/src/http-client/types.ts
+++ b/packages/taler-util/src/http-client/types.ts
@@ -6,6 +6,7 @@ import {
buildCodecForUnion,
codecForAny,
codecForBoolean,
+ codecForConstNumber,
codecForConstString,
codecForEither,
codecForList,
@@ -15,12 +16,18 @@ import {
codecOptional,
} from "../codec.js";
import { PaytoString, codecForPaytoString } from "../payto.js";
-import { AmountString, MerchantContractTerms, codecForMerchantContractTerms } from "../taler-types.js";
+import {
+ AmountString,
+ MerchantContractTerms,
+ codecForLocation,
+ codecForMerchantContractTerms,
+} from "../taler-types.js";
import { TalerActionString, codecForTalerActionString } from "../taleruri.js";
import {
AbsoluteTime,
TalerProtocolDuration,
TalerProtocolTimestamp,
+ codecForDuration,
codecForTimestamp,
} from "../time.js";
@@ -315,9 +322,216 @@ export const codecForMerchantConfig =
export const codecForClaimResponse =
(): Codec<TalerMerchantApi.ClaimResponse> =>
buildCodecForObject<TalerMerchantApi.ClaimResponse>()
- .property("contract_terms", codecForMerchantContractTerms())
- .property("sig", codecForString())
- .build("TalerMerchantApi.ClaimResponse");
+ .property("contract_terms", codecForMerchantContractTerms())
+ .property("sig", codecForString())
+ .build("TalerMerchantApi.ClaimResponse");
+
+export const codecForPaymentResponse =
+ (): Codec<TalerMerchantApi.PaymentResponse> =>
+ buildCodecForObject<TalerMerchantApi.PaymentResponse>()
+ .property("pos_confirmation", codecOptional(codecForString()))
+ .property("sig", codecForString())
+ .build("TalerMerchantApi.PaymentResponse");
+
+export const codecForStatusPaid = (): Codec<TalerMerchantApi.StatusPaid> =>
+ buildCodecForObject<TalerMerchantApi.StatusPaid>()
+ .property("refund_amount", codecForAmountString())
+ .property("refund_pending", codecForBoolean())
+ .property("refund_taken", codecForAmountString())
+ .property("refunded", codecForBoolean())
+ .property("type", codecForConstString("paid"))
+ .build("TalerMerchantApi.StatusPaid");
+
+export const codecForStatusGoto =
+ (): Codec<TalerMerchantApi.StatusGotoResponse> =>
+ buildCodecForObject<TalerMerchantApi.StatusGotoResponse>()
+ .property("public_reorder_url", codecForURL())
+ .property("type", codecForConstString("goto"))
+ .build("TalerMerchantApi.StatusGotoResponse");
+
+export const codecForStatusStatusUnpaid =
+ (): Codec<TalerMerchantApi.StatusUnpaidResponse> =>
+ buildCodecForObject<TalerMerchantApi.StatusUnpaidResponse>()
+ .property("type", codecForConstString("unpaid"))
+ .property("already_paid_order_id", codecOptional(codecForString()))
+ .property("fulfillment_url", codecOptional(codecForString()))
+ .property("taler_pay_uri", codecForString())
+ .build("TalerMerchantApi.PaymentResponse");
+
+export const codecForPaidRefundStatusResponse =
+ (): Codec<TalerMerchantApi.PaidRefundStatusResponse> =>
+ buildCodecForObject<TalerMerchantApi.PaidRefundStatusResponse>()
+ .property("pos_confirmation", codecOptional(codecForString()))
+ .property("refunded", codecForBoolean())
+ .build("TalerMerchantApi.PaidRefundStatusResponse");
+
+export const codecForMerchantAbortPayRefundSuccessStatus =
+ (): Codec<TalerMerchantApi.MerchantAbortPayRefundSuccessStatus> =>
+ buildCodecForObject<TalerMerchantApi.MerchantAbortPayRefundSuccessStatus>()
+ .property("exchange_pub", codecForString())
+ .property("exchange_sig", codecForString())
+ .property("exchange_status", codecForConstNumber(200))
+ .property("type", codecForConstString("success"))
+ .build("TalerMerchantApi.MerchantAbortPayRefundSuccessStatus");
+
+export const codecForMerchantAbortPayRefundFailureStatus =
+ (): Codec<TalerMerchantApi.MerchantAbortPayRefundFailureStatus> =>
+ buildCodecForObject<TalerMerchantApi.MerchantAbortPayRefundFailureStatus>()
+ .property("exchange_code", codecForNumber())
+ .property("exchange_reply", codecForAny())
+ .property("exchange_status", codecForNumber())
+ .property("type", codecForConstString("failure"))
+ .build("TalerMerchantApi.MerchantAbortPayRefundFailureStatus");
+
+export const codecForMerchantAbortPayRefundStatus =
+ (): Codec<TalerMerchantApi.MerchantAbortPayRefundStatus> =>
+ buildCodecForUnion<TalerMerchantApi.MerchantAbortPayRefundStatus>()
+ .discriminateOn("type")
+ .alternative("success", codecForMerchantAbortPayRefundSuccessStatus())
+ .alternative("failure", codecForMerchantAbortPayRefundFailureStatus())
+ .build("TalerMerchantApi.MerchantAbortPayRefundStatus");
+
+export const codecForAbortResponse =
+ (): Codec<TalerMerchantApi.AbortResponse> =>
+ buildCodecForObject<TalerMerchantApi.AbortResponse>()
+ .property("refunds", codecForList(codecForMerchantAbortPayRefundStatus()))
+ .build("TalerMerchantApi.AbortResponse");
+
+export const codecForWalletRefundResponse =
+ (): Codec<TalerMerchantApi.WalletRefundResponse> =>
+ buildCodecForObject<TalerMerchantApi.WalletRefundResponse>()
+ .property("merchant_pub", codecForString())
+ .property("refund_amount", codecForAmountString())
+ .property("refunds", codecForList(codecForMerchantCoinRefundStatus()))
+ .build("TalerMerchantApi.AbortResponse");
+
+export const codecForMerchantCoinRefundSuccessStatus =
+ (): Codec<TalerMerchantApi.MerchantCoinRefundSuccessStatus> =>
+ buildCodecForObject<TalerMerchantApi.MerchantCoinRefundSuccessStatus>()
+ .property("type", codecForConstString("success"))
+ .property("coin_pub", codecForString())
+ .property("exchange_status", codecForConstNumber(200))
+ .property("exchange_sig", codecForString())
+ .property("rtransaction_id", codecForNumber())
+ .property("refund_amount", codecForAmountString())
+ .property("exchange_pub", codecForString())
+ .property("execution_time", codecForTimestamp)
+ .build("TalerMerchantApi.MerchantCoinRefundSuccessStatus");
+
+export const codecForMerchantCoinRefundFailureStatus =
+ (): Codec<TalerMerchantApi.MerchantCoinRefundFailureStatus> =>
+ buildCodecForObject<TalerMerchantApi.MerchantCoinRefundFailureStatus>()
+ .property("type", codecForConstString("failure"))
+ .property("coin_pub", codecForString())
+ .property("exchange_status", codecForNumber())
+ .property("rtransaction_id", codecForNumber())
+ .property("refund_amount", codecForAmountString())
+ .property("exchange_code", codecOptional(codecForNumber()))
+ .property("exchange_reply", codecOptional(codecForAny()))
+ .property("execution_time", codecForTimestamp)
+ .build("TalerMerchantApi.MerchantCoinRefundFailureStatus");
+
+export const codecForMerchantCoinRefundStatus =
+ (): Codec<TalerMerchantApi.MerchantCoinRefundStatus> =>
+ buildCodecForUnion<TalerMerchantApi.MerchantCoinRefundStatus>()
+ .discriminateOn("type")
+ .alternative("success", codecForMerchantCoinRefundSuccessStatus())
+ .alternative("failure", codecForMerchantCoinRefundFailureStatus())
+ .build("TalerMerchantApi.MerchantCoinRefundStatus");
+
+export const codecForQueryInstancesResponse =
+ (): Codec<TalerMerchantApi.QueryInstancesResponse> =>
+ buildCodecForObject<TalerMerchantApi.QueryInstancesResponse>()
+ .property("name", codecForString())
+ .property("user_type", codecForString())
+ .property("email", codecOptional(codecForString()))
+ .property("website", codecOptional(codecForString()))
+ .property("logo", codecOptional(codecForString()))
+ .property("merchant_pub", codecForString())
+ .property("address", codecForLocation())
+ .property("jurisdiction", codecForLocation())
+ .property("use_stefan", codecForBoolean())
+ .property("default_wire_transfer_delay", codecForDuration)
+ .property("default_pay_delay", codecForDuration)
+ .property(
+ "auth",
+ buildCodecForObject<{
+ type: "external" | "token";
+ }>()
+ .property(
+ "type",
+ codecForEither(
+ codecForConstString("token"),
+ codecForConstString("external"),
+ ),
+ )
+ .build("TalerMerchantApi.QueryInstancesResponse.auth"),
+ )
+ .build("TalerMerchantApi.QueryInstancesResponse");
+
+export const codecForAccountKycRedirects =
+ (): Codec<TalerMerchantApi.AccountKycRedirects> =>
+ buildCodecForObject<TalerMerchantApi.AccountKycRedirects>()
+ .property(
+ "pending_kycs",
+ codecForList(codecForMerchantAccountKycRedirect()),
+ )
+ .property("timeout_kycs", codecForList(codecForExchangeKycTimeout()))
+
+ .build("TalerMerchantApi.AccountKycRedirects");
+
+export const codecForMerchantAccountKycRedirect =
+ (): Codec<TalerMerchantApi.MerchantAccountKycRedirect> =>
+ buildCodecForObject<TalerMerchantApi.MerchantAccountKycRedirect>()
+ .property("kyc_url", codecForURL())
+ .property("aml_status", codecForNumber())
+ .property("exchange_url", codecForURL())
+ .property("payto_uri", codecForPaytoString())
+ .build("TalerMerchantApi.MerchantAccountKycRedirect");
+
+export const codecForExchangeKycTimeout =
+ (): Codec<TalerMerchantApi.ExchangeKycTimeout> =>
+ buildCodecForObject<TalerMerchantApi.ExchangeKycTimeout>()
+ .property("exchange_url", codecForURL())
+ .property("exchange_code", codecForNumber())
+ .property("exchange_http_status", codecForNumber())
+ .build("TalerMerchantApi.ExchangeKycTimeout");
+
+export const codecForAccountAddResponse =
+ (): Codec<TalerMerchantApi.AccountAddResponse> =>
+ buildCodecForObject<TalerMerchantApi.AccountAddResponse>()
+ .property("h_wire", codecForString())
+ .property("salt", codecForString())
+ .build("TalerMerchantApi.AccountAddResponse");
+
+export const codecForAccountsSummaryResponse =
+ (): Codec<TalerMerchantApi.AccountsSummaryResponse> =>
+ buildCodecForObject<TalerMerchantApi.AccountsSummaryResponse>()
+ .property("accounts", codecForList(codecForBankAccountEntry()))
+ .build("TalerMerchantApi.AccountsSummaryResponse");
+
+export const codecForBankAccountEntry =
+ (): Codec<TalerMerchantApi.BankAccountEntry> =>
+ buildCodecForObject<TalerMerchantApi.BankAccountEntry>()
+ .property("payto_uri", codecForPaytoString())
+ .property("h_wire", codecForString())
+ .property("salt", codecForString())
+ .property("credit_facade_url", codecForURL())
+ .property("active", codecForBoolean())
+ .build("TalerMerchantApi.BankAccountEntry");
+
+export const codecForInventorySummaryResponse =
+ (): Codec<TalerMerchantApi.InventorySummaryResponse> =>
+ buildCodecForObject<TalerMerchantApi.InventorySummaryResponse>()
+ .property("products", codecForList(codecForInventoryEntry()))
+ .build("TalerMerchantApi.InventorySummaryResponse");
+
+export const codecForInventoryEntry =
+ (): Codec<TalerMerchantApi.InventoryEntry> =>
+ buildCodecForObject<TalerMerchantApi.InventoryEntry>()
+ .property("product_id", codecForString())
+ .property("product_serial", codecForNumber())
+ .build("TalerMerchantApi.InventoryEntry");
export const codecForExchangeConfig =
(): Codec<TalerExchangeApi.ExchangeVersionResponse> =>
@@ -2477,7 +2691,6 @@ export namespace TalerMerchantApi {
export interface ClaimResponse {
// Contract terms of the claimed order
contract_terms: MerchantContractTerms;
-
// Signature by the merchant over the contract terms.
sig: EddsaSignature;
@@ -2647,7 +2860,9 @@ export namespace TalerMerchantApi {
exchange_url: string;
}
- interface StatusPaid {
+ export interface StatusPaid {
+ type: "paid";
+
// Was the payment refunded (even partially, via refund or abort)?
refunded: boolean;
@@ -2660,14 +2875,16 @@ export namespace TalerMerchantApi {
// Amount that already taken by the wallet.
refund_taken: AmountString;
}
- interface StatusGotoResponse {
+ export interface StatusGotoResponse {
+ type: "goto";
// The client should go to the reorder URL, there a fresh
// order might be created as this one is taken by another
// customer or wallet (or repurchase detection logic may
// apply).
public_reorder_url: string;
}
- interface StatusUnpaidResponse {
+ export interface StatusUnpaidResponse {
+ type: "unpaid";
// URI that the wallet must process to complete the payment.
taler_pay_uri: string;
@@ -2680,7 +2897,7 @@ export namespace TalerMerchantApi {
already_paid_order_id?: string;
}
- interface PaidRefundStatusResponse {
+ export interface PaidRefundStatusResponse {
// Text to be shown to the point-of-sale staff as a proof of
// payment (present only if reusable OTP algorithm is used).
pos_confirmation?: string;
@@ -2726,18 +2943,18 @@ export namespace TalerMerchantApi {
// URL of the exchange this coin was withdrawn from.
exchange_url: string;
}
- interface AbortResponse {
+ export interface AbortResponse {
// List of refund responses about the coins that the wallet
// requested an abort for. In the same order as the coins
// from the original request.
// The rtransaction_id is implied to be 0.
refunds: MerchantAbortPayRefundStatus[];
}
- type MerchantAbortPayRefundStatus =
+ export type MerchantAbortPayRefundStatus =
| MerchantAbortPayRefundSuccessStatus
| MerchantAbortPayRefundFailureStatus;
// Details about why a refund failed.
- interface MerchantAbortPayRefundFailureStatus {
+ export interface MerchantAbortPayRefundFailureStatus {
// Used as tag for the sum type RefundStatus sum type.
type: "failure";
@@ -2753,7 +2970,7 @@ export namespace TalerMerchantApi {
// Additional details needed to verify the refund confirmation signature
// (h_contract_terms and merchant_pub) are already known
// to the wallet and thus not included.
- interface MerchantAbortPayRefundSuccessStatus {
+ export interface MerchantAbortPayRefundSuccessStatus {
// Used as tag for the sum type MerchantCoinRefundStatus sum type.
type: "success";
@@ -2777,7 +2994,7 @@ export namespace TalerMerchantApi {
// wallet/customer).
h_contract: HashCode;
}
- interface WalletRefundResponse {
+ export interface WalletRefundResponse {
// Amount that was refunded in total.
refund_amount: AmountString;
@@ -2787,11 +3004,11 @@ export namespace TalerMerchantApi {
// Public key of the merchant.
merchant_pub: EddsaPublicKey;
}
- type MerchantCoinRefundStatus =
+ export type MerchantCoinRefundStatus =
| MerchantCoinRefundSuccessStatus
| MerchantCoinRefundFailureStatus;
// Details about why a refund failed.
- interface MerchantCoinRefundFailureStatus {
+ export interface MerchantCoinRefundFailureStatus {
// Used as tag for the sum type RefundStatus sum type.
type: "failure";
@@ -2821,7 +3038,7 @@ export namespace TalerMerchantApi {
// Additional details needed to verify the refund confirmation signature
// (h_contract_terms and merchant_pub) are already known
// to the wallet and thus not included.
- interface MerchantCoinRefundSuccessStatus {
+ export interface MerchantCoinRefundSuccessStatus {
// Used as tag for the sum type MerchantCoinRefundStatus sum type.
type: "success";
@@ -3031,7 +3248,7 @@ export namespace TalerMerchantApi {
deleted: boolean;
}
- interface QueryInstancesResponse {
+ export interface QueryInstancesResponse {
// Merchant name corresponding to this instance.
name: string;
@@ -3079,7 +3296,7 @@ export namespace TalerMerchantApi {
};
}
- interface AccountKycRedirects {
+ export interface AccountKycRedirects {
// Array of pending KYCs.
pending_kycs: MerchantAccountKycRedirect[];
@@ -3087,7 +3304,7 @@ export namespace TalerMerchantApi {
timeout_kycs: ExchangeKycTimeout[];
}
- interface MerchantAccountKycRedirect {
+ export interface MerchantAccountKycRedirect {
// URL that the user should open in a browser to
// proceed with the KYC process (as returned
// by the exchange's /kyc-check/ endpoint).
@@ -3105,7 +3322,7 @@ export namespace TalerMerchantApi {
payto_uri: PaytoString;
}
- interface ExchangeKycTimeout {
+ export interface ExchangeKycTimeout {
// Base URL of the exchange this is about.
exchange_url: string;
@@ -3135,11 +3352,13 @@ export namespace TalerMerchantApi {
credit_facade_credentials?: FacadeCredentials;
}
- type FacadeCredentials = NoFacadeCredentials | BasicAuthFacadeCredentials;
- interface NoFacadeCredentials {
+ export type FacadeCredentials =
+ | NoFacadeCredentials
+ | BasicAuthFacadeCredentials;
+ export interface NoFacadeCredentials {
type: "none";
}
- interface BasicAuthFacadeCredentials {
+ export interface BasicAuthFacadeCredentials {
type: "basic";
// Username to use to authenticate
@@ -3148,7 +3367,7 @@ export namespace TalerMerchantApi {
// Password to use to authenticate
password: string;
}
- interface AccountAddResponse {
+ export interface AccountAddResponse {
// Hash over the wire details (including over the salt).
h_wire: HashCode;
@@ -3171,11 +3390,11 @@ export namespace TalerMerchantApi {
credit_facade_credentials?: FacadeCredentials;
}
- interface AccountsSummaryResponse {
+ export interface AccountsSummaryResponse {
// List of accounts that are known for the instance.
accounts: BankAccountEntry[];
}
- interface BankAccountEntry {
+ export interface BankAccountEntry {
// payto:// URI of the account.
payto_uri: PaytoString;
@@ -3278,17 +3497,19 @@ export namespace TalerMerchantApi {
minimum_age?: Integer;
}
- interface InventorySummaryResponse {
+ export interface InventorySummaryResponse {
// List of products that are present in the inventory.
products: InventoryEntry[];
}
- interface InventoryEntry {
+ export interface InventoryEntry {
// Product identifier, as found in the product.
product_id: string;
+ // product_serial_id of the product in the database.
+ product_serial: Integer;
}
- interface ProductDetail {
+ export interface ProductDetail {
// Human-readable product description.
description: string;