Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(24831): cancel pending payment #40

Merged
merged 4 commits into from
Jan 27, 2025
Merged
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
192 changes: 192 additions & 0 deletions apps/payments-api/openapi-definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2220,9 +2220,18 @@ paths:
- type: string
enum:
- cancelled
- type: string
enum:
- cancellation_requested
- type: string
enum:
- failed
- type: string
enum:
- refunded
- type: string
enum:
- refund_failed
amount:
minimum: 1
maximum: 1000000
Expand Down Expand Up @@ -2386,9 +2395,18 @@ paths:
- type: string
enum:
- cancelled
- type: string
enum:
- cancellation_requested
- type: string
enum:
- failed
- type: string
enum:
- refunded
- type: string
enum:
- refund_failed
amount:
minimum: 1
maximum: 1000000
Expand Down Expand Up @@ -2556,9 +2574,18 @@ paths:
- type: string
enum:
- cancelled
- type: string
enum:
- cancellation_requested
- type: string
enum:
- failed
- type: string
enum:
- refunded
- type: string
enum:
- refund_failed
required:
- status
required: true
Expand Down Expand Up @@ -2755,9 +2782,18 @@ paths:
- type: string
enum:
- cancelled
- type: string
enum:
- cancellation_requested
- type: string
enum:
- failed
- type: string
enum:
- refunded
- type: string
enum:
- refund_failed
amount:
minimum: 1
maximum: 1000000
Expand Down Expand Up @@ -3341,9 +3377,18 @@ paths:
- type: string
enum:
- cancelled
- type: string
enum:
- cancellation_requested
- type: string
enum:
- failed
- type: string
enum:
- refunded
- type: string
enum:
- refund_failed
createdAt:
type: string
updatedAt:
Expand Down Expand Up @@ -3921,6 +3966,135 @@ paths:
- detail
- requestId
- name
/api/v1/transactions/{transactionId}/cancel-payment:
post:
parameters:
- schema:
type: string
in: path
name: transactionId
required: true
responses:
"200":
description: Default Response
content:
application/json:
schema:
type: object
properties:
data:
type: object
properties:
success:
type: boolean
required:
- success
metadata:
type: object
properties:
links:
description: Object containing the links to the related endpoints
type: object
properties:
self:
type: object
properties:
href:
description: URL pointing to the request itself
type: string
next:
type: object
properties:
href:
description: URL pointing to the next page of results in a paginated response.
If there are no more results, this field may
be omitted
type: string
prev:
type: object
properties:
href:
description: URL pointing to the previous page of results in a paginated
response. If there are no more results, this
field may be omitted
type: string
first:
type: object
properties:
href:
description: URL pointing to the first page of results in a paginated response
type: string
last:
type: object
properties:
href:
description: URL pointing to the first page of results in a paginated response
type: string
pages:
description: It may contain a list of other useful URLs, e.g. one entry for
page:'page 1', 'page 2'
type: object
additionalProperties:
type: object
properties:
href:
type: string
required:
- self
- first
- last
- pages
totalCount:
description: Number representing the total number of available items
type: number
required:
- data
"401":
description: Default Response
content:
application/json:
schema:
type: object
properties:
code:
type: string
detail:
type: string
requestId:
type: string
name:
type: string
validation: {}
validationContext:
type: string
required:
- code
- detail
- requestId
- name
"500":
description: Default Response
content:
application/json:
schema:
type: object
properties:
code:
type: string
detail:
type: string
requestId:
type: string
name:
type: string
validation: {}
validationContext:
type: string
required:
- code
- detail
- requestId
- name
/api/v1/citizen/transactions:
get:
tags:
Expand Down Expand Up @@ -3971,9 +4145,18 @@ paths:
- type: string
enum:
- cancelled
- type: string
enum:
- cancellation_requested
- type: string
enum:
- failed
- type: string
enum:
- refunded
- type: string
enum:
- refund_failed
title:
type: string
updatedAt:
Expand Down Expand Up @@ -4157,9 +4340,18 @@ paths:
- type: string
enum:
- cancelled
- type: string
enum:
- cancellation_requested
- type: string
enum:
- failed
- type: string
enum:
- refunded
- type: string
enum:
- refund_failed
amount:
minimum: 1
maximum: 1000000
Expand Down
15 changes: 14 additions & 1 deletion apps/payments-api/plugins/entities/citizen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import fp from "fastify-plugin";
import { CitizenRepo } from "./repo";
import { CitizenTransactionDO } from "./types";
import { PaginationParams } from "../../../types/pagination";
import { TransactionStatusesEnum } from "../transactions";
import { RefundStatuses } from "../refunds/types";

export type CitizenPlugin = Awaited<ReturnType<typeof buildPlugin>>;

Expand All @@ -25,7 +27,18 @@ const buildGetTransactions =
log.error((err as Error).message);
}

return result?.rows ?? [];
return (result?.rows ?? []).map((transaction: (CitizenTransactionDO & { refundStatus: string; })) => {
return {
transactionId: transaction.transactionId,
status: transaction.refundStatus
? (transaction.refundStatus === RefundStatuses.Failed ? TransactionStatusesEnum.RefundFailed : TransactionStatusesEnum.Refunded)
: transaction.status,
title: transaction.title,
amount: transaction.amount,
extPaymentId: transaction.extPaymentId,
updatedAt: transaction.updatedAt
}
});
};

const buildGetTransactionsTotalCount =
Expand Down
8 changes: 5 additions & 3 deletions apps/payments-api/plugins/entities/citizen/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ export class CitizenRepo {
getTransactions(
userId: string,
pagination: PaginationParams,
): Promise<QueryResult<CitizenTransactionDO[]>> {
): Promise<QueryResult<(CitizenTransactionDO & { refundStatus: string; })[]>> {
return this.pg.query(
`SELECT
t.transaction_id as "transactionId",
t.status,
t.status,
pr.title,
t.amount,
t.ext_payment_id as "extPaymentId",
t.updated_at as "updatedAt"
t.updated_at as "updatedAt",
r.status as "refundStatus"
FROM payment_transactions t
INNER JOIN payment_requests pr ON pr.payment_request_id = t.payment_request_id
LEFT JOIN payment_refunds r ON r.transaction_id = t.transaction_id
WHERE t.user_id = $1
ORDER BY t.updated_at DESC
LIMIT $2 OFFSET $3`,
Expand Down
Loading