import { isly } from "isly" import { Acquirer } from "../../Acquirer" import { Amount } from "../../Amount" import { Merchant } from "../../Merchant" import { Exchange } from "../../Transaction/Exchange" import { Batch } from "../Batch" import { Fee } from "../Fee" import { Identifier as SettlementIdentifier } from "../Identifier" export type Creatable = Creatable.Known | Creatable.Unknown export namespace Creatable { export interface Base { card: string transaction?: string transactionReference?: string account: string approvalCode: string merchant: Merchant acquirer: Acquirer reference: string batch: Batch fee: Fee amount: Amount settlement: SettlementIdentifier exchange?: Exchange } export namespace Base { export const type = isly.object({ card: isly.string(), transaction: isly.string().optional(), transactionReference: isly.string().optional(), account: isly.string(), approvalCode: isly.string(), merchant: Merchant.type, acquirer: Acquirer.type, reference: isly.string(), batch: Batch.type, fee: Fee.type, amount: Amount.type, settlement: SettlementIdentifier.type, exchange: Exchange.type.optional(), }) } export interface Capture extends Base { type: "capture" } export namespace Capture { export const type = Base.type.extend({ type: isly.string("capture") }) } export interface Refund extends Base { type: "refund" } export namespace Refund { export const type = Base.type.extend({ type: isly.string("refund") }) } export type Known = Capture | Refund export namespace Known { export const type = isly.union(Capture.type, Refund.type) } export interface Unknown extends Partial { type: "unknown" data: Record } export namespace Unknown { export const type = isly.object({ ...(Object.fromEntries( Object.entries(Base.type.getProperties()).map(([k, v]) => [k, v.optional()]) ) as isly.object.Properties>), // TODO: Add "Partial" to isly type: isly.string("unknown"), data: isly.record>(isly.string(), isly.any()), }) } export const type = isly.union(Known.type, Unknown.type) }