Skip to content
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
3 changes: 2 additions & 1 deletion src/integration/bank/services/olkypay.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
import { OlkyRecipient } from '../entities/olky-recipient.entity';
import { OlkyRecipientRepository } from '../repositories/olky-recipient.repository';

export const OLKYPAY_RELEASE_BALANCE_LIMIT = 50000; // EUR

export interface OlkyRecipientData {
iban: string;
name: string;
Expand Down Expand Up @@ -208,7 +210,6 @@ export class OlkypayService {
remittanceInfo: tx.line2,
accountIban: accountIban,
type: tx.codeInterbancaireInterne === OlkypayTransactionType.BILLING ? BankTxType.BANK_ACCOUNT_FEE : null,
bankReleaseDate: new Date(),
};
} catch (e) {
throw new Error(`Failed to parse transaction ${tx.idCtp}: ${e.message}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ import {
MoreThanOrEqual,
Not,
} from 'typeorm';
import { OlkypayService } from '../../../../../integration/bank/services/olkypay.service';
import {
OLKYPAY_RELEASE_BALANCE_LIMIT,
OlkypayService,
} from '../../../../../integration/bank/services/olkypay.service';
import { BankService } from '../../../bank/bank/bank.service';
import { VirtualIbanService } from '../../../bank/virtual-iban/virtual-iban.service';
import { TransactionSourceType, TransactionTypeInternal } from '../../../payment/entities/transaction.entity';
Expand Down Expand Up @@ -196,6 +199,15 @@ export class BankTxService implements OnModuleInit {
}

if (olkyTransactions.length > 0) await this.settingService.set(settingKeyOlky, newModificationTime);

// Release unreleased transactions if balance is below threshold
const { balance } = await this.olkyService.getBalance();
if (balance < OLKYPAY_RELEASE_BALANCE_LIMIT) {
await this.bankTxRepo.update(
{ accountIban: olkyBank.iban, bankReleaseDate: IsNull() },
{ bankReleaseDate: new Date() },
);
}
}

private async assignTransactions(): Promise<void> {
Expand Down
Loading