-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
662/mk/use open payments types #1024
Changes from 5 commits
c3ccd88
3415f5f
4693a79
c633b30
909462a
8feaacb
5300073
01a0ba0
36d8b8e
d04f994
379aee8
11fa542
27cfdde
4efddb3
dc051ec
0fddf9e
ad57048
d48dc0a
9302bad
5e5d4e8
25972d3
4800c80
cf95410
9a967f1
e5f3c03
5733224
28a34df
5e95486
b6d25c6
09a0c10
c079942
c55e586
fc311e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import { Model, ModelOptions, Pojo, QueryContext } from 'objection' | |
import { v4 as uuid } from 'uuid' | ||
|
||
import { Amount, AmountJSON, serializeAmount } from '../../amount' | ||
import { Connection, ConnectionJSON } from '../../connection/model' | ||
import { Connection } from '../../connection/model' | ||
import { | ||
PaymentPointer, | ||
PaymentPointerSubresource | ||
|
@@ -11,7 +11,11 @@ import { Asset } from '../../../asset/model' | |
import { LiquidityAccount, OnCreditOptions } from '../../../accounting/service' | ||
import { ConnectorAccount } from '../../../connector/core/rafiki' | ||
import { WebhookEvent } from '../../../webhook/model' | ||
import { IncomingPayment as OpenPaymentsIncomingPayment } from 'open-payments' | ||
import { | ||
IncomingPayment as OpenPaymentsIncomingPayment, | ||
IncomingPaymentWithConnection as OpenPaymentsIncomingPaymentWithConnection, | ||
IncomingPaymentWithConnectionUrl as OpenPaymentsIncomingPaymentWithConnectionUrl | ||
} from 'open-payments' | ||
|
||
export enum IncomingPaymentEventType { | ||
IncomingPaymentExpired = 'incoming_payment.expired', | ||
|
@@ -239,12 +243,13 @@ export class IncomingPayment | |
return payment | ||
} | ||
|
||
public toOpenPaymentsType({ | ||
ilpStreamConnection | ||
}: { | ||
ilpStreamConnection: Connection | ||
}): OpenPaymentsIncomingPayment { | ||
return { | ||
public toOpenPaymentsType( | ||
ilpStreamConnection: Connection | string | undefined | ||
): | ||
| OpenPaymentsIncomingPayment | ||
| OpenPaymentsIncomingPaymentWithConnection | ||
| OpenPaymentsIncomingPaymentWithConnectionUrl { | ||
const baseIncomingPayment: OpenPaymentsIncomingPayment = { | ||
id: this.url, | ||
paymentPointer: this.paymentPointer.url, | ||
incomingAmount: this.incomingAmount | ||
|
@@ -254,24 +259,23 @@ export class IncomingPayment | |
completed: this.completed, | ||
createdAt: this.createdAt.toISOString(), | ||
updatedAt: this.updatedAt.toISOString(), | ||
expiresAt: this.expiresAt.toISOString(), | ||
ilpStreamConnection: ilpStreamConnection.toOpenPaymentsType() | ||
expiresAt: this.expiresAt.toISOString() | ||
} | ||
} | ||
} | ||
|
||
// TODO: disallow undefined | ||
// https://github.com/interledger/rafiki/issues/594 | ||
export type IncomingPaymentJSON = { | ||
id: string | ||
paymentPointer: string | ||
incomingAmount?: AmountJSON | ||
receivedAmount: AmountJSON | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wilsonianb Keeping There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I'm good with keeping amount values as strings in |
||
completed: boolean | ||
description?: string | ||
externalRef?: string | ||
createdAt: string | ||
updatedAt: string | ||
expiresAt?: string | ||
ilpStreamConnection?: ConnectionJSON | string | ||
if (!ilpStreamConnection) { | ||
return baseIncomingPayment | ||
} | ||
|
||
if (typeof ilpStreamConnection === 'string') { | ||
return { | ||
...baseIncomingPayment, | ||
ilpStreamConnection | ||
} | ||
} | ||
|
||
return { | ||
...baseIncomingPayment, | ||
ilpStreamConnection: ilpStreamConnection.toOpenPaymentsType().id | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to suggest adding an abstract
toOpenPaymentsType
toPaymentPointerSubresource
but this one for incoming payments would complicate itrafiki/packages/backend/src/open_payments/payment_pointer/model.ts
Line 165 in 16a4f82