Skip to content

Commit

Permalink
fix : tax_free param type change String to Float
Browse files Browse the repository at this point in the history
feat : 모바일웹모드 custom WebChromeClient 추가


feat : custom webChromeClient 예제 추가


docs : update readme
  • Loading branch information
kjh5833 committed Sep 7, 2021
1 parent 9423e03 commit 7d6a294
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 12 deletions.
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Iamport.pluginMobileWebSupporter(webview)

- Custom WebViewClient 의 사용

[샘플앱의 예시 MyWebViewClient.kt](./app/src/main/java/com/iamport/sampleapp/ui/MyWebViewClient.kt)
[샘플앱의 예시 MyWebViewClient class](./app/src/main/java/com/iamport/sampleapp/MyWebViewClient.kt)

```kotlin
/**
Expand Down Expand Up @@ -249,6 +249,35 @@ class MobileWebViewModeFragment : Fragment() {
}
}

```


- Custom WebChromeClient 의 사용

[샘플앱의 예시 MyWebViewChromeClient class](./app/src/main/java/com/iamport/sampleapp/MyWebViewClient.kt)



```kotlin
/**
[IamportWebChromeClient] 상속하여 사용
*/
// CASE 1 : IamportWebChromeClient 상속
open class MyWebViewChromeClient : IamportWebChromeClient() {
override fun onJsConfirm(view: WebView, url: String, message: String, result: JsResult): Boolean {
Log.i("MyWebViewChromeClient", "called this function")
return super.onJsConfirm(view, url, message, result)
}
}

class MobileWebViewModeFragment : Fragment() {
override fun setupWebView() {
// IamportWebChromeClient 사용
it.webChromeClient = MyWebViewChromeClient()
// ..
}
}

```

</details>
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/java/com/iamport/sampleapp/MyWebViewClient.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.iamport.sampleapp

import android.util.Log
import android.webkit.JsResult
import android.webkit.WebResourceRequest
import android.webkit.WebView
import com.iamport.sdk.domain.IamportWebChromeClient
import com.iamport.sdk.domain.strategy.webview.IamPortMobileModeWebViewClient

open class MyWebViewClient : IamPortMobileModeWebViewClient() {
Expand All @@ -14,4 +16,13 @@ open class MyWebViewClient : IamPortMobileModeWebViewClient() {
return super.shouldOverrideUrlLoading(view, request)
}

}
}

open class MyWebViewChromeClient : IamportWebChromeClient() {

override fun onJsConfirm(view: WebView, url: String, message: String, result: JsResult): Boolean {
Log.i("MyWebViewChromeClient", "called this function")
return super.onJsConfirm(view, url, message, result)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.iamport.sampleapp.MyWebViewChromeClient
import com.iamport.sampleapp.MyWebViewClient
import com.iamport.sampleapp.databinding.WebViewModeFragmentBinding
import com.iamport.sdk.domain.core.Iamport
Expand Down Expand Up @@ -43,6 +44,7 @@ class MobileWebViewModeFragment : Fragment() {

// 통상적인 경우의 custom webviewClient
it.webViewClient = MyWebViewClient()
it.webChromeClient = MyWebViewChromeClient()

// oreo 미만에서 url 변경만 보고 싶은경우
Iamport.mobileWebModeShouldOverrideUrlLoading()?.observe(this, EventObserver { uri ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ data class PrepareRequest(
val pay_method: PayMethod = PayMethod.trans,//fixed
val escrow: Boolean?, // true or false
val amount: String, // 결제금액
val tax_free: String?, // 결제금액 중 면세공급가액,
val tax_free: Float?, // 결제금액 중 면세공급가액,
val name: String, //주문명,
val merchant_uid: String, // 가맹점 주문번호,
val customer_uid: String?, // 정기결제용
Expand Down Expand Up @@ -47,7 +47,7 @@ data class PrepareRequest(
PrepareRequest(
escrow = false,
amount = amount,
tax_free = Util.getOrZeroString(tax_free),
tax_free = tax_free,
name = Util.getOrEmpty(name),
merchant_uid = merchant_uid,
customer_uid = customer_uid,
Expand Down
12 changes: 6 additions & 6 deletions sdk/src/main/java/com/iamport/sdk/data/sdk/IamPortRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import kotlinx.serialization.Serializable
@Serializable
data class IamPortRequest(
val pg: String,
val pay_method: PayMethod = PayMethod.card, // 명세상 필수인지 불명확함, default card
val pay_method: PayMethod = PayMethod.card, // default card
val escrow: Boolean? = null, // default false
val merchant_uid: String, // default "random"
val customer_uid: String? = null, // 정기결제용
val name: String? = null,
val amount: String,
val custom_data: String? = null, // 명세상 불명확
val tax_free: String? = null,
val custom_data: String? = null,
val tax_free: Float? = null,
val currency: Currency? = null, // default KRW, 페이팔은 USD 이어야 함
val language: String? = null, // default "ko", en, zh, jp => TODO validator 에 추가
val buyer_name: String? = null,
Expand All @@ -36,7 +36,7 @@ data class IamPortRequest(
val digital: Boolean? = null, // default false
val vbank_due: String? = null, // YYYYMMDDhhmm
private var m_redirect_url: String? = Platform.native.redirectUrl, // 콜백
val app_scheme: String? = null, // 명세상 nullable 이나, RN 에서 필수
val app_scheme: String? = null,
val biz_num: String? = null,
val popup: Boolean? = null,
private val niceMobileV2 : Boolean = true,
Expand Down Expand Up @@ -96,7 +96,7 @@ data class IamPortRequest(
var name: String? = null

var custom_data: String? = null // 명세상 불명확
var tax_free: String? = null
var tax_free: Float? = null
var currency: Currency? = null // default KRW, 페이팔은 USD 이어야 함
var language: String? = null // default "ko"
var buyer_name: String? = null
Expand Down Expand Up @@ -158,7 +158,7 @@ data class IamPortRequest(
this.custom_data = custom_data
}

fun tax_free(tax_free: String) = apply {
fun tax_free(tax_free: Float) = apply {
this.tax_free = tax_free
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import android.webkit.WebChromeClient
import android.webkit.WebView


class IamportWebChromeClient : WebChromeClient() {
open class IamportWebChromeClient : WebChromeClient() {
override fun onJsConfirm(
view: WebView,
url: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,18 @@ open class IamPortMobileWebMode() : IamPortWebViewMode() {
setLayerType(View.LAYER_TYPE_HARDWARE, null)
clearCache(true) // FIXME: 안지워도 될까? 고민..
visibility = View.VISIBLE
webChromeClient = IamportWebChromeClient()
// webChromeClient = IamportWebChromeClient()

webChromeClient = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
webChromeClient.let {
if (it is IamportWebChromeClient) {
return@let it
}
IamportWebChromeClient()
}
} else {
IamportWebChromeClient()
}

webViewClient = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
webViewClient.let {
Expand Down

0 comments on commit 7d6a294

Please sign in to comment.