diff --git a/localenv/mock-account-servicing-entity/generated/graphql.ts b/localenv/mock-account-servicing-entity/generated/graphql.ts index 66a0f79622..0e4dbb1b63 100644 --- a/localenv/mock-account-servicing-entity/generated/graphql.ts +++ b/localenv/mock-account-servicing-entity/generated/graphql.ts @@ -709,6 +709,8 @@ export type IncomingPaymentResponse = { }; export enum IncomingPaymentState { + /** The payment is cancelled before completion, and no further funds will be accepted. */ + Cancelled = 'CANCELLED', /** The payment is completed automatically once the expected `incomingAmount` is received or manually via an API call. */ Completed = 'COMPLETED', /** The payment has expired before completion, and no further funds will be accepted. */ diff --git a/packages/backend/src/graphql/generated/graphql.schema.json b/packages/backend/src/graphql/generated/graphql.schema.json index e1e634ff92..a133e9776e 100644 --- a/packages/backend/src/graphql/generated/graphql.schema.json +++ b/packages/backend/src/graphql/generated/graphql.schema.json @@ -4266,6 +4266,12 @@ "inputFields": null, "interfaces": null, "enumValues": [ + { + "name": "CANCELLED", + "description": "The payment is cancelled before completion, and no further funds will be accepted.", + "isDeprecated": false, + "deprecationReason": null + }, { "name": "COMPLETED", "description": "The payment is completed automatically once the expected `incomingAmount` is received or manually via an API call.", diff --git a/packages/backend/src/graphql/generated/graphql.ts b/packages/backend/src/graphql/generated/graphql.ts index 66a0f79622..0e4dbb1b63 100644 --- a/packages/backend/src/graphql/generated/graphql.ts +++ b/packages/backend/src/graphql/generated/graphql.ts @@ -709,6 +709,8 @@ export type IncomingPaymentResponse = { }; export enum IncomingPaymentState { + /** The payment is cancelled before completion, and no further funds will be accepted. */ + Cancelled = 'CANCELLED', /** The payment is completed automatically once the expected `incomingAmount` is received or manually via an API call. */ Completed = 'COMPLETED', /** The payment has expired before completion, and no further funds will be accepted. */ diff --git a/packages/backend/src/graphql/schema.graphql b/packages/backend/src/graphql/schema.graphql index de3c7a524f..34c9e7849d 100644 --- a/packages/backend/src/graphql/schema.graphql +++ b/packages/backend/src/graphql/schema.graphql @@ -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 { diff --git a/packages/backend/src/open_payments/payment/incoming/model.test.ts b/packages/backend/src/open_payments/payment/incoming/model.test.ts index d9a332c245..2dc3207a1d 100644 --- a/packages/backend/src/open_payments/payment/incoming/model.test.ts +++ b/packages/backend/src/open_payments/payment/incoming/model.test.ts @@ -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 => { incomingPayment.state = paymentState diff --git a/packages/backend/src/open_payments/payment/incoming/model.ts b/packages/backend/src/open_payments/payment/incoming/model.ts index 8a35c743b1..c69ecc2040 100644 --- a/packages/backend/src/open_payments/payment/incoming/model.ts +++ b/packages/backend/src/open_payments/payment/incoming/model.ts @@ -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 { @@ -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 { @@ -163,7 +169,8 @@ export class IncomingPayment }) .whereNotIn('state', [ IncomingPaymentState.Expired, - IncomingPaymentState.Completed + IncomingPaymentState.Completed, + IncomingPaymentState.Cancelled ]) } else { incomingPayment = await IncomingPayment.query() @@ -172,7 +179,8 @@ export class IncomingPayment }) .whereNotIn('state', [ IncomingPaymentState.Expired, - IncomingPaymentState.Completed + IncomingPaymentState.Completed, + IncomingPaymentState.Cancelled ]) } if (incomingPayment) { @@ -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 ) } diff --git a/packages/backend/src/open_payments/payment/incoming/service.test.ts b/packages/backend/src/open_payments/payment/incoming/service.test.ts index d01c72b7c0..ea08f4e5f9 100644 --- a/packages/backend/src/open_payments/payment/incoming/service.test.ts +++ b/packages/backend/src/open_payments/payment/incoming/service.test.ts @@ -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() }) @@ -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) }) diff --git a/packages/backend/src/open_payments/payment/incoming/service.ts b/packages/backend/src/open_payments/payment/incoming/service.ts index 1e07f445e4..8ddce21223 100644 --- a/packages/backend/src/open_payments/payment/incoming/service.ts +++ b/packages/backend/src/open_payments/payment/incoming/service.ts @@ -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 { @@ -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 }) } diff --git a/packages/card-service/src/graphql/generated/graphql.ts b/packages/card-service/src/graphql/generated/graphql.ts index ba49c0cfa9..28709e21ed 100644 --- a/packages/card-service/src/graphql/generated/graphql.ts +++ b/packages/card-service/src/graphql/generated/graphql.ts @@ -709,6 +709,8 @@ export type IncomingPaymentResponse = { }; export enum IncomingPaymentState { + /** The payment is cancelled before completion, and no further funds will be accepted. */ + Cancelled = 'CANCELLED', /** The payment is completed automatically once the expected `incomingAmount` is received or manually via an API call. */ Completed = 'COMPLETED', /** The payment has expired before completion, and no further funds will be accepted. */ diff --git a/packages/frontend/app/generated/graphql.ts b/packages/frontend/app/generated/graphql.ts index 93e817e0f0..b7d76d6c1d 100644 --- a/packages/frontend/app/generated/graphql.ts +++ b/packages/frontend/app/generated/graphql.ts @@ -709,6 +709,8 @@ export type IncomingPaymentResponse = { }; export enum IncomingPaymentState { + /** The payment is cancelled before completion, and no further funds will be accepted. */ + Cancelled = 'CANCELLED', /** The payment is completed automatically once the expected `incomingAmount` is received or manually via an API call. */ Completed = 'COMPLETED', /** The payment has expired before completion, and no further funds will be accepted. */ diff --git a/packages/mock-account-service-lib/src/generated/graphql.ts b/packages/mock-account-service-lib/src/generated/graphql.ts index 66a0f79622..0e4dbb1b63 100644 --- a/packages/mock-account-service-lib/src/generated/graphql.ts +++ b/packages/mock-account-service-lib/src/generated/graphql.ts @@ -709,6 +709,8 @@ export type IncomingPaymentResponse = { }; export enum IncomingPaymentState { + /** The payment is cancelled before completion, and no further funds will be accepted. */ + Cancelled = 'CANCELLED', /** The payment is completed automatically once the expected `incomingAmount` is received or manually via an API call. */ Completed = 'COMPLETED', /** The payment has expired before completion, and no further funds will be accepted. */ diff --git a/packages/point-of-sale/src/graphql/generated/graphql.ts b/packages/point-of-sale/src/graphql/generated/graphql.ts index a5a2ba76b2..e5d3e586ba 100644 --- a/packages/point-of-sale/src/graphql/generated/graphql.ts +++ b/packages/point-of-sale/src/graphql/generated/graphql.ts @@ -709,6 +709,8 @@ export type IncomingPaymentResponse = { }; export enum IncomingPaymentState { + /** The payment is cancelled before completion, and no further funds will be accepted. */ + Cancelled = 'CANCELLED', /** The payment is completed automatically once the expected `incomingAmount` is received or manually via an API call. */ Completed = 'COMPLETED', /** The payment has expired before completion, and no further funds will be accepted. */ diff --git a/test/test-lib/src/generated/graphql.ts b/test/test-lib/src/generated/graphql.ts index 66a0f79622..0e4dbb1b63 100644 --- a/test/test-lib/src/generated/graphql.ts +++ b/test/test-lib/src/generated/graphql.ts @@ -709,6 +709,8 @@ export type IncomingPaymentResponse = { }; export enum IncomingPaymentState { + /** The payment is cancelled before completion, and no further funds will be accepted. */ + Cancelled = 'CANCELLED', /** The payment is completed automatically once the expected `incomingAmount` is received or manually via an API call. */ Completed = 'COMPLETED', /** The payment has expired before completion, and no further funds will be accepted. */