Skip to content

Commit

Permalink
feat : 나이스 + 뱅크페이 로직 제거
Browse files Browse the repository at this point in the history
나이스 + 뱅크페이 결제시 특별한 작업이 없어도 결제가 잘 되어 제거 함
fix : 모바일 웹 모드 이니시스 + 뱅크페이 취소시 버그 수정
  • Loading branch information
kjh5833 committed Aug 4, 2021
1 parent 17afc36 commit f4e7e8b
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 112 deletions.
2 changes: 1 addition & 1 deletion sdk/src/main/java/com/iamport/sdk/domain/di/appModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ val appModule = module {
single { JudgeStrategy() }
single { ChaiStrategy() }
single { WebViewStrategy() }
single { NiceTransWebViewStrategy() }
// single { NiceTransWebViewStrategy() }
single { CertificationWebViewStrategy() }

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.iamport.sdk.domain.strategy.base.IStrategy
import com.iamport.sdk.domain.strategy.base.JudgeStrategy
import com.iamport.sdk.domain.strategy.chai.ChaiStrategy
import com.iamport.sdk.domain.strategy.webview.IamPortMobileModeWebViewClient
import com.iamport.sdk.domain.strategy.webview.NiceTransWebViewStrategy
import com.iamport.sdk.domain.strategy.webview.WebViewStrategy
import com.orhanobut.logger.Logger
import org.koin.core.component.KoinApiExtension
Expand All @@ -25,7 +24,7 @@ class StrategyRepository : IamportKoinComponent {

private val webViewStrategy: WebViewStrategy by inject() // webview 사용하는 pg

private val niceTransWebViewStrategy: NiceTransWebViewStrategy by inject()
// private val niceTransWebViewStrategy: NiceTransWebViewStrategy by inject()

/**
* 실제로 앱 띄울 결제 타입
Expand Down Expand Up @@ -72,7 +71,7 @@ class StrategyRepository : IamportKoinComponent {
Pair(it, request.pay_method).let { pair: Pair<PG, PayMethod> ->
return when {
isChaiPayment(pair) -> PaymentKinds.CHAI
isNiceTransPayment(pair) -> PaymentKinds.NICE
isNiceTransPayment(pair) -> PaymentKinds.WEB // PaymentKinds.NICE 사용 안함
else -> PaymentKinds.WEB
}
}
Expand All @@ -81,24 +80,26 @@ class StrategyRepository : IamportKoinComponent {
}

// for 결제요청
fun getWebViewStrategy(payment: Payment): IStrategy {
return when (getPaymentKinds(payment)) {
PaymentKinds.NICE -> niceTransWebViewStrategy
else -> webViewStrategy
}
fun getWebViewStrategy(): IStrategy {
return webViewStrategy
// return when (getPaymentKinds(payment)) {
// PaymentKinds.NICE -> niceTransWebViewStrategy
// else -> webViewStrategy
// }
}

// for webview mode inject
fun getWebViewClient(payment: Payment): WebViewClient {
return when (getPaymentKinds(payment)) {
PaymentKinds.NICE -> niceTransWebViewStrategy
else -> webViewStrategy
}
fun getWebViewClient(): WebViewClient {
return webViewStrategy
// return when (getPaymentKinds(payment)) {
// PaymentKinds.NICE -> niceTransWebViewStrategy
// else -> webViewStrategy
// }
}

fun getNiceTransWebViewClient(): NiceTransWebViewStrategy {
return niceTransWebViewStrategy
}
// fun getNiceTransWebViewClient(): NiceTransWebViewStrategy {
// return niceTransWebViewStrategy
// }

fun getMobileWebModeClient(): IamPortMobileModeWebViewClient {
return mobileWebModeStrategy ?: run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import android.os.Build
import android.webkit.WebResourceRequest
import android.webkit.WebView
import androidx.annotation.RequiresApi
import com.iamport.sdk.data.nice.BankPayResultCode
import com.iamport.sdk.domain.utils.Event
import com.orhanobut.logger.Logger

open class IamPortMobileModeWebViewClient : NiceTransWebViewStrategy() {
open class IamPortMobileModeWebViewClient : WebViewStrategy() {

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
Expand All @@ -19,5 +20,4 @@ open class IamPortMobileModeWebViewClient : NiceTransWebViewStrategy() {

return super.shouldOverrideUrlLoading(view, request)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import com.orhanobut.logger.Logger.*
import java.net.URLDecoder
import java.nio.charset.StandardCharsets

/**
// 해당로직 쓰지 않아도 정상 결제 되는 듯 함
// NiceTransWebViewStrategy 가 필요없어진 듯
// bankpay launcher 도 삭제해도 될 듯
*/

open class NiceTransWebViewStrategy : WebViewStrategy() {

// private val niceApi: NiceApi by inject()
Expand All @@ -29,16 +35,16 @@ open class NiceTransWebViewStrategy : WebViewStrategy() {

request?.url?.let {
d("아주 나이스~ $it")
if (isNiceTransScheme(it)) {

bankTid = it.getQueryParameter(NiceBankpay.USER_KEY).toString()
niceTransUrl = it.getQueryParameter(NiceBankpay.CALLBACKPARAM).toString()

makeBankPayData(it)?.let { data ->
bus.niceTransRequestParam.postValue(Event(data)) // 뱅크페이 앱 열기
}
return true
}
// if (isNiceTransScheme(it)) {
//
// bankTid = it.getQueryParameter(NiceBankpay.USER_KEY).toString()
// niceTransUrl = it.getQueryParameter(NiceBankpay.CALLBACKPARAM).toString()
//
// makeBankPayData(it)?.let { data ->
// bus.niceTransRequestParam.postValue(Event(data)) // 뱅크페이 앱 열기
// }
// return true
// }
}

return super.shouldOverrideUrlLoading(view, request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UICoroutineScope(private val dispatchers: CoroutineContext = Dispatchers.M
get() = dispatchers + job

override fun releaseCoroutine() {
Logger.d("UICoroutineScope", "onRelease coroutine")
Logger.d("UICoroutineScope onRelease coroutine")
job.cancel()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object WebViewLiveDataEventBus {
val openWebView = MutableLiveData<Event<Payment>>()

// 나이스 + 실시간계좌 뱅크페이 앱 결과
val niceTransRequestParam = MutableLiveData<Event<String>>()
// val niceTransRequestParam = MutableLiveData<Event<String>>()

// 외부앱
val thirdPartyUri = MutableLiveData<Event<Uri>>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.iamport.sdk.data.sdk.Payment
interface BaseMain {
fun openWebView(payment: Payment)
fun openThirdPartyApp(it: Uri)
fun openNiceTransApp(it: String)
// fun openNiceTransApp(it: String)
fun observeViewModel(payment: Payment?)
fun requestPayment(it: Payment)
fun sdkFinish(iamPortResponse: IamPortResponse?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.os.Build
import android.view.View
import android.webkit.WebView
import androidx.activity.ComponentActivity
import androidx.activity.result.ActivityResultLauncher
import androidx.lifecycle.LiveData
import com.iamport.sdk.data.sdk.IamPortResponse
import com.iamport.sdk.data.sdk.Payment
Expand All @@ -17,7 +16,7 @@ import com.orhanobut.logger.Logger
import org.koin.core.component.KoinApiExtension

@KoinApiExtension
open class IamPortMobileWebMode(bankPayLauncher: ActivityResultLauncher<String>?) : IamPortWebViewMode(bankPayLauncher = bankPayLauncher) {
open class IamPortMobileWebMode() : IamPortWebViewMode() {

fun initStart(activity: ComponentActivity, webview: WebView) {
Logger.i("HELLO I'MPORT Mobile Web Mode SDK!")
Expand All @@ -28,10 +27,10 @@ open class IamPortMobileWebMode(bankPayLauncher: ActivityResultLauncher<String>?
observeViewModel(null) // 관찰할 LiveData
}

override fun processBankPayPayment(resPair: Pair<String, String>) {
Logger.d("processBankPayPayment")
viewModel.mobileModeProcessBankPayPayment(resPair)
}
// override fun processBankPayPayment(resPair: Pair<String, String>) {
// Logger.d("ignore processBankPayPayment")
// viewModel.mobileModeProcessBankPayPayment(resPair)
// }


/**
Expand All @@ -40,7 +39,7 @@ open class IamPortMobileWebMode(bankPayLauncher: ActivityResultLauncher<String>?
override fun observeViewModel(payment: Payment?) {
activity?.run {

viewModel.niceTransRequestParam().observe(this, EventObserver(this@IamPortMobileWebMode::openNiceTransApp))
// viewModel.niceTransRequestParam().observe(this, EventObserver(this@IamPortMobileWebMode::openNiceTransApp))
viewModel.thirdPartyUri().observe(this, EventObserver(this@IamPortMobileWebMode::openThirdPartyApp))
viewModel.impResponse().observe(this, EventObserver(this@IamPortMobileWebMode::sdkFinish))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.net.Uri
import android.view.View
import android.webkit.WebView
import androidx.activity.ComponentActivity
import androidx.activity.result.ActivityResultLauncher
import com.google.gson.GsonBuilder
import com.iamport.sdk.data.sdk.IamPortResponse
import com.iamport.sdk.data.sdk.Payment
Expand All @@ -24,7 +23,6 @@ import org.koin.core.qualifier.named

@KoinApiExtension
open class IamPortWebViewMode @JvmOverloads constructor(
val bankPayLauncher: ActivityResultLauncher<String>?,
scope: BaseCoroutineScope = UICoroutineScope()
) : IamportKoinComponent, BaseMain, BaseCoroutineScope by scope {

Expand All @@ -45,9 +43,9 @@ open class IamPortWebViewMode @JvmOverloads constructor(
observeViewModel(payment) // 관찰할 LiveData
}

open fun processBankPayPayment(resPair: Pair<String, String>) {
viewModel.processBankPayPayment(resPair)
}
// open fun processBankPayPayment(resPair: Pair<String, String>) {
// viewModel.processBankPayPayment(resPair)
// }

/**
* 관찰할 LiveData 옵저빙
Expand All @@ -58,7 +56,7 @@ open class IamPortWebViewMode @JvmOverloads constructor(
activity?.let {
viewModel.run {
openWebView().observe(it, EventObserver(this@IamPortWebViewMode::openWebView))
niceTransRequestParam().observe(it, EventObserver(this@IamPortWebViewMode::openNiceTransApp))
// niceTransRequestParam().observe(it, EventObserver(this@IamPortWebViewMode::openNiceTransApp))
thirdPartyUri().observe(it, EventObserver(this@IamPortWebViewMode::openThirdPartyApp))
impResponse().observe(it, EventObserver(this@IamPortWebViewMode::sdkFinish))

Expand Down Expand Up @@ -88,7 +86,7 @@ open class IamPortWebViewMode @JvmOverloads constructor(
viewModel.run {
d("do removeObservers")
openWebView().removeObservers(it)
niceTransRequestParam().removeObservers(it)
// niceTransRequestParam().removeObservers(it)
thirdPartyUri().removeObservers(it)
impResponse().removeObservers(it)
}
Expand Down Expand Up @@ -125,15 +123,15 @@ open class IamPortWebViewMode @JvmOverloads constructor(
/**
* 뱅크페이 외부앱 열기 for nice PG + 실시간계좌이체(trans)
*/
override fun openNiceTransApp(it: String) {
d("openNiceTransApp $it")
runCatching {
bankPayLauncher?.launch(it)
}.onFailure {
// 뱅크페이 앱 패키지는 하드코딩
activity?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(Util.getMarketId(ProvidePgPkg.BANKPAY.pkg))))
}
}
// override fun openNiceTransApp(it: String) {
// d("openNiceTransApp $it")
// runCatching {
// bankPayLauncher?.launch(it)
// }.onFailure {
//// 뱅크페이 앱 패키지는 하드코딩
// activity?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(Util.getMarketId(ProvidePgPkg.BANKPAY.pkg))))
// }
// }

/**
* 외부앱 열기
Expand Down Expand Up @@ -200,7 +198,7 @@ open class IamPortWebViewMode @JvmOverloads constructor(
JsNativeInterface(payment, get(named("${CONST.KOIN_KEY}Gson")), evaluateJS),
CONST.PAYMENT_WEBVIEW_JS_INTERFACE_NAME
)
webViewClient = viewModel.getWebViewClient(payment)
webViewClient = viewModel.getWebViewClient()
visibility = View.VISIBLE

loadUrl(CONST.PAYMENT_FILE_URL) // load WebView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ import com.iamport.sdk.data.sdk.IamPortApprove
import com.iamport.sdk.data.sdk.IamPortResponse
import com.iamport.sdk.data.sdk.Payment
import com.iamport.sdk.data.sdk.ProvidePgPkg
import com.iamport.sdk.domain.core.Iamport
import com.iamport.sdk.domain.core.IamportReceiver
import com.iamport.sdk.domain.di.IamportKoinComponent
import com.iamport.sdk.domain.utils.*
import com.iamport.sdk.domain.utils.Util.observeAlways
import com.iamport.sdk.presentation.contract.BankPayContract
import com.iamport.sdk.presentation.contract.ChaiContract
import com.iamport.sdk.presentation.viewmodel.MainViewModel
import com.iamport.sdk.presentation.viewmodel.MainViewModelFactory
Expand Down Expand Up @@ -63,8 +61,8 @@ internal class IamportSdk(
// ---------------------------------------------

// 뱅크페이 앱 런처s
private var bankPayLauncher: ActivityResultLauncher<String>? = null // 뱅크페이 앱 런처(for webview & mobile web mode)
private val bankPayContract by lazy { BankPayContract() }
// private var bankPayLauncher: ActivityResultLauncher<String>? = null // 뱅크페이 앱 런처(for webview & mobile web mode)
// private val bankPayContract by lazy { BankPayContract() }

// 차이 앱 런처
private var launcherChai: ActivityResultLauncher<Pair<String, String>>? = null // 차이앱 런처
Expand Down Expand Up @@ -100,21 +98,21 @@ internal class IamportSdk(
MODE.ACTIVITY -> {
hostHelper.getActivityRef()?.run {
launcherChai = registerForActivityResult(chaiContract) { resultCallback() }
bankPayLauncher = registerForActivityResult(bankPayContract) {
if (it != null) {
resultBankPayAppCallback(it)
}
}
// bankPayLauncher = registerForActivityResult(bankPayContract) {
// if (it != null) {
// resultBankPayAppCallback(it)
// }
// }
}
}
MODE.FRAGMENT -> {
hostHelper.getFragmentRef()?.run {
launcherChai = registerForActivityResult(chaiContract) { resultCallback() }
bankPayLauncher = registerForActivityResult(bankPayContract) {
if (it != null) {
resultBankPayAppCallback(it)
}
}
// bankPayLauncher = registerForActivityResult(bankPayContract) {
// if (it != null) {
// resultBankPayAppCallback(it)
// }
// }
}
}
MODE.NONE -> {
Expand Down Expand Up @@ -155,7 +153,7 @@ internal class IamportSdk(

hostHelper.getActivityRef()?.let {
webviewRef.get()?.let { webview ->
iamPortMobileWebMode = IamPortMobileWebMode(bankPayLauncher)
iamPortMobileWebMode = IamPortMobileWebMode()
iamPortMobileWebMode?.initStart(it, webview) // webview only 모드
}
}
Expand Down Expand Up @@ -386,14 +384,14 @@ internal class IamportSdk(
/**
* 나이스 뱅크페이 앱 종료 콜백 감지 for 웹뷰모드, 모바일웹모드
*/
private fun resultBankPayAppCallback(resPair: Pair<String, String>) {
d("Result Callback BankPayLauncher")
if (modeWebViewRef?.get() != null) {
iamPortWebViewMode?.processBankPayPayment(resPair)
return
}
iamPortMobileWebMode?.processBankPayPayment(resPair)
}
// private fun resultBankPayAppCallback(resPair: Pair<String, String>) {
// d("Result Callback BankPayLauncher")
// if (modeWebViewRef?.get() != null) {
// iamPortWebViewMode?.processBankPayPayment(resPair)
// return
// }
// iamPortMobileWebMode?.processBankPayPayment(resPair)
// }


/**
Expand Down Expand Up @@ -445,7 +443,7 @@ internal class IamportSdk(
clearMainViewModel()
modeWebViewRef?.get()?.let { webView ->
hostHelper.getActivityRef()?.let { activity ->
iamPortWebViewMode = IamPortWebViewMode(bankPayLauncher)
iamPortWebViewMode = IamPortWebViewMode()
iamPortWebViewMode?.initStart(activity, webView, payment, paymentResultCallBack) // webview only 모드
} ?: run {
w("Cannot found activity, So running activity mode")
Expand Down
Loading

0 comments on commit f4e7e8b

Please sign in to comment.