Skip to content

Commit 73a3a1f

Browse files
committed
fix paypal fee collection
1 parent 129e1ea commit 73a3a1f

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/api/withdrawal/withdrawal.service.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,19 +258,21 @@ export class WithdrawalService {
258258
trolleyRecipientPayoutDetails.payoutMethod === 'paypal' &&
259259
ENV_CONFIG.TROLLEY_PAYPAL_FEE_PERCENT
260260
) {
261-
const feePercent = Number(ENV_CONFIG.TROLLEY_PAYPAL_FEE_PERCENT) / 100;
262-
feeAmount = Math.max(
261+
const feePercent =
262+
Number(ENV_CONFIG.TROLLEY_PAYPAL_FEE_PERCENT) / 100;
263+
264+
feeAmount = +Math.min(
263265
ENV_CONFIG.TROLLEY_PAYPAL_FEE_MAX_AMOUNT,
264266
feePercent * paymentAmount,
265-
);
267+
).toFixed(2);
266268

267269
paymentAmount -= feeAmount;
268270
}
269271

270272
this.logger.log(
271273
`
272-
Total amount won: $${totalAmount} USD, to be paid: $${totalAmount.toFixed(2)} USD.
273-
Fee applied: $${feeAmount.toFixed(2)} USD (${Number(ENV_CONFIG.TROLLEY_PAYPAL_FEE_PERCENT) * 100}%, max ${ENV_CONFIG.TROLLEY_PAYPAL_FEE_MAX_AMOUNT}).
274+
Total amount won: $${totalAmount.toFixed(2)} USD, to be paid: $${paymentAmount.toFixed(2)} USD.
275+
Fee applied: $${feeAmount.toFixed(2)} USD (${Number(ENV_CONFIG.TROLLEY_PAYPAL_FEE_PERCENT)}%, max ${ENV_CONFIG.TROLLEY_PAYPAL_FEE_MAX_AMOUNT}).
274276
Payout method type: ${trolleyRecipientPayoutDetails.payoutMethod}.
275277
`,
276278
);
@@ -287,6 +289,10 @@ export class WithdrawalService {
287289
feeAmount,
288290
totalAmount: totalAmount,
289291
payoutMethod: trolleyRecipientPayoutDetails.payoutMethod,
292+
env_trolley_paypal_fee_percent:
293+
ENV_CONFIG.TROLLEY_PAYPAL_FEE_PERCENT,
294+
env_trolley_paypal_fee_max_amount:
295+
ENV_CONFIG.TROLLEY_PAYPAL_FEE_MAX_AMOUNT,
290296
},
291297
);
292298

src/config/config.env.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ export class ConfigEnv {
9898
@Min(0)
9999
@Max(99)
100100
@IsOptional()
101-
TROLLEY_PAYPAL_FEE_PERCENT: number;
101+
TROLLEY_PAYPAL_FEE_PERCENT: number = 0;
102102

103103
@IsNumber()
104104
@IsOptional()
105-
TROLLEY_PAYPAL_FEE_MAX_AMOUNT: number;
105+
TROLLEY_PAYPAL_FEE_MAX_AMOUNT: number = 0;
106106
}

src/shared/global/trolley.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ export class TrolleyService {
118118
recipient: {
119119
id: recipientId,
120120
},
121-
sourceAmount: totalAmount.toString(),
122-
sourceCurrency: 'USD',
121+
amount: totalAmount.toFixed(2),
122+
currency: 'USD',
123123
memo: paymentMemo ?? 'Topcoder payment',
124124
externalId: transactionId,
125125
};

0 commit comments

Comments
 (0)