Skip to content

PM-1099 withdraw action #45

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

Merged
merged 8 commits into from
May 7, 2025
Merged

PM-1099 withdraw action #45

merged 8 commits into from
May 7, 2025

Conversation

vas3a
Copy link
Collaborator

@vas3a vas3a commented May 6, 2025

https://topcoder.atlassian.net/browse/PM-1099 - Implement /withdraw endpoint in tc-finance API
https://topcoder.atlassian.net/browse/PM-1160 - Payment processed event handler
https://topcoder.atlassian.net/browse/PM-1167 - Payment failed & returned event handler

@vas3a vas3a requested a review from kkartunov May 6, 2025 15:10
Copy link
Contributor

@kkartunov kkartunov left a comment

Choose a reason for hiding this comment

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

Looks good!
Very few minor observations.

@@ -12,7 +12,9 @@ export class PaymentMethodRepository {
* @param userId user id
* @param tx transaction
*/
async hasVerifiedPaymentMethod(userId: string): Promise<boolean> {
async hasVerifiedPaymentMethod(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please rename this to getConnectedPaymentMethod as it is more explainatory and makes sense after recent changes.


export class WithdrawRequestDto {
@ApiProperty({
description: 'The ID of the winnings to withdraw',
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename winnings to payments?

})
@IsArray()
@ArrayNotEmpty()
@IsString({ each: true })
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably we could refactor this a bit by using @IsUUID decorator as payment IDs are UUIDs?

const winningIds = (payload.externalId ?? '').split(',').slice(0, -1);
const externalTransactionId = payload.batch.id;

if (!winningIds.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Code should throw here. Noting of the following logic will or shouldn't work without winningIds.
Agian, why we call those winnings as they are actually payment IDs? Can we update all of the refs and service signatures to reflect that?

this.logger.error(
`Failed to process trolley payment batch: ${error.message}`,
);
throw new Error('Failed to process trolley payment batch!');
Copy link
Contributor

Choose a reason for hiding this comment

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

We are sure that throwing here will revert the transactions for payment & payment_release from above?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, it won't... good catch! updating.

@@ -74,7 +74,7 @@ export class WinningsService {
body.winnerId,
);
const hasPaymentMethod =
await this.paymentMethodRepo.hasVerifiedPaymentMethod(body.winnerId);
await this.paymentMethodRepo.getConnectedPaymentMethod(body.winnerId);
Copy link

Choose a reason for hiding this comment

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

The method name getConnectedPaymentMethod suggests it retrieves a payment method, but the variable hasPaymentMethod implies a boolean value. Consider renaming the variable to better reflect the return type or ensure the method returns a boolean if the intention is to check for a connected payment method.

@vas3a vas3a requested a review from kkartunov May 7, 2025 11:49
Copy link
Contributor

@kkartunov kkartunov left a comment

Choose a reason for hiding this comment

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

Looks good.

@vas3a vas3a merged commit caf1188 into dev May 7, 2025
1 check passed
@vas3a vas3a deleted the PM-1099_withdraw-action branch May 7, 2025 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants