-
Notifications
You must be signed in to change notification settings - Fork 96
663/mk/create outgoing payment #807
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
Changes from all commits
b13bdc8
27078fd
604d4b9
5449605
2813395
8f039a3
4f9ac7b
68c8154
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 |
---|---|---|
@@ -1,15 +1,22 @@ | ||
import { HttpMethod, ResponseValidator } from 'openapi' | ||
import { BaseDeps, RouteDeps } from '.' | ||
import { getRSPath, OutgoingPayment } from '../types' | ||
import { get } from './requests' | ||
import { CreateOutgoingPaymentArgs, getRSPath, OutgoingPayment } from '../types' | ||
import { get, post } from './requests' | ||
|
||
interface GetArgs { | ||
url: string | ||
accessToken: string | ||
} | ||
|
||
interface PostArgs<T> { | ||
url: string | ||
body: T | ||
accessToken: string | ||
} | ||
|
||
export interface OutgoingPaymentRoutes { | ||
get(args: GetArgs): Promise<OutgoingPayment> | ||
create(args: PostArgs<CreateOutgoingPaymentArgs>): Promise<OutgoingPayment> | ||
} | ||
|
||
export const createOutgoingPaymentRoutes = ( | ||
|
@@ -23,12 +30,24 @@ export const createOutgoingPaymentRoutes = ( | |
method: HttpMethod.GET | ||
}) | ||
|
||
const createOutgoingPaymentOpenApiValidator = | ||
openApi.createResponseValidator<OutgoingPayment>({ | ||
path: getRSPath('/outgoing-payments'), | ||
method: HttpMethod.POST | ||
}) | ||
|
||
return { | ||
get: (args: GetArgs) => | ||
getOutgoingPayment( | ||
{ axiosInstance, logger }, | ||
args, | ||
getOutgoingPaymentOpenApiValidator | ||
), | ||
create: (args: PostArgs<CreateOutgoingPaymentArgs>) => | ||
createOutgoingPayment( | ||
{ axiosInstance, logger }, | ||
args, | ||
createOutgoingPaymentOpenApiValidator | ||
) | ||
} | ||
} | ||
|
@@ -39,11 +58,35 @@ export const getOutgoingPayment = async ( | |
validateOpenApiResponse: ResponseValidator<OutgoingPayment> | ||
) => { | ||
const { axiosInstance, logger } = deps | ||
const { url } = args | ||
const { url, accessToken } = args | ||
|
||
const outgoingPayment = await get( | ||
{ axiosInstance, logger }, | ||
args, | ||
{ url, accessToken }, | ||
validateOpenApiResponse | ||
) | ||
|
||
try { | ||
return validateOutgoingPayment(outgoingPayment) | ||
} catch (error) { | ||
const errorMessage = 'Could not validate outgoing payment' | ||
logger.error({ url, validateError: error?.message }, errorMessage) | ||
|
||
throw new Error(errorMessage) | ||
} | ||
} | ||
|
||
export const createOutgoingPayment = async ( | ||
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. Here the only other validation I could think of doing on a newly created outgoing payment (that wasn't already covered in 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 agree that does somehow seem less concerning than a non-zero |
||
deps: BaseDeps, | ||
args: PostArgs<CreateOutgoingPaymentArgs>, | ||
validateOpenApiResponse: ResponseValidator<OutgoingPayment> | ||
) => { | ||
const { axiosInstance, logger } = deps | ||
const { url, body, accessToken } = args | ||
|
||
const outgoingPayment = await post( | ||
{ axiosInstance, logger }, | ||
{ url, body, accessToken }, | ||
validateOpenApiResponse | ||
) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
This is a guess about the desired behaviour
the main issue here was using
||
instead of??
. When we call this function just above:rafiki/packages/backend/src/open_payments/payment/outgoing/service.ts
Line 160 in cbbc416
we pass in
value: BigInt(0)
.BigInt(0)
is falsy, so we end up callingdeps.accountingService.getTotalSent(payment.id))
even though we actually just wanted to setsent
to be 0.