-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OnlineBankingJP Payment Component
COAND-373
- Loading branch information
Showing
13 changed files
with
347 additions
and
1 deletion.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...java/com/adyen/checkout/components/model/payments/request/OnlineBankingJPPaymentMethod.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" /> |
36 changes: 36 additions & 0 deletions
36
...e-banking-jp/src/main/java/com/adyen/checkout/onlinebankingjp/OnlineBankingJPComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
...g-jp/src/main/java/com/adyen/checkout/onlinebankingjp/OnlineBankingJPComponentProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...nking-jp/src/main/java/com/adyen/checkout/onlinebankingjp/OnlineBankingJPConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.