Skip to content

Commit

Permalink
Merge pull request #25 from XYOracleNetwork/feature/payment-receipts
Browse files Browse the repository at this point in the history
Payment Receipts
  • Loading branch information
JoelBCarter authored Apr 5, 2024
2 parents d10c383 + e044216 commit df57c32
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 8 deletions.
15 changes: 14 additions & 1 deletion packages/payload/packages/payments/src/Escrow/Terms.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address, Hash } from '@xylabs/hex'
import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'
import { isPayloadOfSchemaType, isPayloadOfSchemaTypeWithMeta, isPayloadOfSchemaTypeWithSources, Payload } from '@xyo-network/payload-model'

import { EscrowSchema } from './Schema'

Expand Down Expand Up @@ -59,4 +59,17 @@ export interface EscrowTermsFields {
*/
export type EscrowTerms = Payload<Partial<EscrowTermsFields>, EscrowTermsSchema>

/**
* Identity function for determining if an object is an EscrowTerms
*/
export const isEscrowTerms = isPayloadOfSchemaType<EscrowTerms>(EscrowTermsSchema)

/**
* Identity function for determining if an object is an EscrowTerms with sources
*/
export const isEscrowTermsWithSources = isPayloadOfSchemaTypeWithSources<EscrowTerms>(EscrowTermsSchema)

/**
* Identity function for determining if an object is an EscrowTerms with meta
*/
export const isEscrowTermsWithMeta = isPayloadOfSchemaTypeWithMeta<EscrowTerms>(EscrowTermsSchema)
22 changes: 20 additions & 2 deletions packages/payload/packages/payments/src/Payment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { isPayloadOfSchemaType, PayloadWithSources } from '@xyo-network/payload-model'
import {
isPayloadOfSchemaType,
isPayloadOfSchemaTypeWithMeta,
isPayloadOfSchemaTypeWithSources,
PayloadWithSources,
} from '@xyo-network/payload-model'

import { SupportedCurrency } from './Currency'

Expand All @@ -17,8 +22,21 @@ export interface PaymentFields {
}

/**
* A payment is a record of a payment made
* A payment is a record of an amount to be paid
*/
export type Payment = PayloadWithSources<PaymentFields, PaymentSchema>

/**
* Identity function for determine if an object is a Payment
*/
export const isPayment = isPayloadOfSchemaType<Payment>(PaymentSchema)

/**
* Identity function for determine if an object is a Payment with sources
*/
export const isPaymentWithSources = isPayloadOfSchemaTypeWithSources<Payment>(PaymentSchema)

/**
* Identity function for determine if an object is a Payment with meta
*/
export const isPaymentWithMeta = isPayloadOfSchemaTypeWithMeta<Payment>(PaymentSchema)
30 changes: 25 additions & 5 deletions packages/payload/packages/payments/src/Purchase.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
import { Hash } from '@xylabs/hex'
import { PayloadWithSources } from '@xyo-network/payload-model'
import {
isPayloadOfSchemaType,
isPayloadOfSchemaTypeWithMeta,
isPayloadOfSchemaTypeWithSources,
PayloadWithSources,
} from '@xyo-network/payload-model'

export type PurchaseSchema = 'network.xyo.payments.purchase'
export const PurchaseSchema: PurchaseSchema = 'network.xyo.payments.purchase'

export interface PurchaseFields {
/**
* The hashes that were purchased
* The things that were purchased
*/
hashes: Hash[]
assets: Hash[]
/**
* The payments for this purchase. Array to allow for multiple payments
* The receipts for payments for this purchase. Array to allow for multiple payments
* for a single quote.
*/
payments: Hash[]
receipts: Hash[]
}

/**
* A purchase ties a payment made to a quote
*/
export type Purchase = PayloadWithSources<PurchaseFields, PurchaseSchema>

/**
* Identity function for determine if an object is a Purchase
*/
export const isPurchase = isPayloadOfSchemaType<Purchase>(PurchaseSchema)

/**
* Identity function for determine if an object is a Purchase with sources
*/
export const isPurchaseWithSources = isPayloadOfSchemaTypeWithSources<Purchase>(PurchaseSchema)

/**
* Identity function for determine if an object is a Purchase with meta
*/
export const isPurchaseWithMeta = isPayloadOfSchemaTypeWithMeta<Purchase>(PurchaseSchema)
42 changes: 42 additions & 0 deletions packages/payload/packages/payments/src/Receipt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
isPayloadOfSchemaType,
isPayloadOfSchemaTypeWithMeta,
isPayloadOfSchemaTypeWithSources,
PayloadWithSources,
} from '@xyo-network/payload-model'

import { SupportedCurrency } from './Currency'

export type ReceiptSchema = 'network.xyo.payments.receipt'
export const ReceiptSchema: ReceiptSchema = 'network.xyo.payments.receipt'

export interface ReceiptFields {
/**
* The amount paid
*/
amount: number
/**
* The currency of the amount paid
*/
currency: SupportedCurrency
}

/**
* A receipt is a record of a payment made
*/
export type Receipt = PayloadWithSources<ReceiptFields, ReceiptSchema>

/**
* Identity function for determine if an object is a Receipt
*/
export const isReceipt = isPayloadOfSchemaType<Receipt>(ReceiptSchema)

/**
* Identity function for determine if an object is a Receipt with sources
*/
export const isReceiptWithSources = isPayloadOfSchemaTypeWithSources<Receipt>(ReceiptSchema)

/**
* Identity function for determine if an object is a Receipt with meta
*/
export const isReceiptWithMeta = isPayloadOfSchemaTypeWithMeta<Receipt>(ReceiptSchema)
1 change: 1 addition & 0 deletions packages/payload/packages/payments/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './Currency'
export * from './Escrow'
export * from './Payment'
export * from './Purchase'
export * from './Receipt'

0 comments on commit df57c32

Please sign in to comment.