Skip to content

Commit e7a1de3

Browse files
authored
Merge pull request #61 from topcoder-platform/PM-1257_handle-wipro-users
PM-1257 - handle wipro users payout
2 parents 41b95c1 + 1b38436 commit e7a1de3

File tree

3 files changed

+63
-4
lines changed

3 files changed

+63
-4
lines changed

prisma/migrations/20250423135831_truncate_payment_methods/migration.sql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,11 @@ ALTER TABLE "paypal_payment_method" ALTER COLUMN "user_payment_method_id" DROP N
77
UPDATE payoneer_payment_method SET user_payment_method_id = NULL;
88
UPDATE paypal_payment_method SET user_payment_method_id = NULL;
99

10-
DELETE FROM user_default_payment_method;
11-
DELETE FROM user_payment_methods;
10+
DROP TABLE user_default_payment_method;
11+
12+
DELETE FROM user_payment_methods
13+
WHERE payment_method_id NOT IN (
14+
SELECT payment_method_id
15+
FROM payment_method
16+
WHERE payment_method_type IN ('Wipro Payroll', 'Trolley')
17+
);

src/api/payment-providers/trolley.service.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable } from '@nestjs/common';
1+
import { BadRequestException, Injectable } from '@nestjs/common';
22
import { UserInfo } from 'src/dto/user.dto';
33
import { TrolleyService as Trolley } from 'src/shared/global/trolley.service';
44
import { PrismaService } from 'src/shared/global/prisma.service';
@@ -157,6 +157,12 @@ export class TrolleyService {
157157
* @returns A URL string to the Trolley user portal.
158158
*/
159159
async getPortalUrlForUser(user: UserInfo) {
160+
if (user.email.toLowerCase().indexOf('@wipro.com') > -1) {
161+
throw new BadRequestException(
162+
'Please contact Topgear support to withdrawal your payments',
163+
);
164+
}
165+
160166
const recipient = await this.getPayeeRecipient(user);
161167
const link = this.trolley.getRecipientPortalUrl({
162168
email: user.email,

src/api/winnings/winnings.service.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { Injectable, HttpStatus, Logger } from '@nestjs/common';
2-
import { Prisma, payment, payment_status } from '@prisma/client';
2+
import {
3+
Prisma,
4+
payment,
5+
payment_method_status,
6+
payment_status,
7+
} from '@prisma/client';
38

49
import { PrismaService } from 'src/shared/global/prisma.service';
510

@@ -28,6 +33,47 @@ export class WinningsService {
2833
private readonly originRepo: OriginRepository,
2934
) {}
3035

36+
private async setPayrollPaymentMethod(userId: string) {
37+
const payrollPaymentMethod = await this.prisma.payment_method.findFirst({
38+
where: {
39+
payment_method_type: 'Wipro Payroll',
40+
},
41+
});
42+
43+
if (!payrollPaymentMethod) {
44+
this.logger.error(`Failed to retrieve Wipro Payroll payment method!`);
45+
return;
46+
}
47+
48+
if (
49+
await this.prisma.user_payment_methods.findFirst({
50+
where: {
51+
user_id: userId,
52+
payment_method_id: payrollPaymentMethod.payment_method_id,
53+
},
54+
})
55+
) {
56+
return;
57+
}
58+
59+
this.logger.debug(`Enrolling wipro user ${userId} with Wipro Payroll.`);
60+
61+
try {
62+
await this.prisma.user_payment_methods.create({
63+
data: {
64+
user_id: userId,
65+
status: payment_method_status.CONNECTED,
66+
payment_method_id: payrollPaymentMethod.payment_method_id,
67+
},
68+
});
69+
} catch (error) {
70+
this.logger.error(
71+
`Failed to enroll wipro user ${userId} with Wipro Payrol! ${error.message}`,
72+
error,
73+
);
74+
}
75+
}
76+
3177
/**
3278
* Create winnings with parameters
3379
* @param body the request body
@@ -97,6 +143,7 @@ export class WinningsService {
97143

98144
if (payrollPayment) {
99145
paymentModel.payment_status = PaymentStatus.PAID;
146+
await this.setPayrollPaymentMethod(body.winnerId);
100147
}
101148

102149
winningModel.payment.create.push(paymentModel);

0 commit comments

Comments
 (0)