Skip to content

Commit

Permalink
Derive payment uuid from the tx hash for better duplicate handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperschwartz committed Feb 4, 2022
1 parent 396683c commit afe2d2c
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,19 @@ class EventHandlerService(
}

fun handlePaymentMadeEvent(event: IncomingInvoiceEvent) {
val paymentUuid = UUID.randomUUID()
// Derive the payment uuid from the incoming TX hash. This will prevent duplicate payments from being
// stored from re-running the same event
val paymentUuid = UUID.nameUUIDFromBytes(event.streamEvent.txHash.toByteArray())
val logPrefix = "PAYMENT MADE [Invoice ${event.invoiceUuid} | Payment $paymentUuid]:"
logger.info("$logPrefix Handling payment made event")
val calc = invoiceCalcFactory.generate(event.invoiceUuid)
if (calc.payments.any { it.uuid == paymentUuid }) {
logger.info("$logPrefix Skipping duplicate payment from event hash [${event.streamEvent.txHash}]")
return
}
val paymentTime = event.streamEvent.attributeValueI<OffsetDateTime>(PayableContractKey.PAYMENT_TIME)
if (calc.payments.any { it.effectiveTime == paymentTime }) {
logger.warn("$logPrefix Duplicate payment for time [$paymentTime] received. Ignoring duplicate request")
logger.warn("$logPrefix Skipping duplicate payment for time [$paymentTime] received. Ignoring duplicate request")
return
}
if (calc.invoiceStatus !in INVOICE_STATUSES_ALLOWED_FOR_PAYMENT) {
Expand Down

0 comments on commit afe2d2c

Please sign in to comment.