From f3b4d1b36cba5d6526b5d6a304be6a63f00cf66e Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Thu, 23 Jan 2020 11:51:12 +0100 Subject: [PATCH 1/2] Expect that all gateway parameters may be null and supply default values --- .../wordpress/android/fluxc/model/gateways/GatewayMapper.kt | 6 +++--- .../network/rest/wpcom/wc/gateways/GatewayRestClient.kt | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/model/gateways/GatewayMapper.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/model/gateways/GatewayMapper.kt index 4c330ddef3..2435900995 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/model/gateways/GatewayMapper.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/model/gateways/GatewayMapper.kt @@ -10,11 +10,11 @@ class GatewayMapper response.gatewayId, response.title ?: "", response.description ?: "", - response.order, - response.enabled, + response.order ?: 0, + response.enabled ?: false, response.methodTitle ?: "", response.methodDescription ?: "", - response.features + response.features ?: emptyList() ) } } diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/gateways/GatewayRestClient.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/gateways/GatewayRestClient.kt index a2fd7e1823..d89857e4b9 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/gateways/GatewayRestClient.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/gateways/GatewayRestClient.kt @@ -75,10 +75,10 @@ constructor( @SerializedName("id") val gatewayId: String, @SerializedName("title") val title: String?, @SerializedName("description") val description: String?, - @SerializedName("order") val order: Int, - @SerializedName("enabled") val enabled: Boolean, + @SerializedName("order") val order: Int?, + @SerializedName("enabled") val enabled: Boolean?, @SerializedName("method_title") val methodTitle: String?, @SerializedName("method_description") val methodDescription: String?, - @SerializedName("method_supports") val features: List + @SerializedName("method_supports") val features: List? ) } From 73fb317c2083c6d3afcb90e883e04a3819b1df4e Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Thu, 23 Jan 2020 12:31:04 +0100 Subject: [PATCH 2/2] Handle the case where the order can be an empty string --- .../wordpress/android/fluxc/wc/gateways/GatewayFixtures.kt | 4 ++-- .../wordpress/android/fluxc/model/gateways/GatewayMapper.kt | 2 +- .../fluxc/network/rest/wpcom/wc/gateways/GatewayRestClient.kt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/example/src/test/java/org/wordpress/android/fluxc/wc/gateways/GatewayFixtures.kt b/example/src/test/java/org/wordpress/android/fluxc/wc/gateways/GatewayFixtures.kt index 86eef7e3d4..0b11f67c91 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/wc/gateways/GatewayFixtures.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/wc/gateways/GatewayFixtures.kt @@ -7,7 +7,7 @@ val GATEWAYS_RESPONSE = listOf( "cod", "Cash on Delivery", "Pay cash", - 0, + "", false, "COD: Method title", "COD: Method description", @@ -17,7 +17,7 @@ val GATEWAYS_RESPONSE = listOf( "stripe", "Credit card", "Pay with CC", - 1, + "1", true, "Stripe: Method title", "Stripe: Method description", diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/model/gateways/GatewayMapper.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/model/gateways/GatewayMapper.kt index 2435900995..b2d4739bd6 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/model/gateways/GatewayMapper.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/model/gateways/GatewayMapper.kt @@ -10,7 +10,7 @@ class GatewayMapper response.gatewayId, response.title ?: "", response.description ?: "", - response.order ?: 0, + response.order?.toIntOrNull() ?: 0, response.enabled ?: false, response.methodTitle ?: "", response.methodDescription ?: "", diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/gateways/GatewayRestClient.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/gateways/GatewayRestClient.kt index d89857e4b9..580bf27658 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/gateways/GatewayRestClient.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/gateways/GatewayRestClient.kt @@ -75,7 +75,7 @@ constructor( @SerializedName("id") val gatewayId: String, @SerializedName("title") val title: String?, @SerializedName("description") val description: String?, - @SerializedName("order") val order: Int?, + @SerializedName("order") val order: String?, @SerializedName("enabled") val enabled: Boolean?, @SerializedName("method_title") val methodTitle: String?, @SerializedName("method_description") val methodDescription: String?,