Skip to content

PM-1257 - handle wipro users payout #61

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ ALTER TABLE "paypal_payment_method" ALTER COLUMN "user_payment_method_id" DROP N
UPDATE payoneer_payment_method SET user_payment_method_id = NULL;
UPDATE paypal_payment_method SET user_payment_method_id = NULL;

DELETE FROM user_default_payment_method;
DELETE FROM user_payment_methods;
DROP TABLE user_default_payment_method;

DELETE FROM user_payment_methods
WHERE payment_method_id NOT IN (
SELECT payment_method_id
FROM payment_method
WHERE payment_method_type IN ('Wipro Payroll', 'Trolley')
);
8 changes: 7 additions & 1 deletion src/api/payment-providers/trolley.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { BadRequestException, Injectable } from '@nestjs/common';
import { UserInfo } from 'src/dto/user.dto';
import { TrolleyService as Trolley } from 'src/shared/global/trolley.service';
import { PrismaService } from 'src/shared/global/prisma.service';
Expand Down Expand Up @@ -157,6 +157,12 @@ export class TrolleyService {
* @returns A URL string to the Trolley user portal.
*/
async getPortalUrlForUser(user: UserInfo) {
if (user.email.toLowerCase().indexOf('@wipro.com') > -1) {

Choose a reason for hiding this comment

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

medium
correctness
The check for user.email.toLowerCase().indexOf('@wipro.com') > -1 could be improved for clarity and correctness by using user.email.toLowerCase().endsWith('@wipro.com'). This ensures that only emails ending with @wipro.com are matched, avoiding potential false positives.

throw new BadRequestException(
'Please contact Topgear support to withdrawal your payments',
);
}

const recipient = await this.getPayeeRecipient(user);
const link = this.trolley.getRecipientPortalUrl({
email: user.email,
Expand Down
49 changes: 48 additions & 1 deletion src/api/winnings/winnings.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Injectable, HttpStatus, Logger } from '@nestjs/common';
import { Prisma, payment, payment_status } from '@prisma/client';
import {
Prisma,
payment,
payment_method_status,
payment_status,
} from '@prisma/client';

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

Expand Down Expand Up @@ -28,6 +33,47 @@ export class WinningsService {
private readonly originRepo: OriginRepository,
) {}

private async setPayrollPaymentMethod(userId: string) {
const payrollPaymentMethod = await this.prisma.payment_method.findFirst({
where: {
payment_method_type: 'Wipro Payroll',
},
});

if (!payrollPaymentMethod) {
this.logger.error(`Failed to retrieve Wipro Payroll payment method!`);
return;
}

if (
await this.prisma.user_payment_methods.findFirst({
where: {
user_id: userId,
payment_method_id: payrollPaymentMethod.payment_method_id,
},
})
) {
return;
}

this.logger.debug(`Enrolling wipro user ${userId} with Wipro Payroll.`);

try {
await this.prisma.user_payment_methods.create({
data: {
user_id: userId,
status: payment_method_status.CONNECTED,
payment_method_id: payrollPaymentMethod.payment_method_id,
},
});
} catch (error) {
this.logger.error(
`Failed to enroll wipro user ${userId} with Wipro Payrol! ${error.message}`,
error,
);
}
}

/**
* Create winnings with parameters
* @param body the request body
Expand Down Expand Up @@ -97,6 +143,7 @@ export class WinningsService {

if (payrollPayment) {
paymentModel.payment_status = PaymentStatus.PAID;
await this.setPayrollPaymentMethod(body.winnerId);
}

winningModel.payment.create.push(paymentModel);
Expand Down