package Ġcom . x ently . payment Ċ Ċ import Ġandroid . content . Context Ċ import Ġcom . x ently . payment . data . model . Money Ċ import Ġcom . x ently . payment . data . model . square . Payment Ċ import Ġcom . x ently . payment . data . repository . square . IS quare Repository Ċ import Ġcom . x ently . payment . utils . web . Task Result Ċ import Ġcom . x ently . payment . utils . web . errorMessage Ċ import Ġcom . x ently . payment . utils . web . is Successful Ċ import Ġdagger . h ilt . android . qual ifiers . ApplicationContext Ċ import Ġkotlinx . coroutines . Coroutine Dispatcher Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġsq ip . Card Details Ċ import Ġsq ip . Card Entry Activity Command Ċ import Ġsq ip . Card Nonce Background Handler Ċ import Ġjava . io . IOException Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠSquare Card Entry Background Handler Ġ@ Inject Ġinternal Ġconstructor ( ĊĠĠĠ Ġ@ ApplicationContext Ġprivate Ġval Ġcontext : ĠContext , ĊĠĠĠ Ġprivate Ġval Ġrepository : ĠIS quare Repository , ĊĠĠĠ Ġprivate Ġval Ġio Dispatcher : ĠCor outine Dispatcher Ġ= ĠDispatch ers . IO Ċ ) Ġ: ĠCard Nonce Background Handler Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġhandle Entered Card In Background ( card Details : ĠCard Details ): ĠCard Entry Activity Command Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠAss uming Ġsquare Ġwill Ġhandle Ġthe Ġbackground Ġtask ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġrun Blocking ( io Dispatcher ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġrepository . confirm Payment ( Payment ( card Details . nonce , ĠMoney ( 1 5 5 . 4 5 f ), ĠMoney ( 4 5 f ))) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( response . is Successful ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCard Entry Activity Command . Finish () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġresponse Ġas ĠTask Result . Error ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCard Entry Activity Command . Show Error ( response . errorMessage . or Empty ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( exception : ĠIOException ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠCard Entry Activity Command . Show Error ( context . getString ( R . string . network _ failure )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ }