package Ġcom . cyber space . cyber pay flutter Ċ Ċ import Ġandroid . app . Activity Ċ import Ġandroid . content . Broadcast Receiver Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . Intent Ċ import Ġandroid . os . Battery Manager Ċ import Ġandroidx . annotation . NonNull Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġcom . cyber space . cyber p ays dk . Cy ber pay Sdk Ċ import Ġcom . cyber space . cyber p ays dk . Transaction Callback Ċ import Ġcom . cyber space . cyber p ays dk . model . Transaction Ċ import Ġio . flutter . embedding . engine . plugins . Flutter Plugin Ċ import Ġio . flutter . embedding . engine . plugins . activity . Activity Aware Ċ import Ġio . flutter . embedding . engine . plugins . activity . Activity Plugin Binding Ċ import Ġio . flutter . plugin . common .* Ċ import Ġio . flutter . plugin . common . Event Channel . Event Sink Ċ import Ġio . flutter . plugin . common . Method Channel . MethodCall Handler Ċ import Ġio . flutter . plugin . common . Method Channel . Result Ċ import Ġio . flutter . plugin . common . Plugin Registry . Registrar ĊĊ Ċ /** ĠCy ber pay flutter Plugin Ġ*/ Ċ public Ġclass ĠCy ber pay flutter Plugin : ĠFlutter Plugin , ĠMethod Call Handler , ĠActivity Aware , ĠPlugin Registry . Activity Result Listener Ġ{ ĊĠ Ġ/// ĠThe ĠMethod Channel Ġthat Ġwill Ġthe Ġcommunication Ġbetween ĠFlutter Ġand Ġnative ĠAndroid ĊĠ Ġ/// ĊĠ Ġ/// ĠThis Ġlocal Ġreference Ġserves Ġto Ġregister Ġthe Ġplugin Ġwith Ġthe ĠFlutter ĠEngine Ġand Ġunregister Ġit ĊĠ Ġ/// Ġwhen Ġthe ĠFlutter ĠEngine Ġis Ġdet ached Ġfrom Ġthe ĠActivity ĊĠ Ġprivate Ġlateinit Ġvar Ġchannel Ġ: ĠMethod Channel ĊĠ Ġprivate Ġlateinit Ġvar Ġevent Channel : ĠEvent Channel ĊĊĠ Ġprivate Ġvar Ġactivity : ĠActivity ? Ġ= Ġnull ĊĠ Ġprivate Ġvar Ġapplication Context : ĠContext ? Ġ= Ġnull ĊĠ Ġprivate Ġvar ĠRESULT _ CODE Ġ= Ġ 1 0 0 1 ĊĠ Ġprivate Ġvar Ġplugin Result : ĠResult ? Ġ= Ġnull ĊĠ Ġoverride Ġfun Ġon Attached To Engine (@ NonNull Ġflutter Plugin Binding : ĠFlutter Plugin . Flutter Plugin Binding ) Ġ{ ĊĠĠĠ Ġthis . application Context Ġ= Ġflutter Plugin Binding . application Context ; ĊĠĠĠ Ġon Attached To Engine ( flutter Plugin Binding . application Context , Ġflutter Plugin Binding . binary Messenger ) ĊĠ Ġ} ĊĊĠ Ġ// ĠThis Ġstatic Ġfunction Ġis Ġoptional Ġand Ġequivalent Ġto Ġon Attached To Engine . ĠIt Ġsupports Ġthe Ġold ĊĠ Ġ// Ġpre - Flutter - 1 . 1 2 ĠAndroid Ġprojects . ĠYou Ġare Ġencour aged Ġto Ġcontinue Ġsupporting ĊĠ Ġ// Ġplugin Ġregistration Ġvia Ġthis Ġfunction Ġwhile Ġapps Ġmigrate Ġto Ġuse Ġthe Ġnew ĠAndroid ĠAPIs ĊĠ Ġ// Ġpost - flutter - 1 . 1 2 Ġvia Ġhttps :// flutter . dev / go / android - project - migration . ĊĠ Ġ// ĊĠ Ġ// ĠIt Ġis Ġencour aged Ġto Ġshare Ġlogic Ġbetween Ġon Attached To Engine Ġand Ġregister With Ġto Ġkeep ĊĠ Ġ// Ġthem Ġfunction ally Ġequivalent . ĠOnly Ġone Ġof Ġon Attached To Engine Ġor Ġregister With Ġwill Ġbe Ġcalled ĊĠ Ġ// Ġdepending Ġon Ġthe Ġuser 's Ġproject . Ġon Attached To Engine Ġor Ġregister With Ġmust Ġboth Ġbe Ġdefined ĊĠ Ġ// Ġin Ġthe Ġsame Ġclass . ĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġ@ Jvm Static ĊĠĠĠ Ġfun Ġregister With ( regist rar : ĠRegist rar ) Ġ{ ĊĠĠĠĠĠ Ġval Ġinstance Ġ= ĠCy ber pay flutter Plugin () ĊĠĠĠĠĠ Ġregist rar . add Activity Result Listener ( instance ) ĊĠĠĠĠĠ Ġinstance . on Attached To Engine ( regist rar . context (), Ġregist rar . messenger ()); ĊĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġon Attached To Engine ( application Context : ĠContext , Ġmess enger : ĠBinary Messenger ) Ġ{ ĊĠĠĠ Ġthis . application Context Ġ= Ġapplication Context ĊĠĠĠ Ġchannel Ġ= ĠMethod Channel ( messenger , Ġ" cyber pay flutter ") ĊĠĠĠ Ġchannel . set MethodCall Handler ( this ) ĊĠ Ġ} ĊĠ Ġoverride Ġfun Ġon MethodCall (@ NonNull Ġcall : ĠMethod Call , Ġ@ NonNull Ġresult : ĠResult ) Ġ{ ĊĠĠĠ Ġplugin Result Ġ= Ġresult ĊĠĠĠ Ġif Ġ( call . method Ġ== Ġ" get Platform Version ") Ġ{ ĊĠĠĠĠĠ Ġresult . success (" Android Ġ${ android . os . Build . VERSION . RELEASE }") ĊĠĠĠ Ġ} ĊĠĠĠ Ġelse Ġif Ġ( call . method Ġ== Ġ" checkout ") Ġ{ ĊĠĠĠĠĠ Ġval Ġintegration Key Ġ= Ġcall . argument < String >(" integration Key "). toString () ĊĠĠĠĠĠ Ġval Ġamount Ġ= Ġcall . argument < Double >(" amount ") ĊĠĠĠĠĠ Ġval Ġcustomer Email : ĠString Ġ= Ġcall . argument < String >(" customer Email "). toString () ĊĠĠĠĠĠ Ġval Ġlive Mode Ġ= Ġcall . argument < Boolean >(" live Mode ") ĊĊĠĠĠĠĠ Ġval Ġintent Ġ= ĠIntent ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġactivity , ĠPayment Activity :: class . java ) ĊĠĠĠĠĠ Ġintent . putExtra (" integration Key ", Ġintegration Key ) ĊĠĠĠĠĠ Ġintent . putExtra (" mode ", Ġlive Mode ) ĊĠĠĠĠĠ Ġintent . putExtra (" reference Mode ", Ġfalse ) ĊĠĠĠĠĠ Ġintent . putExtra (" customer Email ", Ġcustomer Email ) ĊĠĠĠĠĠ Ġintent . putExtra (" amount ", Ġamount ) ĊĊĠĠĠĠĠ Ġactivity !!. startActivity For Result ( intent , ĠRESULT _ CODE ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġelse Ġif Ġ( call . method Ġ== Ġ" checkout Ref ") Ġ{ ĊĠĠĠĠĠ Ġval Ġintegration Key Ġ= Ġcall . argument < String >(" integration Key "). toString () ĊĠĠĠĠĠ Ġval Ġreference : ĠString Ġ= Ġcall . argument < String >(" reference "). toString () ĊĠĠĠĠĠ Ġval Ġlive Mode Ġ= Ġcall . argument < Boolean >(" live Mode ") ĊĠĠĠĠĠ Ġval Ġintent Ġ= ĠIntent ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġactivity , ĠPayment Activity :: class . java ) ĊĠĠĠĠĠ Ġintent . putExtra (" integration Key ", Ġintegration Key ) ĊĠĠĠĠĠ Ġintent . putExtra (" mode ", Ġlive Mode ) ĊĠĠĠĠĠ Ġintent . putExtra (" reference ", Ġreference ) ĊĠĠĠĠĠ Ġintent . putExtra (" reference Mode ", Ġtrue ) ĊĠĠĠĠĠ Ġactivity !!. startActivity For Result ( intent , ĠRESULT _ CODE ) ĊĠĠĠ Ġ} ĊĠĠĠĠ Ġelse Ġ{ ĊĠĠĠĠĠ Ġresult . not Implemented () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Activity Result ( request Code : ĠInt , ĠresultCode : ĠInt , Ġdata : ĠIntent ?): ĠBoolean Ġ{ ĊĠĠĠ Ġif Ġ( request Code Ġ== ĠRESULT _ CODE ) Ġ{ ĊĠĠĠĠĠ Ġif Ġ( result Code Ġ== ĠActivity . RESULT _ OK ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( data !!. has Extra (" success ")){ ĊĠĠĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġdata . getString Extra (" success ") ĊĠĠĠĠĠĠĠĠĠ Ġplugin Result !!. success ( result ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġelse Ġif Ġ( data . has Extra (" error ")){ ĊĠĠĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġdata . getString Extra (" error ") ĊĠĠĠĠĠĠĠĠĠ Ġplugin Result !!. error (" CY BER PAY _ ERROR ", Ġresult , null Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġplugin Result !!. not Implemented () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġtrue ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġfalse ĊĠ Ġ} ĊĠ Ġoverride Ġfun Ġon Detached From Engine (@ NonNull Ġbinding : ĠFlutter Plugin . Flutter Plugin Binding ) Ġ{ ĊĠĠĠ Ġchannel . set MethodCall Handler ( null ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Attached To Activity ( binding : ĠActivity Plugin Binding ) Ġ{ ĊĠĠĠ Ġactivity Ġ= Ġbinding . activity ĊĠĠĠ Ġbinding . add Activity Result Listener ( this ); ĊĠĠĠ Ġchannel . set MethodCall Handler ( this ) ĊĠ Ġ} ĊĠ Ġoverride Ġfun Ġon Detached From Activity () Ġ{ ĊĠĠĠ Ġactivity Ġ= Ġnull ĊĠĠĠ Ġchannel . set MethodCall Handler ( null ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Re attached To Activity For Config Changes ( binding : ĠActivity Plugin Binding ) Ġ{ ĊĠĠĠ Ġactivity Ġ= Ġbinding . activity ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Detached From Activity For Config Changes () Ġ{ ĊĠĠĠ Ġactivity Ġ= Ġnull ĊĠ Ġ} ĊĊĊ Ċ } Ċ