Skip to content

Commit f49eaa9

Browse files
sanducbmkurapov
andauthored
feat(card-service): handle payment cancelled & funded events (#3667)
* feat(card-service): handle payment cancelled & funded events * feat(card-service): fix tests * fix: updates to make e2e payment flow work (#3668) * chore(localenv): add CARD_WEBHOOK_SERVICE_URL to cloud nine wallet backend * feat(backend): fetch cardDetails during outgoing payment funded and cancelled * chore(pos): correctly handle response from card service * test(pos): update card service client test * chore(card-service): add paymentRoutes to AppServices * chore(backend): fix withGraphFetched query * test(pos): remove unused test * fix(card-service): update payment result type * chore(card-service): format --------- Co-authored-by: Max Kurapov <[email protected]>
1 parent ba2e599 commit f49eaa9

File tree

23 files changed

+483
-133
lines changed

23 files changed

+483
-133
lines changed

localenv/cloud-nine-wallet/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ services:
156156
KEY_ID: 7097F83B-CB84-469E-96C6-2141C72E22C0
157157
OPERATOR_TENANT_ID: 438fa74a-fa7d-4317-9ced-dde32ece1787
158158
CARD_SERVICE_URL: 'http://cloud-nine-wallet-card-service:3007'
159+
CARD_WEBHOOK_SERVICE_URL: 'http://cloud-nine-wallet-card-service:3007/payment-event'
159160
depends_on:
160161
- shared-database
161162
- shared-redis

localenv/mock-account-servicing-entity/generated/graphql.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/backend/src/graphql/generated/graphql.schema.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/backend/src/graphql/generated/graphql.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/backend/src/graphql/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,7 @@ input CancelOutgoingPaymentInput {
12521252

12531253
enum CardPaymentFailureReason {
12541254
invalid_signature
1255+
invalid_request
12551256
}
12561257

12571258
input CreateOutgoingPaymentFromIncomingPaymentInput {

packages/backend/src/open_payments/payment/outgoing/service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export type CancelOutgoingPaymentOptions = {
213213
id: string
214214
tenantId: string
215215
reason?: string
216-
cardPaymentFailureReason?: 'invalid_signature'
216+
cardPaymentFailureReason?: 'invalid_signature' | 'invalid_request'
217217
}
218218

219219
export type CreateOutgoingPaymentOptions =
@@ -264,7 +264,7 @@ async function cancelOutgoingPayment(
264264
: {})
265265
}
266266
})
267-
.withGraphFetched('quote')
267+
.withGraphFetched('[quote, cardDetails]')
268268
const asset = await deps.assetService.get(payment.quote.assetId)
269269
if (asset) payment.quote.asset = asset
270270

@@ -719,7 +719,7 @@ async function fundPayment(
719719
tenantId
720720
})
721721
.forUpdate()
722-
.withGraphFetched('quote')
722+
.withGraphFetched('[quote, cardDetails]')
723723
if (!payment) return FundingError.UnknownPayment
724724

725725
const asset = await deps.assetService.get(payment.quote.assetId)

packages/card-service/src/app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import cors from '@koa/cors'
99
import { createValidatorMiddleware, HttpMethod } from '@interledger/openapi'
1010
import { PaymentContext } from './payment/types'
1111
import { PaymentEventContext } from './payment/types'
12+
import { PaymentRoutes } from './payment/routes'
1213

1314
export interface AppServices {
1415
logger: Promise<Logger>
1516
config: Promise<IAppConfig>
17+
paymentRoutes: Promise<PaymentRoutes>
1618
}
1719

1820
export type AppContainer = IocContract<AppServices>

packages/card-service/src/graphql/generated/graphql.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/card-service/src/openapi/specs/card-server.yaml

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,46 @@ paths:
5454
application/json:
5555
schema:
5656
type: object
57+
required:
58+
- requestId
59+
- result
5760
properties:
5861
requestId:
5962
type: string
63+
format: uuid
6064
result:
61-
type: string
62-
enum:
63-
- approved
65+
type: object
66+
required:
67+
- code
68+
properties:
69+
code:
70+
type: string
71+
enum:
72+
- approved
73+
- invalid_signature
74+
description:
75+
type: string
6476
'400':
6577
description: Invalid request
66-
'401':
67-
description: Card expired or invalid signature
78+
content:
79+
application/json:
80+
schema:
81+
type: object
82+
required:
83+
- error
84+
properties:
85+
error:
86+
type: object
87+
required:
88+
- code
89+
- description
90+
properties:
91+
code:
92+
type: string
93+
enum:
94+
- invalid_request
95+
description:
96+
type: string
6897
'500':
6998
description: Internal server error
7099
/payment-event:
@@ -78,31 +107,54 @@ paths:
78107
schema:
79108
type: object
80109
required:
81-
- requestId
82-
- outgoingPaymentId
83-
- result
110+
- id
111+
- type
112+
- data
84113
properties:
85-
requestId:
114+
id:
86115
type: string
87116
format: uuid
88-
outgoingPaymentId:
117+
type:
89118
type: string
90-
format: uuid
91-
result:
119+
enum:
120+
- outgoing_payment.funded
121+
- outgoing_payment.cancelled
122+
data:
92123
type: object
93124
required:
94-
- code
125+
- id
126+
- cardDetails
95127
properties:
96-
code:
128+
id:
97129
type: string
98-
enum:
99-
- completed
100-
- card_expired
101-
- invalid_signature
130+
format: uuid
131+
cardDetails:
132+
type: object
133+
required:
134+
- requestId
135+
properties:
136+
requestId:
137+
type: string
138+
format: uuid
139+
initiatedAt:
140+
type: string
141+
format: date-time
142+
data:
143+
type: object
144+
additionalProperties: true
145+
additionalProperties: true
146+
metadata:
147+
type: object
148+
properties:
149+
cardPaymentFailureReason:
150+
type: string
151+
enum:
152+
- invalid_signature
153+
- invalid_request
154+
additionalProperties: true
155+
additionalProperties: true
102156
responses:
103-
'202':
104-
description: Payment event accepted and forwarded
157+
'200':
158+
description: Payment event accepted
105159
'400':
106160
description: Malformed request body
107-
'404':
108-
description: Request not found

0 commit comments

Comments
 (0)