@@ -471,37 +471,56 @@ trait PaymentBehavior
471471 case Some (authorId) =>
472472 paymentAccount.walletId match {
473473 case Some (debitedWalletId) =>
474- // load credited payment account
475- paymentDao.loadPaymentAccount(creditedAccount, clientId) complete () match {
476- case Success (s) =>
477- maybeCreditedPaymentAccount = s
478- maybeCreditedPaymentAccount match {
479- case Some (creditedPaymentAccount) => // credited account
480- creditedPaymentAccount.userId match {
481- case Some (creditedUserId) =>
482- creditedPaymentAccount.walletId match {
483- case Some (creditedWalletId) =>
484- Some (
485- TransferTransaction .defaultInstance
486- .withDebitedAmount(debitedAmount)
487- .withFeesAmount(feesAmount)
488- .withCurrency(currency)
489- .withAuthorId(authorId)
490- .withDebitedWalletId(debitedWalletId)
491- .withCreditedUserId(creditedUserId)
492- .withCreditedWalletId(creditedWalletId)
493- .copy(
494- orderUuid = orderUuid,
495- externalReference = externalReference
496- )
497- )
498- case _ => None
499- }
500- case _ => None
501- }
502- case _ => None
503- }
504- case Failure (_) => None
474+ if (debitedAccount == creditedAccount) { // direct transfer from the platform account to authorId
475+ val creditedUserId = authorId
476+ val creditedWalletId = debitedWalletId
477+ Some (
478+ TransferTransaction .defaultInstance
479+ .withDebitedAmount(debitedAmount)
480+ .withFeesAmount(feesAmount)
481+ .withCurrency(currency)
482+ .withAuthorId(authorId)
483+ .withDebitedWalletId(debitedWalletId)
484+ .withCreditedUserId(creditedUserId)
485+ .withCreditedWalletId(creditedWalletId)
486+ .copy(
487+ orderUuid = orderUuid,
488+ externalReference = externalReference
489+ )
490+ )
491+ } else {
492+ // load credited payment account
493+ paymentDao.loadPaymentAccount(creditedAccount, clientId) complete () match {
494+ case Success (s) =>
495+ maybeCreditedPaymentAccount = s
496+ maybeCreditedPaymentAccount match {
497+ case Some (creditedPaymentAccount) => // credited account
498+ creditedPaymentAccount.userId match {
499+ case Some (creditedUserId) =>
500+ creditedPaymentAccount.walletId match {
501+ case Some (creditedWalletId) =>
502+ Some (
503+ TransferTransaction .defaultInstance
504+ .withDebitedAmount(debitedAmount)
505+ .withFeesAmount(feesAmount)
506+ .withCurrency(currency)
507+ .withAuthorId(authorId)
508+ .withDebitedWalletId(debitedWalletId)
509+ .withCreditedUserId(creditedUserId)
510+ .withCreditedWalletId(creditedWalletId)
511+ .copy(
512+ orderUuid = orderUuid,
513+ externalReference = externalReference
514+ )
515+ )
516+ case _ => None
517+ }
518+ case _ => None
519+ }
520+ case _ => None
521+ }
522+ case Failure (_) => None
523+ }
505524 }
506525 case _ => None
507526 }
@@ -579,7 +598,10 @@ trait PaymentBehavior
579598 .withDebitedAccount(paymentAccount.externalUuid)
580599 .withResultMessage(transaction.resultMessage)
581600 .withTransaction(transaction)
582- .copy(externalReference = externalReference)
601+ .copy(
602+ externalReference = externalReference,
603+ orderUuid = orderUuid
604+ )
583605 ) :+ transactionUpdatedEvent
584606 )
585607 .thenRun(_ =>
0 commit comments