-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ruben
committed
Jan 9, 2025
1 parent
164d47b
commit 55c3085
Showing
63 changed files
with
2,337 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
referenceId,programFinancialServiceProviderConfigurationName,phoneNumber,preferredLanguage,paymentAmountMultiplier,fullName,nationalId | ||
,Nedbank,31600000000,en,1,Sample Name,1234567890 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
services/121-service/src/financial-sync/financial-sync-controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Controller, HttpStatus, Patch } from '@nestjs/common'; | ||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; | ||
|
||
import { FinancialSyncService } from '@121-service/src/financial-sync/financial-sync-service'; | ||
import { AuthenticatedUser } from '@121-service/src/guards/authenticated-user.decorator'; | ||
|
||
@Controller() | ||
export class FinancialSyncController { | ||
public constructor(private financialSyncService: FinancialSyncService) {} | ||
@ApiTags('financial-service-providers/nedbank') | ||
@AuthenticatedUser({ isAdmin: true }) | ||
@ApiOperation({ | ||
summary: | ||
'[CRON] Retrieve and update Nedbank voucher and transaction statusses', | ||
}) | ||
@ApiResponse({ | ||
status: HttpStatus.CREATED, | ||
description: 'Cached unused vouchers', | ||
}) | ||
@Patch('financial-service-providers/nedbank') | ||
public async syncNedbankVoucherAndTransactionStatusses(): Promise<void> { | ||
console.info( | ||
'CronjobService - Started: updateNedbankVoucherAndTransactionStatusses', | ||
); | ||
this.financialSyncService | ||
.syncNedbankVoucherAndTransactionStatusses() | ||
.then(() => { | ||
console.info( | ||
'CronjobService - Complete: updateNedbankVoucherAndTransactionStatusses', | ||
); | ||
return; | ||
}) | ||
.catch((error) => { | ||
throw new Error( | ||
`CronjobService - Failed: updateNedbankVoucherAndTransactionStatusses - ${error}`, | ||
); | ||
}); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
services/121-service/src/financial-sync/financial-sync-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { In, IsNull, Not } from 'typeorm'; | ||
|
||
import { NedbankVoucherStatus } from '@121-service/src/payments/fsp-integration/nedbank/enums/nedbank-voucher-status.enum'; | ||
import { NedbankError } from '@121-service/src/payments/fsp-integration/nedbank/errors/nedbank.error'; | ||
import { NedbankService } from '@121-service/src/payments/fsp-integration/nedbank/nedbank.service'; | ||
import { NedbankVoucherScopedRepository } from '@121-service/src/payments/fsp-integration/nedbank/repositories/nedbank-voucher.scoped.repository'; | ||
import { TransactionStatusEnum } from '@121-service/src/payments/transactions/enums/transaction-status.enum'; | ||
import { TransactionScopedRepository } from '@121-service/src/payments/transactions/transaction.repository'; | ||
|
||
@Injectable() | ||
export class FinancialSyncService { | ||
public constructor( | ||
private readonly nedbankService: NedbankService, | ||
private readonly nedbankVoucherScopedRepository: NedbankVoucherScopedRepository, | ||
private readonly transactionScopedRepository: TransactionScopedRepository, | ||
) {} | ||
|
||
public async syncNedbankVoucherAndTransactionStatusses(): Promise<void> { | ||
const vouchers = await this.nedbankVoucherScopedRepository.find({ | ||
select: ['id', 'orderCreateReference', 'transactionId'], | ||
where: [ | ||
{ status: IsNull() }, | ||
{ | ||
status: Not( | ||
In([NedbankVoucherStatus.REDEEMED, NedbankVoucherStatus.REFUNDED]), | ||
), | ||
}, | ||
], | ||
}); | ||
|
||
for (const voucher of vouchers) { | ||
let voucherStatus: NedbankVoucherStatus; | ||
try { | ||
voucherStatus = | ||
await this.nedbankService.retrieveAndUpdateVoucherStatus( | ||
voucher.orderCreateReference, | ||
voucher.id, | ||
); | ||
} catch (error) { | ||
// ##TODO what extend should end the loop if something goes wrong? | ||
if (error instanceof NedbankError) { | ||
console.error( | ||
`Error while getting order for voucher ${voucher.id}: ${error.message}`, | ||
); | ||
continue; | ||
} else { | ||
throw error; | ||
} | ||
} | ||
|
||
// ##TODO: Should the NedbankService know about the TransactionModule? | ||
// It is the case in https://miro.com/app/board/uXjVLVYmSPM=/?moveToWidget=3458764603767347191&cot=14 however I am not sure about it | ||
if (voucherStatus === NedbankVoucherStatus.REDEEMED) { | ||
await this.transactionScopedRepository.update( | ||
{ id: voucher.transactionId }, | ||
{ status: TransactionStatusEnum.success }, | ||
); | ||
} | ||
if (voucherStatus === NedbankVoucherStatus.REFUNDED) { | ||
await this.transactionScopedRepository.update( | ||
{ id: voucher.transactionId }, | ||
{ | ||
status: TransactionStatusEnum.error, | ||
errorMessage: | ||
'Voucher has been refunded by Nedbank. Please contact Nedbank support.', // TODO: is this the correct ux copy? | ||
}, | ||
); | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
services/121-service/src/financial-sync/financial-sync.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { FinancialSyncController } from '@121-service/src/financial-sync/financial-sync-controller'; | ||
import { FinancialSyncService } from '@121-service/src/financial-sync/financial-sync-service'; | ||
import { NedbankModule } from '@121-service/src/payments/fsp-integration/nedbank/nedbank.module'; | ||
import { TransactionsModule } from '@121-service/src/payments/transactions/transactions.module'; | ||
|
||
@Module({ | ||
imports: [NedbankModule, TransactionsModule], | ||
providers: [FinancialSyncService], | ||
controllers: [FinancialSyncController], | ||
}) | ||
export class FinancialSyncModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.