Skip to content

Commit a148665

Browse files
authored
Merge pull request #217 from Ecwid/generalize_nested_classes
Introduce BaseOrderTax interface to generalize tax objects
2 parents c5b999c + 4c7371b commit a148665

9 files changed

Lines changed: 80 additions & 43 deletions

File tree

src/main/kotlin/com/ecwid/apiclient/v3/converter/FetchedOrder.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fun FetchedOrder.HandlingFee.toUpdated(): UpdatedOrder.HandlingFee {
235235
name = name,
236236
value = value,
237237
description = description,
238-
taxes = taxes.map(FetchedOrder.BaseOrderItemTax::toUpdated)
238+
taxes = taxes.map(FetchedOrder.HandlingFeeTax::toUpdated)
239239
)
240240
}
241241

@@ -260,6 +260,14 @@ fun FetchedOrder.BaseOrderItemTax.toUpdated(): UpdatedOrder.BaseOrderItemTax {
260260
)
261261
}
262262

263+
fun FetchedOrder.HandlingFeeTax.toUpdated(): UpdatedOrder.HandlingFeeTax {
264+
return UpdatedOrder.HandlingFeeTax(
265+
name = name,
266+
value = value,
267+
total = total
268+
)
269+
}
270+
263271
fun FetchedOrder.UtmData.toUpdated(): UpdatedOrder.UtmData {
264272
return UpdatedOrder.UtmData(
265273
source = source,

src/main/kotlin/com/ecwid/apiclient/v3/dto/cart/request/OrderForCalculate.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.ecwid.apiclient.v3.dto.cart.request
22

33
import com.ecwid.apiclient.v3.dto.common.ApiRequestDTO
4+
import com.ecwid.apiclient.v3.dto.common.BaseOrderTax
45
import com.ecwid.apiclient.v3.dto.order.enums.*
56
import java.text.DateFormat
67
import java.text.SimpleDateFormat
@@ -170,13 +171,13 @@ data class OrderForCalculate(
170171
)
171172

172173
data class OrderItemTax(
173-
val name: String? = null,
174-
val value: Double? = null,
175-
val total: Double? = null,
174+
override val name: String? = null,
175+
override val value: Double? = null,
176+
override val total: Double? = null,
176177
val taxOnDiscountedSubtotal: Double? = null,
177178
val taxOnShipping: Double? = null,
178179
val includeInPrice: Boolean? = null
179-
)
180+
) : BaseOrderTax
180181

181182
data class OrderItemProductFile(
182183
val productFileId: Int? = null,

src/main/kotlin/com/ecwid/apiclient/v3/dto/cart/request/UpdatedCart.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ package com.ecwid.apiclient.v3.dto.cart.request
33
import com.ecwid.apiclient.v3.dto.cart.result.FetchedCart
44
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO
55
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO.ModifyKind
6+
import com.ecwid.apiclient.v3.dto.common.BaseOrderTax
67

78
data class UpdatedCart(
89
val hidden: Boolean? = null,
910
val taxesOnShipping: List<TaxOnShipping>? = null
1011
) : ApiUpdatedDTO {
1112

1213
data class TaxOnShipping(
13-
val name: String? = null,
14-
val value: Double? = null,
15-
val total: Double? = null
16-
)
14+
override val name: String? = null,
15+
override val value: Double? = null,
16+
override val total: Double? = null
17+
) : BaseOrderTax
1718

1819
override fun getModifyKind() = ModifyKind.ReadWrite(FetchedCart::class)
1920
}

src/main/kotlin/com/ecwid/apiclient/v3/dto/cart/result/CalculateOrderDetailsResult.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.ecwid.apiclient.v3.dto.cart.result
22

33
import com.ecwid.apiclient.v3.dto.cart.CartStringToStringMap
44
import com.ecwid.apiclient.v3.dto.common.ApiResultDTO
5+
import com.ecwid.apiclient.v3.dto.common.BaseOrderTax
56
import com.ecwid.apiclient.v3.dto.order.enums.*
67
import java.util.*
78

@@ -159,13 +160,13 @@ data class CalculateOrderDetailsResult(
159160
)
160161

161162
data class OrderItemTax(
162-
val name: String? = null,
163-
val value: Double? = null,
164-
val total: Double? = null,
163+
override val name: String? = null,
164+
override val value: Double? = null,
165+
override val total: Double? = null,
165166
val taxOnDiscountedSubtotal: Double? = null,
166167
val taxOnShipping: Double? = null,
167168
val includeInPrice: Boolean? = null
168-
)
169+
) : BaseOrderTax
169170

170171
data class OrderItemProductFile(
171172
val productFileId: Int? = null,
@@ -226,8 +227,8 @@ data class CalculateOrderDetailsResult(
226227
)
227228

228229
data class TaxOnShipping(
229-
val name: String? = null,
230-
val value: Double? = null,
231-
val total: Double? = null
232-
)
230+
override val name: String? = null,
231+
override val value: Double? = null,
232+
override val total: Double? = null
233+
) : BaseOrderTax
233234
}

src/main/kotlin/com/ecwid/apiclient/v3/dto/cart/result/FetchedCart.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.ecwid.apiclient.v3.dto.cart.CartStringToStringMap
44
import com.ecwid.apiclient.v3.dto.cart.request.UpdatedCart
55
import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO
66
import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO.ModifyKind
7+
import com.ecwid.apiclient.v3.dto.common.BaseOrderTax
78
import com.ecwid.apiclient.v3.dto.order.enums.*
89
import java.util.*
910

@@ -165,13 +166,13 @@ data class FetchedCart(
165166
)
166167

167168
data class OrderItemTax(
168-
val name: String? = null,
169-
val value: Double? = null,
170-
val total: Double? = null,
169+
override val name: String? = null,
170+
override val value: Double? = null,
171+
override val total: Double? = null,
171172
val taxOnDiscountedSubtotal: Double? = null,
172173
val taxOnShipping: Double? = null,
173174
val includeInPrice: Boolean? = null
174-
)
175+
) : BaseOrderTax
175176

176177
data class OrderItemProductFile(
177178
val productFileId: Int? = null,
@@ -234,10 +235,10 @@ data class FetchedCart(
234235
)
235236

236237
data class TaxOnShipping(
237-
val name: String? = null,
238-
val value: Double? = null,
239-
val total: Double? = null
240-
)
238+
override val name: String? = null,
239+
override val value: Double? = null,
240+
override val total: Double? = null
241+
) : BaseOrderTax
241242

242243
data class UtmData(
243244
val source: String? = null,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.ecwid.apiclient.v3.dto.common
2+
3+
interface BaseOrderTax {
4+
val name: String?
5+
val value: Double?
6+
val total: Double?
7+
}

src/main/kotlin/com/ecwid/apiclient/v3/dto/order/request/UpdatedOrder.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.ecwid.apiclient.v3.dto.order.request
22

33
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO
44
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO.ModifyKind
5+
import com.ecwid.apiclient.v3.dto.common.BaseOrderTax
56
import com.ecwid.apiclient.v3.dto.common.OrderedStringToListStringMap
67
import com.ecwid.apiclient.v3.dto.common.OrderedStringToStringMap
78
import com.ecwid.apiclient.v3.dto.order.enums.*
@@ -237,19 +238,25 @@ data class UpdatedOrder(
237238
)
238239

239240
data class BaseOrderItemTax(
240-
val name: String? = null,
241-
val value: Double? = null,
242-
val total: Double? = null
243-
)
241+
override val name: String? = null,
242+
override val value: Double? = null,
243+
override val total: Double? = null
244+
) : BaseOrderTax
244245

245246
data class OrderItemTax(
246-
val name: String? = null,
247-
val value: Double? = null,
248-
val total: Double? = null,
247+
override val name: String? = null,
248+
override val value: Double? = null,
249+
override val total: Double? = null,
249250
val taxOnDiscountedSubtotal: Double? = null,
250251
val taxOnShipping: Double? = null,
251252
val includeInPrice: Boolean? = null
252-
)
253+
) : BaseOrderTax
254+
255+
data class HandlingFeeTax(
256+
override val name: String? = null,
257+
override val value: Double? = null,
258+
override val total: Double? = null
259+
) : BaseOrderTax
253260

254261
data class ProductDimensions(
255262
val length: Double? = null,
@@ -287,7 +294,7 @@ data class UpdatedOrder(
287294
val name: String? = null,
288295
val value: Double? = null,
289296
val description: String? = null,
290-
val taxes: List<BaseOrderItemTax>? = null
297+
val taxes: List<HandlingFeeTax>? = null
291298
)
292299

293300
data class UtmData(

src/main/kotlin/com/ecwid/apiclient/v3/dto/order/result/FetchedOrder.kt

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.ecwid.apiclient.v3.dto.order.result
22

33
import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO
44
import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO.ModifyKind
5+
import com.ecwid.apiclient.v3.dto.common.BaseOrderTax
56
import com.ecwid.apiclient.v3.dto.common.OrderedStringToListStringMap
67
import com.ecwid.apiclient.v3.dto.common.OrderedStringToStringMap
78
import com.ecwid.apiclient.v3.dto.order.enums.*
@@ -222,21 +223,21 @@ data class FetchedOrder(
222223
)
223224

224225
data class BaseOrderItemTax(
225-
val name: String? = null,
226-
val value: Double? = null,
227-
val total: Double? = null
228-
)
226+
override val name: String? = null,
227+
override val value: Double? = null,
228+
override val total: Double? = null
229+
) : BaseOrderTax
229230

230231
data class OrderItemTax(
231-
val name: String? = null,
232-
val value: Double? = null,
233-
val total: Double? = null,
232+
override val name: String? = null,
233+
override val value: Double? = null,
234+
override val total: Double? = null,
234235
val taxOnDiscountedSubtotal: Double? = null,
235236
val taxOnShipping: Double? = null,
236237
val includeInPrice: Boolean? = null,
237238
val sourceTaxRateId: Int? = null,
238239
val sourceTaxRateType: RateType? = null
239-
) {
240+
) : BaseOrderTax {
240241
enum class RateType {
241242
AUTO,
242243
MANUAL,
@@ -245,6 +246,13 @@ data class FetchedOrder(
245246
}
246247
}
247248

249+
250+
data class HandlingFeeTax(
251+
override val name: String? = null,
252+
override val value: Double? = null,
253+
override val total: Double? = null
254+
) : BaseOrderTax
255+
248256
data class ProductDimensions(
249257
val length: Double? = null,
250258
val width: Double? = null,
@@ -306,7 +314,7 @@ data class FetchedOrder(
306314
val value: Double? = null,
307315
val valueWithoutTax: Double = 0.0,
308316
val description: String? = null,
309-
val taxes: List<BaseOrderItemTax> = listOf()
317+
val taxes: List<HandlingFeeTax> = listOf()
310318
)
311319

312320
data class RefundInfo(

src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedOrderRules.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ val fetchedOrderNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf
99
AllowNullable(FetchedOrder.BaseOrderItemTax::name),
1010
AllowNullable(FetchedOrder.BaseOrderItemTax::total),
1111
AllowNullable(FetchedOrder.BaseOrderItemTax::value),
12+
AllowNullable(FetchedOrder.HandlingFeeTax::name),
13+
AllowNullable(FetchedOrder.HandlingFeeTax::total),
14+
AllowNullable(FetchedOrder.HandlingFeeTax::value),
1215
AllowNullable(FetchedOrder::latestShipDate),
1316
IgnoreNullable(FetchedOrder::publicUid),
1417
IgnoreNullable(FetchedOrder.CreditCardStatus::avsMessage),

0 commit comments

Comments
 (0)