@@ -28,112 +28,121 @@ import java.lang.ref.WeakReference
2828 * Umbrella class for setting DropIn and Component specific parameters
2929 */
3030object AdyenCheckout {
31- private var currentComponent: WeakReference <Component > = WeakReference (null )
32- private val dropInCallback = DropInCallbackListener ()
33- internal var dropInLauncher: ActivityResultLauncher <DropInResultContractParams >? = null
34- internal var dropInSessionLauncher: ActivityResultLauncher <SessionDropInResultContractParams >? =
35- null
31+ private var currentComponent: WeakReference <Component > = WeakReference (null )
32+ private val dropInCallback = DropInCallbackListener ()
33+ internal var dropInLauncher: ActivityResultLauncher <DropInResultContractParams >? = null
34+ internal var dropInSessionLauncher: ActivityResultLauncher <SessionDropInResultContractParams >? =
35+ null
3636
37- @JvmStatic
38- internal fun addDropInListener (callback : ReactDropInCallback ) {
39- dropInCallback.callback = WeakReference (callback)
40- }
37+ @JvmStatic
38+ internal fun addDropInListener (callback : ReactDropInCallback ) {
39+ dropInCallback.callback = WeakReference (callback)
40+ }
4141
42- @JvmStatic
43- internal fun removeDropInListener () {
44- dropInCallback.callback.clear()
45- }
42+ @JvmStatic
43+ internal fun removeDropInListener () {
44+ dropInCallback.callback.clear()
45+ }
4646
47- /* *
48- * Persist a reference to Activity that will present DropIn or Component
49- * @param activity parent activity for DropIn or Component
50- */
51- @JvmStatic
52- fun setLauncherActivity (activity : ActivityResultCaller ) {
53- dropInLauncher = DropIn .registerForDropInResult(
54- activity, dropInCallback as DropInCallback
55- )
56- dropInSessionLauncher = DropIn .registerForDropInResult(
57- activity, dropInCallback as SessionDropInCallback
58- )
59- }
47+ /* *
48+ * Persist a reference to Activity that will present DropIn or Component
49+ * @param activity parent activity for DropIn or Component
50+ */
51+ @JvmStatic
52+ fun setLauncherActivity (activity : ActivityResultCaller ) {
53+ dropInLauncher =
54+ DropIn .registerForDropInResult(
55+ activity,
56+ dropInCallback as DropInCallback ,
57+ )
58+ dropInSessionLauncher =
59+ DropIn .registerForDropInResult(
60+ activity,
61+ dropInCallback as SessionDropInCallback ,
62+ )
63+ }
6064
61- /* *
62- * Allow Adyen Components to process intents.
63- * @param intent received redirect intent
64- * @return `true` when intent could be handled by AdyenCheckout
65- */
66- @JvmStatic
67- fun handleIntent (intent : Intent ): Boolean {
68- if (intent.data == null ) {
69- return false
70- }
71- val actionHandlingComponent = currentComponent.get() as ? ActionHandlingComponent
72- return if (actionHandlingComponent != null ) {
73- actionHandlingComponent.handleIntent(intent)
74- true
75- } else {
76- Log .e(TAG , " Nothing registered as ActivityResultHandling" )
77- false
78- }
65+ /* *
66+ * Allow Adyen Components to process intents.
67+ * @param intent received redirect intent
68+ * @return `true` when intent could be handled by AdyenCheckout
69+ */
70+ @JvmStatic
71+ fun handleIntent (intent : Intent ): Boolean {
72+ if (intent.data == null ) {
73+ return false
7974 }
80-
81- @JvmStatic
82- internal fun setComponent (component : Component ) {
83- currentComponent = WeakReference (component)
75+ val actionHandlingComponent = currentComponent.get() as ? ActionHandlingComponent
76+ return if (actionHandlingComponent != null ) {
77+ actionHandlingComponent.handleIntent(intent)
78+ true
79+ } else {
80+ Log .e(TAG , " Nothing registered as ActivityResultHandling" )
81+ false
8482 }
83+ }
8584
86- @JvmStatic
87- internal fun removeComponent () {
88- currentComponent.clear()
89- }
85+ @JvmStatic
86+ internal fun setComponent (component : Component ) {
87+ currentComponent = WeakReference (component)
88+ }
89+
90+ @JvmStatic
91+ internal fun removeComponent () {
92+ currentComponent.clear()
93+ }
9094
91- /* *
92- * Allow Adyen Components to process intents.
93- * @param requestCode received redirect intent
94- * @param resultCode received redirect intent
95- * @param data received redirect intent
96- */
97- @JvmStatic
98- fun handleActivityResult (requestCode : Int , resultCode : Int , data : Intent ? ) {
99- if (requestCode == GooglePayModule .GOOGLEPAY_REQUEST_CODE ) {
100- val activityResultHandlingComponent =
101- currentComponent.get() as ? ActivityResultHandlingComponent
102- if (activityResultHandlingComponent != null ) {
103- activityResultHandlingComponent.handleActivityResult(resultCode, data)
104- } else {
105- Log .e(TAG , " Nothing registered as ActivityResultHandling" )
106- }
107- }
95+ /* *
96+ * Allow Adyen Components to process intents.
97+ * @param requestCode received redirect intent
98+ * @param resultCode received redirect intent
99+ * @param data received redirect intent
100+ */
101+ @JvmStatic
102+ fun handleActivityResult (
103+ requestCode : Int ,
104+ resultCode : Int ,
105+ data : Intent ? ,
106+ ) {
107+ if (requestCode == GooglePayModule .GOOGLEPAY_REQUEST_CODE ) {
108+ val activityResultHandlingComponent =
109+ currentComponent.get() as ? ActivityResultHandlingComponent
110+ if (activityResultHandlingComponent != null ) {
111+ activityResultHandlingComponent.handleActivityResult(resultCode, data)
112+ } else {
113+ Log .e(TAG , " Nothing registered as ActivityResultHandling" )
114+ }
108115 }
116+ }
109117
110- private const val TAG = " AdyenCheckout"
118+ private const val TAG = " AdyenCheckout"
111119}
112120
113- private class DropInCallbackListener : DropInCallback , SessionDropInCallback {
121+ private class DropInCallbackListener :
122+ DropInCallback ,
123+ SessionDropInCallback {
124+ var callback: WeakReference <ReactDropInCallback > =
125+ WeakReference (null )
114126
115- var callback: WeakReference <ReactDropInCallback > =
116- WeakReference (null )
117-
118- override fun onDropInResult (dropInResult : DropInResult ? ) {
119- callback.get()?.let {
120- when (dropInResult) {
121- is DropInResult .CancelledByUser -> it.onCancel()
122- is DropInResult .Error -> it.onError(dropInResult.reason)
123- is DropInResult .Finished -> it.onCompleted(dropInResult.result)
124- null -> return
125- }
126- }
127+ override fun onDropInResult (dropInResult : DropInResult ? ) {
128+ callback.get()?.let {
129+ when (dropInResult) {
130+ is DropInResult .CancelledByUser -> it.onCancel()
131+ is DropInResult .Error -> it.onError(dropInResult.reason)
132+ is DropInResult .Finished -> it.onCompleted(dropInResult.result)
133+ null -> return
134+ }
127135 }
136+ }
128137
129- override fun onDropInResult (sessionDropInResult : SessionDropInResult ? ) {
130- callback.get()?.let {
131- when (sessionDropInResult) {
132- is SessionDropInResult .CancelledByUser -> it.onCancel()
133- is SessionDropInResult .Error -> it.onError(sessionDropInResult.reason)
134- is SessionDropInResult .Finished -> it.onFinished(sessionDropInResult.result)
135- null -> return
136- }
137- }
138+ override fun onDropInResult (sessionDropInResult : SessionDropInResult ? ) {
139+ callback.get()?.let {
140+ when (sessionDropInResult) {
141+ is SessionDropInResult .CancelledByUser -> it.onCancel()
142+ is SessionDropInResult .Error -> it.onError(sessionDropInResult.reason)
143+ is SessionDropInResult .Finished -> it.onFinished(sessionDropInResult.result)
144+ null -> return
145+ }
138146 }
139- }
147+ }
148+ }
0 commit comments