Skip to content

Commit

Permalink
feat: remove walletAddress from complete incoming payment context
Browse files Browse the repository at this point in the history
  • Loading branch information
njlie committed Oct 19, 2023
1 parent 3ebbdc0 commit 4ad3cdb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 0 additions & 1 deletion packages/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ export class App {
// Complete incoming payment
router.post<DefaultState, SignedSubresourceContext>(
'/incoming-payments/:id/complete',
createWalletAddressMiddleware(),
createValidatorMiddleware<ContextType<SignedSubresourceContext>>(
resourceServerSpec,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ describe('Incoming Payment Routes', (): void => {
describe('get unauthenticated incoming payment', (): void => {
test('Can get incoming payment with public fields', async (): Promise<void> => {
const incomingPayment = await createIncomingPayment(deps, {
paymentPointerId: paymentPointer.id,
walletAddressId: walletAddress.id,
expiresAt,
incomingAmount,
metadata
Expand All @@ -312,7 +312,7 @@ describe('Incoming Payment Routes', (): void => {
params: {
id: incomingPayment.id
},
paymentPointer
walletAddress
})
ctx.authenticated = false

Expand Down
15 changes: 12 additions & 3 deletions packages/backend/src/open_payments/payment/incoming/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async function getIncomingPaymentPublic(
const incomingPayment = await deps.incomingPaymentService.get({
id: ctx.params.id,
client: ctx.accessAction === AccessAction.Read ? ctx.client : undefined,
paymentPointerId: ctx.paymentPointer.id
walletAddressId: ctx.walletAddress.id
})
ctx.body = incomingPayment?.toPublicOpenPaymentsType()
} catch (err) {
Expand Down Expand Up @@ -147,10 +147,14 @@ async function createIncomingPayment(
)
}

if (!incomingPaymentOrError.walletAddress) {
ctx.throw(404)
}

ctx.status = 201
const connection = deps.connectionService.get(incomingPaymentOrError)
ctx.body = incomingPaymentToBody(
ctx.walletAddress,
incomingPaymentOrError.walletAddress,
incomingPaymentOrError,
connection
)
Expand All @@ -175,7 +179,12 @@ async function completeIncomingPayment(
errorToMessage[incomingPaymentOrError]
)
}
ctx.body = incomingPaymentToBody(ctx.walletAddress, incomingPaymentOrError)

if (!incomingPaymentOrError.walletAddress) {
ctx.throw(404)
}

ctx.body = incomingPaymentToBody(incomingPaymentOrError.walletAddress, incomingPaymentOrError)
}

async function listIncomingPayments(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function createWalletAddressMiddleware() {
ctx.throw(401)
}
} else {
ctx.walletAddressUrl = `https://${ctx.request.host}/${ctx.params.paymentPointerPath}`
ctx.walletAddressUrl = `https://${ctx.request.host}/${ctx.params.walletAddressPath}`
}
const config = await ctx.container.use('config')
if (ctx.walletAddressUrl !== config.walletAddressUrl) {
Expand Down

0 comments on commit 4ad3cdb

Please sign in to comment.