Skip to content

Commit

Permalink
Merge pull request #57 from Adyen/feature/renameDropInOutcome
Browse files Browse the repository at this point in the history
Feature/rename drop in outcome
  • Loading branch information
Robert-SD authored Oct 31, 2023
2 parents 13980b9 + 31fb913 commit 4dbe379
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import CheckoutFlutterApi
import CheckoutPlatformInterface
import DeletedStoredPaymentMethodResultDTO
import DropInConfigurationDTO
import DropInResultDTO
import DropInResultType
import PaymentFlowOutcomeDTO
import PaymentFlowResultType
import PlatformCommunicationModel
import PlatformCommunicationType
import SessionDTO
Expand Down Expand Up @@ -104,15 +104,15 @@ class CheckoutPlatformApi(private val checkoutFlutterApi: CheckoutFlutterApi?) :
}
}

override fun onPaymentsResult(paymentsResult: DropInResultDTO) {
if (paymentsResult.dropInResultType == DropInResultType.ACTION) {
override fun onPaymentsResult(paymentsResult: PaymentFlowOutcomeDTO) {
if (paymentsResult.paymentFlowResultType == PaymentFlowResultType.ACTION) {
setAdvanceFlowDropInAdditionalDetailsMessengerObserver()
}

DropInPaymentResultMessenger.sendResult(paymentsResult)
}

override fun onPaymentsDetailsResult(paymentsDetailsResult: DropInResultDTO) {
override fun onPaymentsDetailsResult(paymentsDetailsResult: PaymentFlowOutcomeDTO) {
DropInAdditionalDetailsResultMessenger.sendResult(paymentsDetailsResult)
}

Expand Down
50 changes: 25 additions & 25 deletions android/src/main/kotlin/com/adyen/adyen_checkout/PlatformApi.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Autogenerated from Pigeon (v12.0.0), do not edit directly.
// Autogenerated from Pigeon (v12.0.1), do not edit directly.
// See also: https://pub.dev/packages/pigeon


Expand Down Expand Up @@ -139,13 +139,13 @@ enum class PlatformCommunicationType(val raw: Int) {
}
}

enum class DropInResultType(val raw: Int) {
enum class PaymentFlowResultType(val raw: Int) {
FINISHED(0),
ACTION(1),
ERROR(2);

companion object {
fun ofRaw(raw: Int): DropInResultType? {
fun ofRaw(raw: Int): PaymentFlowResultType? {
return values().firstOrNull { it.raw == raw }
}
}
Expand Down Expand Up @@ -545,28 +545,28 @@ data class PlatformCommunicationModel (
}

/** Generated class from Pigeon that represents data sent in messages. */
data class DropInResultDTO (
val dropInResultType: DropInResultType,
data class PaymentFlowOutcomeDTO (
val paymentFlowResultType: PaymentFlowResultType,
val result: String? = null,
val actionResponse: Map<String?, Any?>? = null,
val error: DropInErrorDTO? = null
val error: ErrorDTO? = null

) {
companion object {
@Suppress("UNCHECKED_CAST")
fun fromList(list: List<Any?>): DropInResultDTO {
val dropInResultType = DropInResultType.ofRaw(list[0] as Int)!!
fun fromList(list: List<Any?>): PaymentFlowOutcomeDTO {
val paymentFlowResultType = PaymentFlowResultType.ofRaw(list[0] as Int)!!
val result = list[1] as String?
val actionResponse = list[2] as Map<String?, Any?>?
val error: DropInErrorDTO? = (list[3] as List<Any?>?)?.let {
DropInErrorDTO.fromList(it)
val error: ErrorDTO? = (list[3] as List<Any?>?)?.let {
ErrorDTO.fromList(it)
}
return DropInResultDTO(dropInResultType, result, actionResponse, error)
return PaymentFlowOutcomeDTO(paymentFlowResultType, result, actionResponse, error)
}
}
fun toList(): List<Any?> {
return listOf<Any?>(
dropInResultType.raw,
paymentFlowResultType.raw,
result,
actionResponse,
error?.toList(),
Expand All @@ -575,19 +575,19 @@ data class DropInResultDTO (
}

/** Generated class from Pigeon that represents data sent in messages. */
data class DropInErrorDTO (
data class ErrorDTO (
val errorMessage: String? = null,
val reason: String? = null,
val dismissDropIn: Boolean? = null

) {
companion object {
@Suppress("UNCHECKED_CAST")
fun fromList(list: List<Any?>): DropInErrorDTO {
fun fromList(list: List<Any?>): ErrorDTO {
val errorMessage = list[0] as String?
val reason = list[1] as String?
val dismissDropIn = list[2] as Boolean?
return DropInErrorDTO(errorMessage, reason, dismissDropIn)
return ErrorDTO(errorMessage, reason, dismissDropIn)
}
}
fun toList(): List<Any?> {
Expand Down Expand Up @@ -662,17 +662,17 @@ private object CheckoutPlatformInterfaceCodec : StandardMessageCodec() {
}
135.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
DropInErrorDTO.fromList(it)
ErrorDTO.fromList(it)
}
}
136.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
DropInResultDTO.fromList(it)
GooglePayConfigurationDTO.fromList(it)
}
}
137.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
GooglePayConfigurationDTO.fromList(it)
PaymentFlowOutcomeDTO.fromList(it)
}
}
138.toByte() -> {
Expand Down Expand Up @@ -713,15 +713,15 @@ private object CheckoutPlatformInterfaceCodec : StandardMessageCodec() {
stream.write(134)
writeValue(stream, value.toList())
}
is DropInErrorDTO -> {
is ErrorDTO -> {
stream.write(135)
writeValue(stream, value.toList())
}
is DropInResultDTO -> {
is GooglePayConfigurationDTO -> {
stream.write(136)
writeValue(stream, value.toList())
}
is GooglePayConfigurationDTO -> {
is PaymentFlowOutcomeDTO -> {
stream.write(137)
writeValue(stream, value.toList())
}
Expand All @@ -740,8 +740,8 @@ interface CheckoutPlatformInterface {
fun getReturnUrl(callback: (Result<String>) -> Unit)
fun startDropInSessionPayment(dropInConfigurationDTO: DropInConfigurationDTO, session: SessionDTO)
fun startDropInAdvancedFlowPayment(dropInConfigurationDTO: DropInConfigurationDTO, paymentMethodsResponse: String)
fun onPaymentsResult(paymentsResult: DropInResultDTO)
fun onPaymentsDetailsResult(paymentsDetailsResult: DropInResultDTO)
fun onPaymentsResult(paymentsResult: PaymentFlowOutcomeDTO)
fun onPaymentsDetailsResult(paymentsDetailsResult: PaymentFlowOutcomeDTO)
fun onDeleteStoredPaymentMethodResult(deleteStoredPaymentMethodResultDTO: DeletedStoredPaymentMethodResultDTO)
fun enableLogging(loggingEnabled: Boolean)
fun cleanUpDropIn()
Expand Down Expand Up @@ -835,7 +835,7 @@ interface CheckoutPlatformInterface {
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val paymentsResultArg = args[0] as DropInResultDTO
val paymentsResultArg = args[0] as PaymentFlowOutcomeDTO
var wrapped: List<Any?>
try {
api.onPaymentsResult(paymentsResultArg)
Expand All @@ -854,7 +854,7 @@ interface CheckoutPlatformInterface {
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val paymentsDetailsResultArg = args[0] as DropInResultDTO
val paymentsDetailsResultArg = args[0] as PaymentFlowOutcomeDTO
var wrapped: List<Any?>
try {
api.onPaymentsDetailsResult(paymentsDetailsResultArg)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.adyen.adyen_checkout.dropInAdvancedFlow

import DeletedStoredPaymentMethodResultDTO
import DropInErrorDTO
import DropInResultDTO
import DropInResultType
import ErrorDTO
import PaymentFlowOutcomeDTO
import PaymentFlowResultType
import android.content.Intent
import android.os.IBinder
import androidx.lifecycle.Lifecycle
Expand Down Expand Up @@ -83,7 +83,7 @@ class AdvancedFlowDropInService : DropInService(), LifecycleOwner {
return@observe
}

val dropInServiceResult = mapToDropInResult(message.contentIfNotHandled)
val dropInServiceResult = mapToDropInServiceResult(message.contentIfNotHandled)
sendResult(dropInServiceResult)
}
}
Expand All @@ -95,7 +95,7 @@ class AdvancedFlowDropInService : DropInService(), LifecycleOwner {
return@observe
}

val dropInServiceResult = mapToDropInResult(message.contentIfNotHandled)
val dropInServiceResult = mapToDropInServiceResult(message.contentIfNotHandled)
sendResult(dropInServiceResult)
}
}
Expand Down Expand Up @@ -126,27 +126,27 @@ class AdvancedFlowDropInService : DropInService(), LifecycleOwner {
}
}

private fun mapToDropInResult(dropInResultDTO: DropInResultDTO?): DropInServiceResult {
return when (dropInResultDTO?.dropInResultType) {
DropInResultType.FINISHED -> DropInServiceResult.Finished(
result = "${dropInResultDTO.result}"
private fun mapToDropInServiceResult(paymentFlowOutcomeDTO: PaymentFlowOutcomeDTO?): DropInServiceResult {
return when (paymentFlowOutcomeDTO?.paymentFlowResultType) {
PaymentFlowResultType.FINISHED -> DropInServiceResult.Finished(
result = "${paymentFlowOutcomeDTO.result}"
)

DropInResultType.ERROR -> DropInServiceResult.Error(
errorDialog = buildErrorDialog(dropInResultDTO.error),
reason = dropInResultDTO.error?.reason,
dismissDropIn = dropInResultDTO.error?.dismissDropIn ?: false
PaymentFlowResultType.ERROR -> DropInServiceResult.Error(
errorDialog = buildErrorDialog(paymentFlowOutcomeDTO.error),
reason = paymentFlowOutcomeDTO.error?.reason,
dismissDropIn = paymentFlowOutcomeDTO.error?.dismissDropIn ?: false
)

DropInResultType.ACTION -> {
if (dropInResultDTO.actionResponse == null) {
PaymentFlowResultType.ACTION -> {
if (paymentFlowOutcomeDTO.actionResponse == null) {
DropInServiceResult.Error(
errorDialog = null,
reason = "Action response not provided",
dismissDropIn = true
)
} else {
val actionJson = JSONObject(dropInResultDTO.actionResponse)
val actionJson = JSONObject(paymentFlowOutcomeDTO.actionResponse)
DropInServiceResult.Action(action = Action.SERIALIZER.deserialize(actionJson))
}
}
Expand All @@ -159,7 +159,7 @@ class AdvancedFlowDropInService : DropInService(), LifecycleOwner {
}
}

private fun buildErrorDialog(dropInError: DropInErrorDTO?): ErrorDialog? {
private fun buildErrorDialog(dropInError: ErrorDTO?): ErrorDialog? {
return if (dropInError?.dismissDropIn == true) {
null
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.adyen.adyen_checkout.dropInAdvancedFlow

import DeletedStoredPaymentMethodResultDTO
import DropInResultDTO
import PaymentFlowOutcomeDTO
import androidx.lifecycle.LiveData
import com.adyen.adyen_checkout.models.DropInStoredPaymentMethodDeletionModel
import com.adyen.adyen_checkout.utils.Event
Expand All @@ -17,12 +17,12 @@ class DropInServiceResultMessenger : LiveData<Event<JSONObject>>() {
}
}

class DropInPaymentResultMessenger : LiveData<Event<DropInResultDTO>>() {
class DropInPaymentResultMessenger : LiveData<Event<PaymentFlowOutcomeDTO>>() {
companion object {
private val dropInPaymentResultMessenger = DropInPaymentResultMessenger()

fun instance() = dropInPaymentResultMessenger
fun sendResult(value: DropInResultDTO) {
fun sendResult(value: PaymentFlowOutcomeDTO) {
dropInPaymentResultMessenger.postValue(Event(value))
}
}
Expand All @@ -40,13 +40,13 @@ class DropInAdditionalDetailsPlatformMessenger : LiveData<Event<JSONObject>>() {
}
}

class DropInAdditionalDetailsResultMessenger : LiveData<Event<DropInResultDTO>>() {
class DropInAdditionalDetailsResultMessenger : LiveData<Event<PaymentFlowOutcomeDTO>>() {
companion object {
private val dropInAdditionalDetailsResultMessenger =
DropInAdditionalDetailsResultMessenger()

fun instance() = dropInAdditionalDetailsResultMessenger
fun sendResult(value: DropInResultDTO) {
fun sendResult(value: PaymentFlowOutcomeDTO) {
dropInAdditionalDetailsResultMessenger.postValue(Event(value))
}
}
Expand Down
14 changes: 8 additions & 6 deletions example/lib/repositories/adyen_sessions_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:adyen_checkout_example/network/models/payment_request_network_mo
import 'package:adyen_checkout_example/network/models/session_request_network_model.dart';
import 'package:adyen_checkout_example/network/models/session_response_network_model.dart';
import 'package:adyen_checkout_example/network/service.dart';
import 'package:adyen_checkout_example/repositories/drop_in_outcome_handler.dart';
import 'package:adyen_checkout_example/repositories/payment_flow_outcome_handler.dart';

class AdyenSessionsRepository {
AdyenSessionsRepository(
Expand All @@ -22,7 +22,8 @@ class AdyenSessionsRepository {

final AdyenCheckout _adyenCheckout;
final Service _service;
final DropInOutcomeHandler _dropInOutcomeHandler = DropInOutcomeHandler();
final PaymentFlowOutcomeHandler _paymentFlowOutcomeHandler =
PaymentFlowOutcomeHandler();

//A session should not being created from the mobile application.
//Please provide a CheckoutSession object from your own backend.
Expand Down Expand Up @@ -97,7 +98,7 @@ class AdyenSessionsRepository {
));
}

Future<DropInOutcome> postPayments(String paymentComponentJson) async {
Future<PaymentFlowOutcome> postPayments(String paymentComponentJson) async {
String returnUrl = await determineExampleReturnUrl();
PaymentsRequestData paymentsRequestData = PaymentsRequestData(
merchantAccount: Config.merchantAccount,
Expand Down Expand Up @@ -135,13 +136,14 @@ class AdyenSessionsRepository {
mergedJson.addAll(jsonDecode(paymentComponentJson));
mergedJson.addAll(paymentsRequestData.toJson());
final response = await _service.postPayments(mergedJson);
return _dropInOutcomeHandler.handleResponse(response);
return _paymentFlowOutcomeHandler.handleResponse(response);
}

Future<DropInOutcome> postPaymentsDetails(String additionalDetails) async {
Future<PaymentFlowOutcome> postPaymentsDetails(
String additionalDetails) async {
final response =
await _service.postPaymentsDetails(jsonDecode(additionalDetails));
return _dropInOutcomeHandler.handleResponse(response);
return _paymentFlowOutcomeHandler.handleResponse(response);
}

Future<String> determineExampleReturnUrl() async {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:adyen_checkout/adyen_checkout.dart';

class DropInOutcomeHandler {
class PaymentFlowOutcomeHandler {
//DropIn results
static const resultPending = "pending";
static const resultAuthorized = "authorised";
Expand All @@ -16,7 +16,7 @@ class DropInOutcomeHandler {
static const messageKey = "message";
static const refusalReasonKey = "refusalReason";

DropInOutcome handleResponse(Map<String, dynamic> jsonResponse) {
PaymentFlowOutcome handleResponse(Map<String, dynamic> jsonResponse) {
if (_isError(jsonResponse)) {
return Error(
errorMessage: jsonResponse[messageKey],
Expand Down
Loading

0 comments on commit 4dbe379

Please sign in to comment.