Skip to content

Commit

Permalink
Add OnlineBankingJP Payment Component
Browse files Browse the repository at this point in the history
COAND-373
  • Loading branch information
ozgur00 committed Feb 13, 2023
1 parent 546e64a commit 8bf8874
Show file tree
Hide file tree
Showing 13 changed files with 347 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2023 Adyen N.V.
*
* This file is open source and available under the MIT license. See the LICENSE file for more info.
*
* Created by ozgur on 24/1/2023.
*/

package com.adyen.checkout.components.model.payments.request

import com.adyen.checkout.core.exception.ModelSerializationException
import com.adyen.checkout.core.model.getStringOrNull
import kotlinx.parcelize.Parcelize
import org.json.JSONException
import org.json.JSONObject

@Parcelize
class OnlineBankingJPPaymentMethod(
override var type: String? = null,
override var firstName: String? = null,
override var lastName: String? = null,
override var telephoneNumber: String? = null,
override var shopperEmail: String? = null,
) : EContextPaymentMethod() {

companion object {
@JvmField
val SERIALIZER: Serializer<OnlineBankingJPPaymentMethod> = object : Serializer<OnlineBankingJPPaymentMethod> {
override fun serialize(modelObject: OnlineBankingJPPaymentMethod): JSONObject {
return try {
JSONObject().apply {
putOpt(TYPE, modelObject.type)
putOpt(FIRST_NAME, modelObject.firstName)
putOpt(LAST_NAME, modelObject.lastName)
putOpt(TELEPHONE_NUMBER, modelObject.telephoneNumber)
putOpt(SHOPPER_EMAIL, modelObject.shopperEmail)
}
} catch (e: JSONException) {
throw ModelSerializationException(OnlineBankingJPPaymentMethod::class.java, e)
}
}

override fun deserialize(jsonObject: JSONObject): OnlineBankingJPPaymentMethod {
return OnlineBankingJPPaymentMethod(
type = jsonObject.getStringOrNull(TYPE),
firstName = jsonObject.getStringOrNull(FIRST_NAME),
lastName = jsonObject.getStringOrNull(LAST_NAME),
telephoneNumber = jsonObject.getStringOrNull(TELEPHONE_NUMBER),
shopperEmail = jsonObject.getStringOrNull(SHOPPER_EMAIL),
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ object PaymentMethodTypes {
BCMC,
DOTPAY,
ECONTEXT_ATM,
ECONTEXT_ONLINE,
ECONTEXT_SEVEN_ELEVEN,
ECONTEXT_STORES,
ENTERCASH,
Expand Down Expand Up @@ -153,7 +154,6 @@ object PaymentMethodTypes {
DRAGONPAY_OTC_BANKING,
DRAGONPAY_OTC_NON_BANKING,
DRAGONPAY_OTC_PHILIPPINES,
ECONTEXT_ONLINE,
)
)
}
1 change: 1 addition & 0 deletions drop-in/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ dependencies {
api project(':mbway')
api project(':molpay')
api project(':online-banking-cz')
api project(':online-banking-jp')
api project(':online-banking-pl')
api project(':online-banking-sk')
api project(':openbanking')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ import com.adyen.checkout.molpay.MolpayConfiguration
import com.adyen.checkout.onlinebankingcz.OnlineBankingCZComponent
import com.adyen.checkout.onlinebankingcz.OnlineBankingCZComponentProvider
import com.adyen.checkout.onlinebankingcz.OnlineBankingCZConfiguration
import com.adyen.checkout.onlinebankingjp.OnlineBankingJPComponent
import com.adyen.checkout.onlinebankingjp.OnlineBankingJPComponentProvider
import com.adyen.checkout.onlinebankingjp.OnlineBankingJPConfiguration
import com.adyen.checkout.onlinebankingpl.OnlineBankingPLComponent
import com.adyen.checkout.onlinebankingpl.OnlineBankingPLComponentProvider
import com.adyen.checkout.onlinebankingpl.OnlineBankingPLConfiguration
Expand Down Expand Up @@ -255,6 +258,12 @@ internal fun <T : Configuration> getDefaultConfigForPaymentMethod(
environment = environment,
clientKey = clientKey
)
OnlineBankingJPComponent.PROVIDER.isPaymentMethodSupported(paymentMethod) ->
OnlineBankingJPConfiguration.Builder(
shopperLocale = shopperLocale,
environment = environment,
clientKey = clientKey
)
OnlineBankingPLComponent.PROVIDER.isPaymentMethodSupported(paymentMethod) ->
OnlineBankingPLConfiguration.Builder(
shopperLocale = shopperLocale,
Expand Down Expand Up @@ -563,6 +572,16 @@ internal fun getComponentFor(
as ComponentCallback<PaymentComponentState<OnlineBankingCZPaymentMethod>>,
)
}
OnlineBankingJPComponent.PROVIDER.isPaymentMethodSupported(paymentMethod) -> {
val onlineBankingJPConfig: OnlineBankingJPConfiguration =
getConfigurationForPaymentMethod(paymentMethod, dropInConfiguration)
OnlineBankingJPComponentProvider(dropInParams).get(
owner = fragment,
paymentMethod = paymentMethod,
configuration = onlineBankingJPConfig,
application = fragment.requireApplication(),
)
}
OnlineBankingPLComponent.PROVIDER.isPaymentMethodSupported(paymentMethod) -> {
val onlineBankingPLConfig: OnlineBankingPLConfiguration =
getConfigurationForPaymentMethod(paymentMethod, dropInConfiguration)
Expand Down
1 change: 1 addition & 0 deletions online-banking-jp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
34 changes: 34 additions & 0 deletions online-banking-jp/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'kotlin-parcelize'
}

// Maven artifact
ext.mavenArtifactId = "online-banking-jp"
ext.mavenArtifactName = "Adyen Online Banking Japan Component"
ext.mavenArtifactDescription = "Adyen checkout Online Banking Japan Component client for Adyen's Checkout API."

apply from: "${rootDir}/config/gradle/sharedTasks.gradle"

android {
compileSdkVersion compile_sdk_version

defaultConfig {
minSdkVersion min_sdk_version
targetSdkVersion target_sdk_version
versionCode version_code
versionName version_name

testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
consumerProguardFiles "consumer-rules.pro"
}

buildFeatures {
viewBinding true
}
}

dependencies {
api project(':econtext')
}
Empty file.
21 changes: 21 additions & 0 deletions online-banking-jp/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
9 changes: 9 additions & 0 deletions online-banking-jp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2023 Adyen N.V.
~
~ This file is open source and available under the MIT license. See the LICENSE file for more info.
~
~ Created by ozgur on 24/1/2023.
-->

<manifest package="com.adyen.checkout.onlinebankingjp" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2023 Adyen N.V.
*
* This file is open source and available under the MIT license. See the LICENSE file for more info.
*
* Created by ozgur on 24/1/2023.
*/

package com.adyen.checkout.onlinebankingjp

import com.adyen.checkout.action.DefaultActionHandlingComponent
import com.adyen.checkout.action.GenericActionDelegate
import com.adyen.checkout.components.PaymentComponentProvider
import com.adyen.checkout.components.model.payments.request.OnlineBankingJPPaymentMethod
import com.adyen.checkout.components.util.PaymentMethodTypes
import com.adyen.checkout.econtext.EContextComponent
import com.adyen.checkout.econtext.EContextDelegate

class OnlineBankingJPComponent internal constructor(
delegate: EContextDelegate<OnlineBankingJPPaymentMethod>,
genericActionDelegate: GenericActionDelegate,
actionHandlingComponent: DefaultActionHandlingComponent
) : EContextComponent<OnlineBankingJPPaymentMethod>(
delegate,
genericActionDelegate,
actionHandlingComponent
) {
companion object {
@JvmField
val PROVIDER: PaymentComponentProvider<OnlineBankingJPComponent, OnlineBankingJPConfiguration> =
OnlineBankingJPComponentProvider()

@JvmField
val PAYMENT_METHOD_TYPES = arrayOf(PaymentMethodTypes.ECONTEXT_ONLINE)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright (c) 2023 Adyen N.V.
*
* This file is open source and available under the MIT license. See the LICENSE file for more info.
*
* Created by ozgur on 24/1/2023.
*/

package com.adyen.checkout.onlinebankingjp

import android.app.Application
import android.os.Bundle
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStoreOwner
import androidx.savedstate.SavedStateRegistryOwner
import com.adyen.checkout.action.DefaultActionHandlingComponent
import com.adyen.checkout.action.GenericActionComponentProvider
import com.adyen.checkout.components.PaymentComponentProvider
import com.adyen.checkout.components.analytics.AnalyticsMapper
import com.adyen.checkout.components.analytics.AnalyticsSource
import com.adyen.checkout.components.analytics.DefaultAnalyticsRepository
import com.adyen.checkout.components.api.AnalyticsService
import com.adyen.checkout.components.base.ButtonComponentParamsMapper
import com.adyen.checkout.components.base.ComponentParams
import com.adyen.checkout.components.base.lifecycle.get
import com.adyen.checkout.components.base.lifecycle.viewModelFactory
import com.adyen.checkout.components.model.paymentmethods.PaymentMethod
import com.adyen.checkout.components.model.payments.request.OnlineBankingJPPaymentMethod
import com.adyen.checkout.components.repository.PaymentObserverRepository
import com.adyen.checkout.components.ui.SubmitHandler
import com.adyen.checkout.core.api.HttpClientFactory
import com.adyen.checkout.core.exception.ComponentException
import com.adyen.checkout.econtext.DefaultEContextDelegate

class OnlineBankingJPComponentProvider(
overrideComponentParams: ComponentParams? = null,
) : PaymentComponentProvider<OnlineBankingJPComponent, OnlineBankingJPConfiguration> {

private val componentParamsMapper = ButtonComponentParamsMapper(overrideComponentParams)

override fun get(
savedStateRegistryOwner: SavedStateRegistryOwner,
viewModelStoreOwner: ViewModelStoreOwner,
paymentMethod: PaymentMethod,
configuration: OnlineBankingJPConfiguration,
application: Application,
defaultArgs: Bundle?,
key: String?
): OnlineBankingJPComponent {
assertSupported(paymentMethod)

val genericFactory: ViewModelProvider.Factory =
viewModelFactory(savedStateRegistryOwner, defaultArgs) { savedStateHandle ->
val componentParams = componentParamsMapper.mapToParams(configuration)
val httpClient = HttpClientFactory.getHttpClient(componentParams.environment)
val analyticsService = AnalyticsService(httpClient)
val analyticsRepository = DefaultAnalyticsRepository(
packageName = application.packageName,
locale = componentParams.shopperLocale,
source = AnalyticsSource.PaymentComponent(componentParams.isCreatedByDropIn, paymentMethod),
analyticsService = analyticsService,
analyticsMapper = AnalyticsMapper(),
)
val eContextDelegate = DefaultEContextDelegate(
observerRepository = PaymentObserverRepository(),
componentParams = componentParams,
paymentMethod = paymentMethod,
analyticsRepository = analyticsRepository,
submitHandler = SubmitHandler()
) { OnlineBankingJPPaymentMethod() }

val genericActionDelegate = GenericActionComponentProvider(componentParams).getDelegate(
configuration = configuration.genericActionConfiguration,
savedStateHandle = savedStateHandle,
application = application,
)

OnlineBankingJPComponent(
delegate = eContextDelegate,
genericActionDelegate = genericActionDelegate,
actionHandlingComponent = DefaultActionHandlingComponent(genericActionDelegate, eContextDelegate),
)
}
return ViewModelProvider(viewModelStoreOwner, genericFactory)[key, OnlineBankingJPComponent::class.java]
}

private fun assertSupported(paymentMethod: PaymentMethod) {
if (!isPaymentMethodSupported(paymentMethod)) {
throw ComponentException("Unsupported payment method ${paymentMethod.type}")
}
}

override fun isPaymentMethodSupported(paymentMethod: PaymentMethod): Boolean {
return OnlineBankingJPComponent.PAYMENT_METHOD_TYPES.contains(paymentMethod.type)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2023 Adyen N.V.
*
* This file is open source and available under the MIT license. See the LICENSE file for more info.
*
* Created by ozgur on 24/1/2023.
*/

package com.adyen.checkout.onlinebankingjp

import android.content.Context
import com.adyen.checkout.action.GenericActionConfiguration
import com.adyen.checkout.components.model.payments.Amount
import com.adyen.checkout.core.api.Environment
import com.adyen.checkout.econtext.EContextConfiguration
import kotlinx.parcelize.Parcelize
import java.util.Locale

@Suppress("LongParameterList")
@Parcelize
class OnlineBankingJPConfiguration private constructor(
override val shopperLocale: Locale,
override val environment: Environment,
override val clientKey: String,
override val isAnalyticsEnabled: Boolean?,
override val amount: Amount,
override val isSubmitButtonVisible: Boolean?,
internal val genericActionConfiguration: GenericActionConfiguration,
) : EContextConfiguration() {

/**
* Builder to create a [OnlineBankingJPConfiguration].
*/
class Builder : EContextConfiguration.Builder<OnlineBankingJPConfiguration, Builder> {

/**
* Constructor for Builder with default values.
*
* @param context A context
* @param environment The [Environment] to be used for network calls to Adyen.
* @param clientKey Your Client Key used for network calls from the SDK to Adyen.
*/
constructor(context: Context, environment: Environment, clientKey: String) : super(
context,
environment,
clientKey
)

/**
* Builder with required parameters.
*
* @param shopperLocale The Locale of the shopper.
* @param environment The [Environment] to be used for network calls to Adyen.
* @param clientKey Your Client Key used for network calls from the SDK to Adyen.
*/
constructor(
shopperLocale: Locale,
environment: Environment,
clientKey: String
) : super(shopperLocale, environment, clientKey)

override fun buildInternal(): OnlineBankingJPConfiguration {
return OnlineBankingJPConfiguration(
shopperLocale = shopperLocale,
environment = environment,
clientKey = clientKey,
isAnalyticsEnabled = isAnalyticsEnabled,
amount = amount,
isSubmitButtonVisible = isSubmitButtonVisible,
genericActionConfiguration = genericActionConfigurationBuilder.build(),
)
}
}
}
Loading

0 comments on commit 8bf8874

Please sign in to comment.