Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions localenv/mock-account-servicing-entity/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/backend/src/graphql/generated/graphql.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/backend/src/graphql/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/backend/src/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,8 @@ enum IncomingPaymentState {
COMPLETED
"The payment has expired before completion, and no further funds will be accepted."
EXPIRED
"The payment is cancelled before completion, and no further funds will be accepted."
CANCELLED
}

type Amount {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ describe('Models', (): void => {
})
})

test.each([IncomingPaymentState.Completed, IncomingPaymentState.Expired])(
test.each([
IncomingPaymentState.Completed,
IncomingPaymentState.Expired,
IncomingPaymentState.Cancelled
])(
'returns incoming payment with existing methods if payment state is %s',
async (paymentState): Promise<void> => {
incomingPayment.state = paymentState
Expand Down
19 changes: 14 additions & 5 deletions packages/backend/src/open_payments/payment/incoming/model.ts
Comment thread
Freedisch marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export enum IncomingPaymentState {
Completed = 'COMPLETED',
// If the payment expires before it is completed then the state will move to `EXPIRED`
// and no further payments will be accepted.
Expired = 'EXPIRED'
Expired = 'EXPIRED',
// If the payment is cancelled before it is completed then the state will move to `CANCELLED`
// and no further payments will be accepted.
Cancelled = 'CANCELLED'
}

export interface IncomingPaymentResponse {
Expand Down Expand Up @@ -116,7 +119,10 @@ export class IncomingPayment
public cancellationReason?: string | null

public get completed(): boolean {
return this.state === IncomingPaymentState.Completed
return (
this.state === IncomingPaymentState.Completed ||
this.state === IncomingPaymentState.Cancelled
)
}

public get incomingAmount(): Amount | undefined {
Expand Down Expand Up @@ -163,7 +169,8 @@ export class IncomingPayment
})
.whereNotIn('state', [
IncomingPaymentState.Expired,
IncomingPaymentState.Completed
IncomingPaymentState.Completed,
IncomingPaymentState.Cancelled
])
} else {
incomingPayment = await IncomingPayment.query()
Expand All @@ -172,7 +179,8 @@ export class IncomingPayment
})
.whereNotIn('state', [
IncomingPaymentState.Expired,
IncomingPaymentState.Completed
IncomingPaymentState.Completed,
IncomingPaymentState.Cancelled
])
}
if (incomingPayment) {
Expand All @@ -184,7 +192,8 @@ export class IncomingPayment
public isExpiredOrComplete(): boolean {
return (
this.state === IncomingPaymentState.Expired ||
this.state === IncomingPaymentState.Completed
this.state === IncomingPaymentState.Completed ||
this.state === IncomingPaymentState.Cancelled
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ describe('Incoming Payment Service', (): void => {
assert.ok(!isIncomingPaymentError(canceledIncomingPayment))
expect(canceledIncomingPayment.id).toBe(incomingPayment.id)
expect(canceledIncomingPayment.cancelledAt).toBeDefined()
expect(canceledIncomingPayment.state).toBe(
IncomingPaymentState.Cancelled
)
expect(!canceledIncomingPayment.approvedAt).toBeTruthy()
})

Expand All @@ -330,6 +333,9 @@ describe('Incoming Payment Service', (): void => {
assert.ok(!isIncomingPaymentError(canceledIncomingPayment))
expect(canceledIncomingPayment.id).toBe(incomingPayment.id)
expect(canceledIncomingPayment.cancelledAt).toBeDefined()
expect(canceledIncomingPayment.state).toBe(
IncomingPaymentState.Cancelled
)
expect(!canceledIncomingPayment.approvedAt).toBeTruthy()
expect(canceledIncomingPayment.cancellationReason).toBe(reason)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ async function processNextIncomingPayment(
}
if (
incomingPayment.state === IncomingPaymentState.Expired ||
incomingPayment.state === IncomingPaymentState.Completed
incomingPayment.state === IncomingPaymentState.Completed ||
incomingPayment.state === IncomingPaymentState.Cancelled
) {
await handleDeactivated(deps, incomingPayment)
} else {
Expand Down Expand Up @@ -512,7 +513,8 @@ async function cancelIncomingPayment(
if (!payment.cancelledAt) {
await payment.$query(trx).patch({
cancelledAt: new Date(Date.now()),
cancellationReason: cancellationReason
cancellationReason: cancellationReason,
state: IncomingPaymentState.Cancelled
Comment thread
Freedisch marked this conversation as resolved.
})
}

Expand Down
2 changes: 2 additions & 0 deletions packages/card-service/src/graphql/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/frontend/app/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/mock-account-service-lib/src/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/point-of-sale/src/graphql/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/test-lib/src/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading