Skip to content

Commit

Permalink
handle for google Pay ,
Browse files Browse the repository at this point in the history
- added fix of detached window to destory webview
  • Loading branch information
aslm-android committed Jan 10, 2024
1 parent 0464edc commit 3eab7f0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 61 deletions.
5 changes: 2 additions & 3 deletions app/src/main/java/com/example/knet_android/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ class MainActivity : AppCompatActivity() ,KnetPayStatusDelegate{
val post = HashMap<String,Any>()
post.put("url",posturl?: "")

val redirect = HashMap<String,Any>()
redirect.put("url","onTapKnetRedirect://")
// val redirect = HashMap<String,Any>()
// redirect.put("url","onTapKnetRedirect://")
val configuration = LinkedHashMap<String,Any>()


Expand Down Expand Up @@ -378,7 +378,6 @@ class MainActivity : AppCompatActivity() ,KnetPayStatusDelegate{
configuration.put("invoice",invoice)
configuration.put("interface",interfacee)
configuration.put("post",post)
configuration.put("redirect",redirect)
configuration.put("scope",scopeKey.toString())
configuration.put("transaction",transaction)
configuration.put("acceptance",acceptance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class TapKnetConfiguration {
hashMapHeader[HeadersMdn] = headers.mdn.toString()
hashMapHeader[HeadersApplication] = headers.application.toString()
val redirect = HashMap<String,Any>()
redirect.put("url","onTapRedirect://")
redirect.put(urlKey, redirectValue)
configurationsAsHashMap?.put(headersKey, hashMapHeader)
configurationsAsHashMap?.put(redirectKey, redirect)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.net.http.SslError
import android.os.Build
import android.util.AttributeSet
import android.util.Log
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.ViewGroup
import android.webkit.*
Expand Down Expand Up @@ -98,27 +99,14 @@ class TapKnetPay : LinearLayout {
javaScriptEnabled = true
domStorageEnabled = true
javaScriptCanOpenWindowsAutomatically = true
allowUniversalAccessFromFileURLs = true
allowFileAccessFromFileURLs = true
allowContentAccess = true
allowFileAccess = true
setSupportMultipleWindows(true)
cacheMode = WebSettings.LOAD_CACHE_ELSE_NETWORK
mixedContentMode = 0
useWideViewPort = true
loadWithOverviewMode = true
builtInZoomControls = true
displayZoomControls = true
setSupportZoom(true)
defaultTextEncodingName = "utf-8"
databaseEnabled = true

pluginState = WebSettings.PluginState.ON
}
}
knetWebView.setBackgroundColor(Color.TRANSPARENT)


knetWebView.setLayerType(LAYER_TYPE_SOFTWARE, null)
webChrome = WebChrome(context)
knetWebView.webChromeClient = webChrome
Expand All @@ -141,6 +129,8 @@ class TapKnetPay : LinearLayout {
knetWebView.loadUrl(urlToBeloaded)
}
}


}

private fun initializePaymentData(buttonType: ThreeDsPayButtonType?) {
Expand Down Expand Up @@ -168,16 +158,6 @@ class TapKnetPay : LinearLayout {
webViewScheme = scheme.value.second
}

private fun getHeaders(): Headers {
val extraHeaders: MutableMap<String, String> = HashMap()
extraHeaders["Cache-Control"] = "no-cache"
extraHeaders["Pragma"] = "no-cache"
extraHeaders["Accept-Encoding"] = "gzip, deflate, br"
extraHeaders["Accept"] = "application/json, text/plain, */*"

return extraHeaders.toHeaders()
}


private fun applyTheme() {
/**
Expand Down Expand Up @@ -321,14 +301,14 @@ class TapKnetPay : LinearLayout {
}
if (request?.url.toString().contains(KnetStatusDelegate.onChargeCreated.name)) {

// val data = request?.url?.getQueryParameterFromUri(keyValueName).toString()
// Log.e("chargedData",data.toString())
// val gson = Gson()
// threeDsResponse = gson.fromJson(data, ThreeDsResponse::class.java)
// when (threeDsResponse.stopRedirection) {
// false -> navigateTo3dsActivity(PaymentFlow.PAYMENTBUTTON.name)
// else -> {}
// }
val data = request?.url?.getQueryParameterFromUri(keyValueName).toString()
Log.e("chargedData", data.toString())
val gson = Gson()
threeDsResponse = gson.fromJson(data, ThreeDsResponse::class.java)
when (threeDsResponse.stopRedirection) {
false -> navigateTo3dsActivity(PaymentFlow.PAYMENTBUTTON.name)
else -> {}
}
DataConfiguration.getTapKnetListener()?.onChargeCreated(
request?.url?.getQueryParameterFromUri(keyValueName).toString()
)
Expand Down Expand Up @@ -434,12 +414,7 @@ class TapKnetPay : LinearLayout {
view: WebView?,
request: WebResourceRequest?
): WebResourceResponse? {
val webResourceResponse = super.shouldInterceptRequest(view, request)
Log.e("request", request?.method.toString())
Log.e("request", request?.requestHeaders.toString())
Log.e("request", request?.url.toString())

return webResourceResponse
return super.shouldInterceptRequest(view, request)
}

override fun onReceivedError(
Expand All @@ -452,21 +427,12 @@ class TapKnetPay : LinearLayout {
}
}

private fun initWeb() {

MainScope().launch {
val url =
"${webviewStarterUrl}${encodeConfigurationMapToUrl(DataConfiguration.configurationsAsHashMap)}"
Log.e("url here", url)
knetWebView.post {
knetWebView.stopLoading()
knetWebView.loadUrl(url)
}

}
override fun onDetachedFromWindow() {
Log.e("detached","here")
knetWebView.destroy()
super.onDetachedFromWindow()
}


}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const val operatorKey = "operator"
const val headersKey = "headers"

const val redirectKey = "redirect"
const val redirectValue = "onTapRedirect://"

const val urlKey = "url"
const val careemPayUrlHandler ="https://checkout"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,12 @@ class ThreeDsWebViewActivityButton : AppCompatActivity() {
when (paymentFlow) {
PaymentFlow.PAYMENTBUTTON.name -> {
webView?.loadUrl(request?.url.toString())
val Redirect =
DataConfiguration.configurationsAsHashMap?.get(redirectKey) as HashMap<*, *>
val Redirect = DataConfiguration.configurationsAsHashMap?.get(redirectKey) as HashMap<*, *>
val redirect = Redirect.get(urlKey)
when (request?.url?.toString()
?.contains(redirect.toString(), ignoreCase = true)) {
when (request?.url?.toString()?.contains(redirect.toString(), ignoreCase = true)) {
true -> {
threeDsBottomsheet.dialog?.dismiss()
val splittiedString = request.url.toString()
.split(redirect.toString() + "?", ignoreCase = true)
val splittiedString = request.url.toString().split("?", ignoreCase = true)
Log.e("splittedString", splittiedString.toString())
try {
TapKnetPay.retrieve(splittiedString[1])
Expand Down Expand Up @@ -147,7 +144,9 @@ class ThreeDsWebViewActivityButton : AppCompatActivity() {
return
} else {
doAfterSpecificTime(time = delayTime) {
threeDsBottomsheet.show(supportFragmentManager, "")
if (!supportFragmentManager.isDestroyed){
threeDsBottomsheet.show(supportFragmentManager, "")
}
}
}
loadedBottomSheet = true
Expand Down

0 comments on commit 3eab7f0

Please sign in to comment.