Skip to content

Commit

Permalink
Rebased onto main and applied ktlint format
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-SD committed Sep 18, 2023
1 parent ef8d540 commit 90576c6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import org.json.JSONObject

@Suppress("NAME_SHADOWING")
class CheckoutPlatformApi(private val checkoutFlutterApi: CheckoutFlutterApi?) :
CheckoutPlatformInterface {
CheckoutPlatformInterface {
lateinit var activity: FragmentActivity
lateinit var dropInSessionLauncher:
ActivityResultLauncher<SessionDropInResultContractParams>
Expand All @@ -48,18 +48,18 @@ class CheckoutPlatformApi(private val checkoutFlutterApi: CheckoutFlutterApi?) :
callback(Result.success(RedirectComponent.getReturnUrl(activity.applicationContext)))
}

override fun startDropInSessionPayment(
override fun startDropInSessionPayment(
dropInConfigurationDTO: DropInConfigurationDTO,
session: Session,
) {
checkForFlutterFragmentActivity()
activity.lifecycleScope.launch(Dispatchers.IO) {
val sessionModel = session.mapToSession()
val dropInConfiguration =
) {
checkForFlutterFragmentActivity()
activity.lifecycleScope.launch(Dispatchers.IO) {
val sessionModel = session.mapToSession()
val dropInConfiguration =
dropInConfigurationDTO.mapToDropInConfiguration(activity.applicationContext)
val checkoutSession = createCheckoutSession(sessionModel, dropInConfiguration)
withContext(Dispatchers.Main) {
DropIn.startPayment(
val checkoutSession = createCheckoutSession(sessionModel, dropInConfiguration)
withContext(Dispatchers.Main) {
DropIn.startPayment(
activity.applicationContext,
dropInSessionLauncher,
checkoutSession,
Expand All @@ -69,31 +69,31 @@ class CheckoutPlatformApi(private val checkoutFlutterApi: CheckoutFlutterApi?) :
}
}

override fun startDropInAdvancedFlowPayment(
override fun startDropInAdvancedFlowPayment(
dropInConfigurationDTO: DropInConfigurationDTO,
paymentMethodsResponse: String,
) {
checkForFlutterFragmentActivity()
setAdvancedFlowDropInServiceObserver()
activity.lifecycleScope.launch(Dispatchers.IO) {
val paymentMethodsApiResponse = PaymentMethodsApiResponse.SERIALIZER.deserialize(
) {
checkForFlutterFragmentActivity()
setAdvancedFlowDropInServiceObserver()
activity.lifecycleScope.launch(Dispatchers.IO) {
val paymentMethodsApiResponse = PaymentMethodsApiResponse.SERIALIZER.deserialize(
JSONObject(paymentMethodsResponse),
)
val paymentMethodsWithoutGiftCards =
)
val paymentMethodsWithoutGiftCards =
removeGiftCardPaymentMethods(paymentMethodsApiResponse)
val dropInConfiguration =
val dropInConfiguration =
dropInConfigurationDTO.mapToDropInConfiguration(activity.applicationContext)
withContext(Dispatchers.Main) {
DropIn.startPayment(
withContext(Dispatchers.Main) {
DropIn.startPayment(
activity.applicationContext,
dropInAdvancedFlowLauncher,
paymentMethodsWithoutGiftCards,
dropInConfiguration,
AdvancedFlowDropInService::class.java,
)
)
}
}
}
}

override fun onPaymentsResult(paymentsResult: DropInResult) {
if (paymentsResult.dropInResultType == DropInResultType.ACTION) {
Expand Down
56 changes: 29 additions & 27 deletions android/src/main/kotlin/com/adyen/adyen_checkout/utils/Mapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,44 @@ import com.adyen.checkout.card.CardType
import com.adyen.checkout.card.KCPAuthVisibility
import com.adyen.checkout.card.SocialSecurityNumberVisibility
import com.adyen.checkout.components.core.OrderResponse
import com.adyen.checkout.dropin.DropInConfiguration
import com.adyen.checkout.sessions.core.SessionModel
import com.adyen.checkout.core.Environment as SDKEnvironment

object Mapper {

fun Session.mapToSession(): com.adyen.checkout.sessions.core.SessionModel {
return com.adyen.checkout.sessions.core.SessionModel(this.id, this.sessionData)
fun Session.mapToSession(): SessionModel {
return SessionModel(this.id, this.sessionData)
}

fun DropInConfigurationDTO.mapToDropInConfiguration(context: Context): com.adyen.checkout.dropin.DropInConfiguration {
fun DropInConfigurationDTO.mapToDropInConfiguration(context: Context): DropInConfiguration {
val environment = this.environment.mapToEnvironment()
val cardConfiguration = CardConfiguration.Builder(
context = context,
environment = environment,
clientKey = this.clientKey
context = context,
environment = environment,
clientKey = this.clientKey
)
.setShowStorePaymentField(cardsConfigurationDTO?.showStorePaymentField ?: false)
.setAddressConfiguration(cardsConfigurationDTO?.addressMode?.mapToAddressConfiguration()
?: AddressConfiguration.None)
.setShowStorePaymentField(cardsConfigurationDTO?.showStorePaymentField ?: false)
.setHideCvcStoredCard(cardsConfigurationDTO?.hideCvcStoredCard ?: false)
.setHideCvc(cardsConfigurationDTO?.hideCvc ?: false)
.setKcpAuthVisibility(determineKcpAuthVisibility(cardsConfigurationDTO?.kcpVisible))
.setSocialSecurityNumberVisibility(determineSocialSecurityNumberVisibility(cardsConfigurationDTO?.socialSecurityVisible))
.setSupportedCardTypes(*mapToSupportedCardTypes(cardsConfigurationDTO?.supportedCardTypes))
.setHolderNameRequired(cardsConfigurationDTO?.holderNameRequired ?: false)
.build()
.setShowStorePaymentField(cardsConfigurationDTO?.showStorePaymentField ?: false)
.setAddressConfiguration(
cardsConfigurationDTO?.addressMode?.mapToAddressConfiguration()
?: AddressConfiguration.None
)
.setShowStorePaymentField(cardsConfigurationDTO?.showStorePaymentField ?: false)
.setHideCvcStoredCard(cardsConfigurationDTO?.hideCvcStoredCard ?: false)
.setHideCvc(cardsConfigurationDTO?.hideCvc ?: false)
.setKcpAuthVisibility(determineKcpAuthVisibility(cardsConfigurationDTO?.kcpVisible))
.setSocialSecurityNumberVisibility(
determineSocialSecurityNumberVisibility(cardsConfigurationDTO?.socialSecurityVisible)
)
.setSupportedCardTypes(*mapToSupportedCardTypes(cardsConfigurationDTO?.supportedCardTypes))
.setHolderNameRequired(cardsConfigurationDTO?.holderNameRequired ?: false)
.build()
val amount = this.amount.mapToAmount()
return com.adyen.checkout.dropin.DropInConfiguration.Builder(
return DropInConfiguration.Builder(
context,
this.environment.mapToEnvironment(),
clientKey,
).setAmount(amount).build()
context,
this.environment.mapToEnvironment(),
clientKey
).setAmount(amount).addCardConfiguration(cardConfiguration).build();
).setAmount(amount).addCardConfiguration(cardConfiguration).build()
}

private fun AddressMode.mapToAddressConfiguration(): AddressConfiguration {
Expand Down Expand Up @@ -105,10 +107,10 @@ object Mapper {

fun OrderResponse.mapToOrderResponseModel(): OrderResponseModel {
return OrderResponseModel(
pspReference = pspReference,
orderData = orderData,
amount = amount?.mapTopAmount(),
remainingAmount = remainingAmount?.mapTopAmount(),
pspReference = pspReference,
orderData = orderData,
amount = amount?.mapTopAmount(),
remainingAmount = remainingAmount?.mapTopAmount(),
)
}
}

0 comments on commit 90576c6

Please sign in to comment.