Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions localenv/cloud-nine-wallet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ services:
KEY_ID: 7097F83B-CB84-469E-96C6-2141C72E22C0
OPERATOR_TENANT_ID: 438fa74a-fa7d-4317-9ced-dde32ece1787
CARD_SERVICE_URL: 'http://cloud-nine-wallet-card-service:3007'
CARD_WEBHOOK_SERVICE_URL: 'http://cloud-nine-wallet-card-service:3007/payment-event'
depends_on:
- shared-database
- shared-redis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ async function cancelOutgoingPayment(
: {})
}
})
.withGraphFetched('quote')
.withGraphFetched('[quote, cardDetails')
const asset = await deps.assetService.get(payment.quote.assetId)
if (asset) payment.quote.asset = asset

Expand Down Expand Up @@ -719,7 +719,7 @@ async function fundPayment(
tenantId
})
.forUpdate()
.withGraphFetched('quote')
.withGraphFetched('[quote, cardDetails]')
if (!payment) return FundingError.UnknownPayment

const asset = await deps.assetService.get(payment.quote.assetId)
Expand Down
2 changes: 2 additions & 0 deletions packages/card-service/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import cors from '@koa/cors'
import { createValidatorMiddleware, HttpMethod } from '@interledger/openapi'
import { PaymentContext } from './payment/types'
import { PaymentEventContext } from './payment/types'
import { PaymentRoutes } from './payment/routes'

export interface AppServices {
logger: Promise<Logger>
config: Promise<IAppConfig>
paymentRoutes: Promise<PaymentRoutes>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we can properly step into the functions

}

export type AppContainer = IocContract<AppServices>
Expand Down
27 changes: 11 additions & 16 deletions packages/point-of-sale/src/card-service-client/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ describe('CardServiceClient', () => {
expect(nock.isDone()).toBeTruthy()
})

const createPaymentResponse = (result?: Result): PaymentResponse => ({
const createPaymentResponse = (resultCode?: Result): PaymentResponse => ({
requestId: 'requestId',
result: result ?? Result.APPROVED
result: { code: resultCode || Result.APPROVED }
})

const options: SendPaymentArgs = {
Expand All @@ -46,20 +46,15 @@ describe('CardServiceClient', () => {
}
}

describe('returns the result', () => {
it.each`
result | code
${Result.APPROVED} | ${HttpStatusCode.Ok}
${Result.CARD_EXPIRED} | ${HttpStatusCode.Unauthorized}
${Result.INVALID_SIGNATURE} | ${HttpStatusCode.Unauthorized}
`('when the result is $result', async (response) => {
nock(CARD_SERVICE_URL)
.post('/payment')
.reply(response.code, createPaymentResponse(response.result))
expect(await client.sendPayment(CARD_SERVICE_URL, options)).toBe(
response.result
)
})
test('returns the result', async () => {
const resultCode = Result.APPROVED
nock(CARD_SERVICE_URL)
.post('/payment')
.reply(201, createPaymentResponse(resultCode))

await expect(client.sendPayment(CARD_SERVICE_URL, options)).resolves.toBe(
resultCode
)
})

test('throws when there is no payload data', async () => {
Expand Down
9 changes: 5 additions & 4 deletions packages/point-of-sale/src/card-service-client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ interface ServiceDependencies extends BaseService {

export enum Result {
APPROVED = 'approved',
CARD_EXPIRED = 'card_expired',
INVALID_SIGNATURE = 'invalid_signature'
}

export type PaymentResponse = {
requestId: string
result: Result
result: {
code: Result
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
Expand Down Expand Up @@ -97,14 +98,14 @@ async function sendPayment(
HttpStatusCode.NotFound
)
}
return payment.result
return payment.result.code
} catch (error) {
deps.logger.debug(error)
if (error instanceof CardServiceClientError) throw error

if (error instanceof AxiosError) {
if (isPaymentResponse(error.response?.data)) {
return error.response.data.result
return error.response.data.result.code
}
throw new CardServiceClientError(
error.response?.data ?? 'Unknown Axios error',
Expand Down
Loading