Account

Internal Account

Address

TEST_ASSET_INTERNAL_ACCOUNT

DEFAULT

LOAN_PENALTIES_UNPAID_INTERNAL

DEFAULT

LOAN_PENALTIES_PAID_INTERNAL

DEFAULT

OVERDRAFT_FEES_PAID_INTERNAL

DEFAULT

OVERDRAFT_FEES_UNPAID_INTERNAL

DEFAULT

OVERDRAFT_PAID_INTERNAL

DEFAULT

OVERDRAFT_UNPAID_INTERNAL

DEFAULT

OVERDRAFT_PENALTIES_PAID_INTERNAL

DEFAULT

OVERDRAFT_PENALTIES_UNPAID_INTERNAL

DEFAULT

SUBSCRIPTION_FEES_PAID_INTERNAL

DEFAULT

SUBSCRIPTION_FEES_UNPAID_INTERNAL

DEFAULT

Overdraft

Smart Contract

Address

test_main_account_product

DEFAULT

WHT

INTEREST

OVERDRAFT

Loan

Smart Contract

Address

test_loan_account_product

DEFAULT

PREPAID

INTEREST_PAID

PRINCIPAL

INTEREST_DUE

PRINCIPAL_DUE

INTEREST_OVERDUE

PRINCIPAL_OVERDUE

ACCRUED_INTEREST

INTERNAL_CONTRA

Pocket

Smart Contract

Address

test_pocket_account_product

DEFAULT

Transactions

Kotlin Transactions:

Transaction

Posting Transaction

Transaction Type

Debit Account

Debit Address

Credit Account

Credit Address

Previous Example

Example

Open Overdraft

CustomInternalToCustomer

OVERDRAFT_IMBURSEMENT

TEST_ASSET_INTERNAL_ACCOUNT

Default

29370f04-0f0a-4a1a-8c0f-839a33f263ea

OVERDRAFT

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/8cb5a953-30d4-438a-b162-74fba1885760/ba5cf1da-51a0-4710-8b01-56c890b8ea63

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/a598c3f7-abe2-4613-a354-383657519b9c/abdaa278-a84f-4486-9245-ca9aa460b18c

Repay Overdraft

CustomCustomerToInternal

OVERDRAFT_REPAYMENT

29370f04-0f0a-4a1a-8c0f-839a33f263ea

Default

TEST_ASSET_INTERNAL_ACCOUNT

Default

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/4536eeb0-6947-4088-88a6-00f17a7ba95c/ea738a8d-301f-46b9-bd15-1ad5ce64e093

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/f02a152f-9bdc-4a26-9f79-876f14f4db13/64acaeca-5554-4cb8-9239-3f95239dc264

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/ff0629a0-d0f7-448b-95c4-d731b646abce

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/b4a365db-6994-4ba7-994d-04293c0ebb36/878fcfb0-b6d5-48a1-b655-10afebffb81b

Apply Fee

CustomCustomerToInternal

OVERDRAFT_REPAYMENT

1317435c-4798-4311-9fb7-f759bbc455b7

Default

TEST_ASSET_INTERNAL_ACCOUNT

Default

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/47e3a191-f3d2-43e6-a2e0-a6f080b1aa69

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/f4be4c63-f006-4020-8ece-88f9089fcd10

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/5a6775c3-692b-41f4-82bc-97303896a53b

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/a76f0de6-5e0a-44f2-a9d5-46eacddc5393

Claim Debt

CustomCustomerToInternal

CLAIM_PAYMENT

1317435c-4798-4311-9fb7-f759bbc455b7

DEFAULT

OVERDRAFT_PENALTIES_UNPAID_INTERNAL

DEFAULT

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/cbf9940b-113f-4a88-9563-88120164b1e3/cdf16b96-af7c-413d-89c0-3c24878f67c6

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/9cc6dc22-fbd9-4e73-b146-adf611112430/0628eea3-405b-4954-bd0c-b6ee7d9d2e06

Repay Loan

Transfer

LOAN_REPAYMENT

29370f04-0f0a-4a1a-8c0f-839a33f263ea

DEFAULT

1183045f-6f15-40c3-8e40-728ca914a507

DEFAULT

https://ops.tm5.sandbox.safibank.online/customers/bf8884a6-8b4a-4abf-8024-a693c06fd414/accounts/1183045f-6f15-40c3-8e40-728ca914a507

https://ops.tm5.sandbox.safibank.online/customers/bf8884a6-8b4a-4abf-8024-a693c06fd414/accounts/430fa5cb-c536-42b5-8f0f-fd1e046c3d8d

Repay Loan with Pocket

Transfer

LOAN_REPAYMENT_POCKET

fca42a44-d4d5-427c-bc8b-3f078ad62b4f

DEFAULT

29370f04-0f0a-4a1a-8c0f-839a33f263ea

DEFAULT

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/4e4e37d5-91f2-4c39-a180-c94e44d7c717

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/5360c4e2-6710-48a2-873a-bc2cb137069c

https://ops.tm5.sandbox.safibank.online/customers/bf8884a6-8b4a-4abf-8024-a693c06fd414/accounts/fcef56dc-9cbd-4c0b-a8f9-a3444ee794c7

Direct Repay

CustomInternalToCustomer

DIRECT_DEBT_REPAY

1317435c-4798-4311-9fb7-f759bbc455b7

DEFAULT

TEST_ASSET_INTERNAL_ACCOUNT

DEFAULT

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/be9c743c-2260-4f14-9c7f-08bdceb03e95/e126098b-af7e-4d94-9e35-7590c7c2fb67

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/29693638-089f-4cb2-af45-a9a02458d906/3db8121e-9200-4fbe-8f4e-1eb3f1b343b3

Smart Contract Transactions

Transaction

Posting Transaction

Transaction Type

Debit Account

Debit Address

Credit Account

Credit Address

Instruction Details

Handlers

Previous Posting Handler

Handler

Transaction Type

Debt Type

Repayment Type

Event

Account Address

Action

Status

LoanInterestEarlyRepaymentPostingHandler

EARLY_REPAYMENT

workflow.registerPaymentEvent(LoanPaymentEventRegistrationDto( ))

DONE

LoanInterestRepaymentPostingHandler

INTEREST_DUE

loansEventHandlerService.handlePaymentEvent(LoanPaymentEvent)

DONE

LoanPrincipalEarlyRepaymentPostingHandler

PRINCIPAL_DUE

workflow.registerPaymentEvent(LoanPaymentEventRegistrationDto())

DONE

LoanPrincipalRepaymentPostingHandler

REPAYMENT

SCHEDULED_REPAYMENT

PRINCIPAL_DUE

loansEventHandlerService.handlePaymentEvent(LoanPaymentEvent)

DONE

LoanUserRepaymentPostingHandler

LOAN_REPAYMENT

  1. loansEventHandlerService.handlePaymentEvent(LoanPaymentEvent)

  2. workflowIds.forEach {

  3. val workflow = workflowClient.newUntypedWorkflowStub(it) workflow.signal("provideReply", ReplyDto(requestId, success))

  4. }

DONE

OverdraftDebtPostingHandler

  • CUSTOMER_DEBT_REPAY

  • CUSTOMER_DEBT_REBALANCE

  • OVERDRAFT_FEE

  • OVERDRAFT_PENALTY

  • OVERDRAFT_PRINCIPAL

  • OVERDRAFT_FEE -> workflow.adjustFeeDebt(debtParams)

  • OVERDRAFT_PENALTY -> workflow.adjustPenaltyDebt(debtParams)

  • OVERDRAFT_PRINCIPALworkflow.adjustPrincipalDebt(debtParams)

DONE

OverdraftPostingHandler

  • OVERDRAFT_IMBURSEMENT

  • OVERDRAFT_REPAYMENT

  • OVERDRAFT_FEE

  • CLAIM_PAYMENT

workflow.provideReply(ReplyDto(requestId, success))

DONE

Current Posting Handler:

Handler

Transaction Type

Action

Previous Handler

Status

Test

LoanRepayPrincipalDueWithPrepaymentTransactionHandler

LoanRepayPrincipalDueWithDefaultTransactionHandler

handlePayment(LoanPaymentEvent)

LoanPrincipalRepaymentPostingHandler

MATCH

LoanRepayInterestDueWithDefaultPostingHandler

LoanRepayInterestDueWithPrepaymentPostingHandler

LoanInterestRepaymentPostingHandler

MATCH

LoanRepayPrincipalDueWithDefaultByEarlyRepaymentTransactionHandler

LoanPayOffWithPrepaidAmountTransaction

workflow.registerPaymentEvent(LoanPaymentEvent)

LoanPrincipalEarlyRepaymentPostingHandler

MATCH

LoanRepayInterestDueWithDefaultByEarlyRepaymentTransactionHandler

workflow.registerPaymentEvent(LoanPaymentEvent)

LoanInterestEarlyRepaymentPostingHandler

MATCH

LoanUserRepayTransactionHandler

  • handleEvent(instructionMetadata, transaction)

  • handleReply(instructionMetadata, transaction, success)

LoanUserRepaymentPostingHandler

MATCH

step1: open loan

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/55eefb5c-147b-41d0-9eaa-53250fecd2b4

step 2: repay loan

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/8ec50865-1549-4bb5-a77b-92ee7f3dee7b/afc5f0c3-c7ef-4188-b18c-b12fe9262ccb

OverdraftImbursementPostingHandler

OVERDRAFT_IMBURSEMENT

workflow.provideReply(ReplyDto(requestId, success))

OverdraftPostingHandler

MATCH

Step1: open overdraft

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/c1244d9c-bdfd-47b3-9ec1-2010719632a7/a4f66d8f-0de8-4483-aa55-019d05aa95f6

Step2: repay

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/f80b8ec9-1437-4756-8788-cb5aa3d6531c/98caadde-05d7-4d01-aae4-b65f0a974df4

OverdraftRepaymentPostingHandler

OVERDRAFT_REPAYMENT

MATCH

OverdraftApplyFeePostingHandler

OVERDRAFT_FEE

MATCH

OverdraftClaimFeePostingHandler

OverdraftClaimPrincipalPostingHandler

CLAIM_PAYMENT

OverdraftPostingHandler

MATCH

DebtRebalanceOverdraftFeePostingHandler

DebtRebalanceOverdraftPenaltiesPostingHandler

DebtRebalanceOverdraftPrincipalPostingHandler

DebtRepayCustomerOverdraftFeePostingHandler

DebtRepayCustomerOverdraftPenaltiesPostingHandler

DebtRepayCustomerOverdraftPrincipalPostingHandler

OverdraftDebtPostingHandler

MATCH

Test Issues:

Issue Number

Description

1

LoanRepayInterestDueWithDefaultByEarlyRepaymentTransactionHandler - Failed to construct LoanRepayInterestDueWithDefaultByEarlyRepaymentTransaction transaction from instruction with clientTransactionId '261f4970-fe2d-441f-b112-d8cf331d2211', instructionMetadata InstructionMetadata(instructionId=a4f66d8f-0de8-4483-aa55-019d05aa95f6, batchId=c1244d9c-bdfd-47b3-9ec1-2010719632a7, requestId=a66d856c-4b22-3863-a454-6afa995d4115, clientId=LoanManagerPostingsClient, clientBatchId=f389e386-83b3-41a2-9844-3ff2c3c50281, batchStatus=ACCEPTED, valueTimestamp=2023-02-08T09:08:09.229904Z, insertionTimestamp=2023-02-08T09:08:09.229904Z, captureTimestamp=null, errorMessage=null)
java.lang.IllegalArgumentException: Invalid UUID string: TEST_ASSET_INTERNAL_ACCOUNT
at java.base/java.util.UUID.fromString1(UUID.java:280)
at java.base/java.util.UUID.fromString(UUID.java:258)
at ph.safibank.tm.model.transaction.CustomCustomerToSelfKt.toCustomCustomerToSelf(CustomCustomerToSelf.kt:74)

2

Failed to construct DebtRepayCustomerOverdraftPenaltiesTransaction transaction from instruction with clientTransactionId '9458bd71-d039-440e-a1ea-57a36ad4d171', instructionMetadata InstructionMetadata(instructionId=98caadde-05d7-4d01-aae4-b65f0a974df4, batchId=f80b8ec9-1437-4756-8788-cb5aa3d6531c, requestId=eefb04cf-9643-3924-b924-83ee05ed4403, clientId=LoanManagerPostingsClient, clientBatchId=f00416ee-4c88-40a0-9db3-099a050ac53d, batchStatus=ACCEPTED, valueTimestamp=2023-02-08T09:10:43.185717Z, insertionTimestamp=2023-02-08T09:10:43.185717Z, captureTimestamp=null, errorMessage=null)
java.lang.RuntimeException: Expected instructionDetails["transaction_type"] equal to 'CUSTOMER_DEBT_REPAY', but found 'OVERDRAFT_REPAYMENT'

3

Failed to construct LoanOverdraftApplyFeeTransaction transaction from instruction with clientTransactionId '9458bd71-d039-440e-a1ea-57a36ad4d171', instructionMetadata InstructionMetadata(instructionId=98caadde-05d7-4d01-aae4-b65f0a974df4, batchId=f80b8ec9-1437-4756-8788-cb5aa3d6531c, requestId=eefb04cf-9643-3924-b924-83ee05ed4403, clientId=LoanManagerPostingsClient, clientBatchId=f00416ee-4c88-40a0-9db3-099a050ac53d, batchStatus=ACCEPTED, valueTimestamp=2023-02-08T09:10:43.185717Z, insertionTimestamp=2023-02-08T09:10:43.185717Z, captureTimestamp=null, errorMessage=null)
java.lang.RuntimeException: Expected instructionDetails["transaction_type"] equal to 'OVERDRAFT_FEE', but found 'OVERDRAFT_REPAYMENT'
at ph.safibank.tm.model.transaction.LoanOverdraftApplyFeeTransaction$Companion.fromPostingInstruction(LoanOverdraftApplyFeeTransaction.kt:46)

4

Failed to construct LoanPayOffWithPrepaidAmountTransaction transaction from instruction with clientTransactionId '4346f2e9-64df-4d13-8ad5-6fefd3e1187e', instructionMetadata InstructionMetadata(instructionId=c5e22119-ac0f-4ab2-846e-c58fc993a185, batchId=1a216cbb-8a7a-46e8-9444-97d823b5b451, requestId=e47edcb6-6f4a-3e98-a8a3-e7adb6bfdc30, clientId=LoanManagerPostingsClient, clientBatchId=e3842178-1608-46a6-8096-73a5106c023e, batchStatus=ACCEPTED, valueTimestamp=2023-02-08T09:24:43.963094Z, insertionTimestamp=2023-02-08T09:24:43.963094Z, captureTimestamp=null, errorMessage=null)
java.lang.RuntimeException: Expected instructionDetails["event"] equal to 'REPAYMENT', but found 'null'
at ph.safibank.tm.model.transaction.LoanPayOffWithPrepaidAmountTransaction$Companion.fromPostingInstruction(LoanPayOffWithPrepaidAmountTransaction.kt:50)
at ph.safibank.tm.listener.handler.LoanPayOffWithPrepaidAmountTransactionHandler.handle(

5

6

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/99838202-5f0e-45e9-8038-143e054b5f0a/3bc0ed9c-4f58-4457-9e2c-57dd607d012c

https://ops.tm5.sandbox.safibank.online/ledgers/posting-instruction-batches/82620aa1-53c0-40f2-9c20-540c2006bd0a

Questions:

  1. The type of debitAccountId and creditAccountId is UUID, so we can’t use transfer transaction to pay overdraft, one option to fix this is to update the type of debitAccountId and creditAccountId to UUID, this will affect other squad, the other way is to follow up current rules but need to update smart contract.

  2. PostingApiClient: https://documentation.tm5.sandbox.safibank.online/api/postings_api/overview/#creating_postings_api_clients

  3. Financial Requirement

  4. https://advancegroup.larksuite.com/sheets/shtusym2fb4TdGS7FPbZgiwRTPc?sheet=1WLqqY

How to debug:

1: Update the SaFiMono/common/tm-client/transactionsDefinitions.yml file and generate the latest tm-client lib

gradle clean build -x test -x integrationTest

2: Copy the tm-client.jar to libs folder(loan-manager\libs) in loan manager service

├── account-manager-api-client-1.jar
├── advanceai-gateway-api-client-8.jar
├── authorization-lib-3.20221104-081556.jar
├── avro-model-4.20230116-035139.jar
├── iam-auth-lib-3.20221109-144652.jar
├── micronaut-gcp-common-4.8.0.jar
├── opentelemetry-api-1.22.0.jar
├── opentelemetry-context-1.22.0.jar
├── opentelemetry-sdk-common-1.22.0.jar
├── opentelemetry-sdk-metrics-1.22.0.jar
├── product-recommendation-manager-api-client-2.jar
├── test-utils-2.20230106-075056.jar
├── tm-client-runner.jar
├── tm-client.jar
└── utils-9.20221222-021144.jar

3: Add below codes in SaFiMono/services/loan-manager/build.gradle.kts

repositories {
    mavenLocal()
    ...
}

dependencies {
    ...
    implementation(
        files(
            "libs/account-manager-api-client-1.jar",
            "libs/advanceai-gateway-api-client-8.jar",
            "libs/authorization-lib-3.20221104-081556.jar",
            "libs/avro-model-4.20230116-035139.jar",
            "libs/iam-auth-lib-3.20221109-144652.jar",
            "libs/product-recommendation-manager-api-client-2.jar",
            "libs/utils-9.20221222-021144.jar",
            "libs/opentelemetry-api-1.22.0.jar",
            "libs/opentelemetry-sdk-common-1.22.0.jar",
            "libs/opentelemetry-context-1.22.0.jar",
            "libs/opentelemetry-sdk-metrics-1.22.0.jar",
            "libs/tm-client.jar",
            "libs/tm-client-runner.jar"
        )
    )
    testImplementation(files("libs/test-utils-2.20230106-075056.jar"))
    api("com.google.protobuf:protobuf-kotlin:3.21.5")
    ...
}

Attachments:

SaFi Postings v13.1 Reviewed by Ivy.xlsx (application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
截屏2023-02-09 12.51.47.png (image/png)
截屏2023-02-09 14.27.31.png (image/png)
截屏2023-02-09 15.28.29.png (image/png)
截屏2023-02-10 16.14.03.png (image/png)
截屏2023-02-13 12.23.36.png (image/png)