Correct the TS interface for subtransactions

This commit is contained in:
Eric Schultz 2021-05-05 17:11:35 -05:00 committed by Eric Schultz
parent 51d97d6a78
commit 1d0b0f5af9
8 changed files with 69 additions and 38 deletions

View file

@ -1,11 +1,14 @@
// License: LGPL-3.0-or-later
import type { HoudiniEvent } from "../../../common";
import type { CommonOfflineTransactionPayment } from '.';
import type { PaymentAsId } from "..";
export interface Charge extends CommonOfflineTransactionPayment {
export interface ChargeAsId extends PaymentAsId {
object: 'offline_transaction_charge';
}
export type Charge = CommonOfflineTransactionPayment & ChargeAsId;
export type ChargeCreated = HoudiniEvent<'offline_transaction_charge.created', Charge>;
export type ChargeUpdated = HoudiniEvent<'offline_transaction_charge.updated', Charge>;
export type ChargeDeleted = HoudiniEvent<'offline_transaction_charge.deleted', Charge>;

View file

@ -1,10 +1,13 @@
// License: LGPL-3.0-or-later
import type { HoudiniEvent } from "../../../common";
import type { CommonOfflineTransactionPayment } from '.';
import type { PaymentAsId } from "..";
export interface Dispute extends CommonOfflineTransactionPayment {
export interface DisputeAsId extends PaymentAsId {
object: 'offline_transaction_dispute';
}
export type Dispute = CommonOfflineTransactionPayment & DisputeAsId;
export type DisputeCreated = HoudiniEvent<'offline_transaction_dispute.created', Dispute>;
export type DisputeUpdated = HoudiniEvent<'offline_transaction_dispute.updated', Dispute>;

View file

@ -1,11 +1,14 @@
// License: LGPL-3.0-or-later
import type { HoudiniEvent } from "../../../common";
import type { CommonOfflineTransactionPayment } from '.';
import type { PaymentAsId } from "..";
export interface Refund extends CommonOfflineTransactionPayment {
export interface RefundAsId extends PaymentAsId {
object: 'offline_transaction_refund';
}
export type Refund = CommonOfflineTransactionPayment & RefundAsId;
export type RefundCreated = HoudiniEvent<'offline_transaction_refund.created', Refund>;
export type RefundUpdated = HoudiniEvent<'offline_transaction_refund.updated', Refund>;
export type RefundDeleted = HoudiniEvent<'offline_transaction_refund.deleted', Refund>;

View file

@ -1,7 +1,7 @@
// License: LGPL-3.0-or-later
import type { HouID, HoudiniEvent } from "../../../common";
import type { Payment, Subtransaction} from "..";
import type { Charge, Refund, Dispute } from '.';
import type { Charge, Refund, Dispute, ChargeAsId, DisputeAsId, RefundAsId } from '.';
export interface CommonOfflineTransactionPayment extends Payment {
// The kind of offline charge. Could be cash, check or something else
@ -14,11 +14,9 @@ export interface CommonOfflineTransactionPayment extends Payment {
}
export default interface OfflineTransaction extends Subtransaction {
charges: HouID[] | Charge[];
deleted: boolean;
disputes: HouID[] | Dispute[];
object: 'offline_transaction';
refunds: HouID[] | Refund[];
payments: (ChargeAsId|RefundAsId|DisputeAsId)[]| (Charge|Refund|Dispute)[];
}
export type OfflineTransactionCreated = HoudiniEvent<'offline_transaction.created', OfflineTransaction>;

View file

@ -1,11 +1,15 @@
// License: LGPL-3.0-or-later
import type { Amount, HoudiniObject, HouID, HoudiniEvent } from "../../common";
import type { Amount, HouID, HoudiniEvent, PolymorphicID } from "../../common";
import type { Subtransaction, TrxDescendent } from ".";
export interface Payment extends HoudiniObject<HouID>, TrxDescendent {
export interface PaymentAsId extends PolymorphicID<HouID> {
type: 'payment';
}
export interface Payment extends PaymentAsId, TrxDescendent {
created: number;
deleted: boolean;
fees: Amount;
fee_total: Amount;
gross_amount: Amount;
net_amount: Amount;
status: string;

View file

@ -0,0 +1,19 @@
// License: LGPL-3.0-or-later
import type { Amount, HouID, HoudiniEvent, PolymorphicID } from "../../common";
import type { Payment, PaymentAsId, TrxDescendent } from ".";
export interface SubtransactionAsId extends PolymorphicID<HouID> {
type: 'subtransaction';
}
export interface Subtransaction extends SubtransactionAsId, TrxDescendent {
created: number;
initial_amount: Amount;
net_amount: Amount;
payments: PaymentAsId[]|Payment[];
}
export type SubtransactionCreated = HoudiniEvent<'subtransaction.created', Subtransaction>;
export type SubtransactionUpdated = HoudiniEvent<'subtransaction.updated', Subtransaction>;
export type SubtransactionDeleted = HoudiniEvent<'subtransaction.deleted', Subtransaction>;

View file

@ -1,19 +1,9 @@
// License: LGPL-3.0-or-later
import type { Amount, HoudiniObject, IDType, HouID, HoudiniEvent } from "../../common";
import type { Amount, HoudiniObject, IDType, HouID, HoudiniEvent, PolymorphicID } from "../../common";
import type Nonprofit from '../';
import type Supporter from "../Supporter";
import type { Payment } from "./Payment";
export interface Subtransaction extends HoudiniObject<HouID>, TrxDescendent {
amount: Amount;
amount_disputed: Amount;
amount_pending: Amount;
amount_refunded: Amount;
created: number;
fee_total: Amount;
net_amount: Amount;
type: 'subtransaction';
}
import type { Payment, PaymentAsId } from "./Payment";
import type { SubtransactionAsId, Subtransaction } from "./Subtransaction";
/**
* Every descendent of a Transaction object will have the following three fields
@ -37,30 +27,21 @@ export interface TrxDescendent {
* Every transaction assignment, including Donation, TicketPurchase, CampaignGiftPurchase
* must have an amount and the type 'trx_assignment' set.
*/
export interface TrxAssignment extends HoudiniObject<HouID>, TrxDescendent {
export interface TrxAssignment extends TrxAssignmentAsId, TrxDescendent {
amount: Amount;
type: 'trx_assignment';
}
export interface TrxAssignmentAsId extends HoudiniObject<HouID> {
export interface TrxAssignmentAsId extends PolymorphicID<HouID> {
type: 'trx_assignment';
}
export interface SubtransactionAsId extends HoudiniObject<HouID> {
type: 'subtransaction';
}
export default interface Transaction extends HoudiniObject<HouID> {
amount: Amount;
// amount_disputed: Amount;
// amount_refunded: Amount;
created: number;
deleted: boolean;
// net_amount: Amount;
nonprofit: IDType | Nonprofit;
object: 'transaction';
payments: PaymentAsId[] | Payment[];
subtransaction: SubtransactionAsId | Subtransaction;
subtransaction_payments: IDType[] | Payment[];
supporter: IDType | Supporter;
transaction_assignments: TrxAssignmentAsId[] | TrxAssignment[];
}
@ -73,5 +54,6 @@ export type TransactionDeleted = HoudiniEvent<'transaction.deleted', Transaction
export * from './Payment';
export * from './Donation';
export * from './OfflineTransaction';
export * from './Subtransaction';
export * as OfflineTransactionTypes from './OfflineTransaction';
export {default as OfflineTransaction} from './OfflineTransaction';

View file

@ -60,7 +60,7 @@ export type RecurrenceRule = {
* Every object controlled by the Houdini event publisher must meet this standard interface
* and will inherit from it.
*/
export interface HoudiniObject<ID extends IDType|HouID=IDType> {
export interface HoudiniObject<ID extends IDType | HouID = IDType> {
/**
* An IDType which unique which uniquely identifies this object
* from all other similar objects
@ -72,7 +72,26 @@ export interface HoudiniObject<ID extends IDType|HouID=IDType> {
object: string;
}
export type PolymorphicID<ID extends IDType|HouID=IDType> = HoudiniObject<ID>;
/**
* Used to identify objects when the field they're assigned too isn't enough to know what type of object they are.
* As an example on a transaction object, you'll have a field called "subtransaction". That could be any subtransaction object, for example, an
* `offline_transaction` or a `stripe_transaction`. We don't have enough information using the field name to tell us EXACTLY what type of field this is.
* There for we provide the following JSON object:
*
* {
* id: <the id of the object>,
* object: <the object type>,
* type: 'subtransaction',
* }
*
*
*
*
*/
export interface PolymorphicID<ID extends IDType | HouID = IDType> extends HoudiniObject<ID> {
/** the subtype of the object */
type: string;
}
type HoudiniObjectOfAllIDs = HoudiniObject<IDType> | HoudiniObject<HouID>;
/**