package Ġru . cat cab . tax im aster . payment gateway . logic Ċ Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . with Context Ċ import Ġorg . jetbrains . ex posed . sql . Database Ċ import Ġorg . jetbrains . ex posed . sql . and Ċ import Ġorg . jetbrains . ex posed . sql . transactions . transaction Ċ import Ġru . cat cab . tax im aster . payment gateway . database . entity . Payment Ċ import Ġru . cat cab . tax im aster . payment gateway . database . entity . Payments Ċ import Ġru . cat cab . tax im aster . payment gateway . database . enum . Source Type . CC B Ċ import Ġru . cat cab . tax im aster . payment gateway . dto . ccb . C cb ResponseError Ċ import Ġru . cat cab . tax im aster . payment gateway . dto . ccb . C cb Response Payment Ċ import Ġru . cat cab . tax im aster . payment gateway . util . common . Helpers . remove Leading Z eros Ċ import Ġru . cat cab . tax im aster . payment gateway . util . context . Log Id Generator Ċ import Ġru . cat cab . tax im aster . payment gateway . util . context . M DC Key Ċ import Ġru . cat cab . tax im aster . payment gateway . util . context . M DC Key . OPERATION _ ID Ċ import Ġru . cat cab . tax im aster . payment gateway . util . context . M DC Key . OPERATION _ NAME Ċ import Ġru . cat cab . tax im aster . payment gateway . util . context . M DC Key . RECE IVER Ċ import Ġru . cat cab . tax im aster . payment gateway . util . context . M DC Key . REQUEST _ ID Ċ import Ġru . cat cab . tax im aster . payment gateway . util . context . Operation Names . CC B _ PAYMENT Ċ import Ġru . cat cab . tax im aster . payment gateway . util . logging . Method Logger Ċ import Ġjava . math . BigDecimal Ċ import Ġjava . time . LocalDateTime Ċ import Ġjava . time . temporal . Ch rono Unit . SECONDS Ċ Ċ class ĠC cb Payment Operation ( ĊĠĠĠ Ġprivate Ġval Ġdatabase : ĠDatabase , ĊĠĠĠ Ġprivate Ġval Ġlog Id Generator : ĠLog Id Generator , ĊĠĠĠ Ġprivate Ġval Ġpayment In Operation : ĠPayment In Operation Ċ ) Ġ{ ĊĠĠĠ Ġprivate Ġval Ġmethod Logger Ġ= ĠMethod Logger () ĊĊĠĠĠ Ġsuspend Ġfun Ġactivate ( account : ĠString , Ġamount : ĠBigDecimal , Ġpay Id : ĠString , Ġpay Date : ĠLocalDateTime ): ĠAny Ġ{ ĊĠĠĠĠĠĠĠ Ġmethod Logger . log Suspend Method (:: activate , Ġaccount , Ġamount , Ġpay Id , Ġpay Date ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġm dc Ġ= Ġmap Of ( OPERATION _ ID . value Ġto Ġlog Id Generator . generate (), ĠOPER ATION _ NAME . value Ġto ĠC CB _ PAYMENT . value , ĠRE CE IVER . value Ġto Ġaccount ) ĊĠĠĠĠĠĠĠ Ġ} ?. let Ġ{ Ġreturn Ġit () Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġreceiver Ġ= Ġaccount . remove Leading Z eros () ĊĠĠĠĠĠĠĠ Ġval Ġpayment Ġ= Ġwith Context ( Dispatch ers . IO ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtransaction ( database ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠPayment . find Ġ{ Ġ( Payments . pay Id Ġeq Ġpay Id ) Ġand Ġ( Payments . source Type Ġeq ĠC CB ) Ġ Ġ}. first OrNull () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġif Ġ( payment Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠC cb ResponseError ( 3 0 , Ġ" Ðĳ Ñĭ Ð» ĠÐ´ÑĢÑĥÐ³ Ð¾Ð¹ ĠÐ¿Ð» Ð°ÑĤ ÐµÐ¶ ĠÑģ ĠÑĥÐºÐ°Ð· Ð°Ð½ Ð½ÑĭÐ¼ ĠÐ½ Ð¾Ð¼ ÐµÑĢ Ð¾Ð¼ ") ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġnew Payment Ġ= Ġpayment In Operation . activate ( CC B , Ġreceiver , Ġamount Ġ/ Ġ 1 0 0 . to BigDecimal (), Ġpay Id , Ġpay Date , ĠM DC Key . getValue ( REQUEST _ ID )) ĊĠĠĠĠĠĠĠ Ġval Ġreg Time Ġ= Ġnew Payment . inserted . tr uncated To ( SECONDS ) ĊĠĠĠĠĠĠĠ Ġreturn ĠC cb Response Payment ( 0 , Ġ" OK ", Ġaccount , Ġnew Payment . id . value . toString (), Ġreg Time ) ĊĠĠĠ Ġ} Ċ }