-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #454 from Ecwid/ECWID-155668
ECWID-155668 Add "updateShippingOption" method to ecwid-java-api-client
- Loading branch information
Showing
22 changed files
with
582 additions
and
172 deletions.
There are no files selected for viewing
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
141 changes: 141 additions & 0 deletions
141
src/main/kotlin/com/ecwid/apiclient/v3/converter/FetchedShippingOption.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,141 @@ | ||
package com.ecwid.apiclient.v3.converter | ||
|
||
import com.ecwid.apiclient.v3.dto.profile.request.UpdatedShippingOption | ||
import com.ecwid.apiclient.v3.dto.profile.result.FetchedShippingOption | ||
|
||
fun FetchedShippingOption.toUpdated(): UpdatedShippingOption { | ||
return UpdatedShippingOption( | ||
id = id, | ||
appClientId = appClientId, | ||
title = title, | ||
titleTranslated = titleTranslated, | ||
description = description, | ||
descriptionTranslated = descriptionTranslated, | ||
enabled = enabled, | ||
orderBy = orderBy, | ||
fulfilmentType = fulfilmentType, | ||
minimumOrderSubtotal = minimumOrderSubtotal, | ||
destinationZone = destinationZone?.toUpdated(), | ||
deliveryTimeDays = deliveryTimeDays, | ||
ratesCalculationType = ratesCalculationType, | ||
locationId = locationId, | ||
flatRate = flatRate?.toUpdated(), | ||
ratesTable = ratesTable?.toUpdated(), | ||
shippingCostMarkup = shippingCostMarkup, | ||
pickupPreparationTimeHours = pickupPreparationTimeHours, | ||
pickupBusinessHours = pickupBusinessHours, | ||
pickupInstruction = pickupInstruction, | ||
pickupInstructionTranslated = pickupInstructionTranslated, | ||
scheduledPickup = scheduledPickup, | ||
type = type, | ||
carrier = carrier, | ||
carrierSettings = carrierSettings?.toUpdate(), | ||
carrierMethods = carrierMethods?.map { it.toUpdated() }, | ||
businessHours = businessHours, | ||
businessHoursLimitationType = businessHoursLimitationType, | ||
allowSameDayDelivery = allowSameDayDelivery, | ||
availabilityPeriod = availabilityPeriod, | ||
customAvailabilityPeriodInDays = customAvailabilityPeriodInDays, | ||
scheduled = scheduled, | ||
scheduledTimePrecisionType = scheduledTimePrecisionType, | ||
timeSlotLengthInMinutes = timeSlotLengthInMinutes, | ||
cutoffTimeForSameDayDelivery = cutoffTimeForSameDayDelivery, | ||
fulfillmentTimeInMinutes = fulfillmentTimeInMinutes, | ||
blackoutDates = blackoutDates?.map { it.toUpdated() }, | ||
estimatedShippingTimeAtCheckoutSettings = estimatedShippingTimeAtCheckoutSettings?.toUpdated(), | ||
) | ||
} | ||
|
||
fun FetchedShippingOption.Zone.toUpdated(): UpdatedShippingOption.Zone { | ||
return UpdatedShippingOption.Zone( | ||
id = id, | ||
name = name, | ||
countryCodes = countryCodes, | ||
stateOrProvinceCodes = stateOrProvinceCodes, | ||
postCodes = postCodes, | ||
) | ||
} | ||
|
||
fun FetchedShippingOption.FlatRate.toUpdated(): UpdatedShippingOption.FlatRate { | ||
return UpdatedShippingOption.FlatRate( | ||
rateType = rateType, | ||
rate = rate, | ||
) | ||
} | ||
|
||
fun FetchedShippingOption.TableRates.toUpdated(): UpdatedShippingOption.TableRates { | ||
return UpdatedShippingOption.TableRates( | ||
tableBasedOn = tableBasedOn, | ||
rates = rates?.map { it.toUpdated() }, | ||
) | ||
} | ||
|
||
fun FetchedShippingOption.Rates.toUpdated(): UpdatedShippingOption.Rates { | ||
return UpdatedShippingOption.Rates( | ||
conditions = conditions?.toUpdated(), | ||
rate = rate?.toUpdated(), | ||
) | ||
} | ||
|
||
fun FetchedShippingOption.Conditions.toUpdated(): UpdatedShippingOption.Conditions { | ||
return UpdatedShippingOption.Conditions( | ||
subtotalFrom = subtotalFrom, | ||
subtotalTo = subtotalTo, | ||
discountedSubtotalFrom = discountedSubtotalFrom, | ||
discountedSubtotalTo = discountedSubtotalTo, | ||
weightFrom = weightFrom, | ||
weightTo = weightTo, | ||
) | ||
} | ||
|
||
fun FetchedShippingOption.Rate.toUpdated(): UpdatedShippingOption.Rate { | ||
return UpdatedShippingOption.Rate( | ||
perOrder = perOrder, | ||
percent = percent, | ||
perItem = perItem, | ||
perWeight = perWeight, | ||
) | ||
} | ||
|
||
fun FetchedShippingOption.BlackoutPeriodItem.toUpdated(): UpdatedShippingOption.BlackoutPeriodItem { | ||
return UpdatedShippingOption.BlackoutPeriodItem( | ||
fromDate = fromDate, | ||
toDate = toDate, | ||
repeatedAnnually = repeatedAnnually, | ||
) | ||
} | ||
|
||
fun FetchedShippingOption.EstimatedShippingTimeAtCheckoutSettings.toUpdated(): UpdatedShippingOption.EstimatedShippingTimeAtCheckoutSettings { | ||
return UpdatedShippingOption.EstimatedShippingTimeAtCheckoutSettings( | ||
estimatedDeliveryDateAtCheckoutEnabled = estimatedDeliveryDateAtCheckoutEnabled, | ||
estimatedTransitTimeInDays = estimatedTransitTimeInDays, | ||
fulfillmentTimeInDays = fulfillmentTimeInDays, | ||
shippingBusinessDays = shippingBusinessDays, | ||
deliveryDays = deliveryDays, | ||
cutoffTimeForSameDayPacking = cutoffTimeForSameDayPacking, | ||
) | ||
} | ||
|
||
fun FetchedShippingOption.CarrierSettings.toUpdate(): UpdatedShippingOption.CarrierSettings { | ||
return UpdatedShippingOption.CarrierSettings( | ||
defaultCarrierAccountEnabled = defaultCarrierAccountEnabled, | ||
defaultPostageDimensions = defaultPostageDimensions?.toUpdate(), | ||
) | ||
} | ||
|
||
fun FetchedShippingOption.DefaultPostageDimensions.toUpdate(): UpdatedShippingOption.DefaultPostageDimensions { | ||
return UpdatedShippingOption.DefaultPostageDimensions( | ||
height = height, | ||
length = length, | ||
width = width, | ||
) | ||
} | ||
|
||
fun FetchedShippingOption.CarrierMethod.toUpdated(): UpdatedShippingOption.CarrierMethod { | ||
return UpdatedShippingOption.CarrierMethod( | ||
id = id, | ||
name = name, | ||
enabled = enabled, | ||
orderBy = orderBy, | ||
) | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/enums/ApiBusinessHoursLimitationType.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,8 @@ | ||
package com.ecwid.apiclient.v3.dto.profile.enums | ||
|
||
@Suppress("unused") | ||
enum class ApiBusinessHoursLimitationType { | ||
ALLOW_ORDERS_AND_INFORM_CUSTOMERS, | ||
DISALLOW_ORDERS_AND_INFORM_CUSTOMERS, | ||
ALLOW_ORDERS_AND_DONT_INFORM_CUSTOMERS | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/enums/AvailabilityPeriodTimeUnit.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,10 @@ | ||
package com.ecwid.apiclient.v3.dto.profile.enums | ||
|
||
private const val MINUTES_IN_DAY = 1_440 // 24 hours * 60 minutes | ||
private const val MINUTES_IN_MONTH = 43_200 // 30 * MINUTES_IN_DAY | ||
|
||
@Suppress("unused") | ||
enum class AvailabilityPeriodTimeUnit(val valueInMinutes: Int) { | ||
DAYS(MINUTES_IN_DAY), | ||
MONTHS(MINUTES_IN_MONTH) | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/enums/AvailabilityPeriodType.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,12 @@ | ||
package com.ecwid.apiclient.v3.dto.profile.enums | ||
|
||
private const val DAYS_IN_WEEK = 7 | ||
private const val SINGLE_UNIT = 1 | ||
private const val MONTHS_IN_CENTURY = 1200 | ||
|
||
@Suppress("unused") | ||
enum class AvailabilityPeriodType(val unitCount: Int, val unit: AvailabilityPeriodTimeUnit?) { | ||
SEVEN_DAYS(DAYS_IN_WEEK, AvailabilityPeriodTimeUnit.DAYS), | ||
ONE_MONTH(SINGLE_UNIT, AvailabilityPeriodTimeUnit.MONTHS), | ||
UNLIMITED(MONTHS_IN_CENTURY, AvailabilityPeriodTimeUnit.MONTHS) | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/enums/FulfilmentType.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,6 @@ | ||
package com.ecwid.apiclient.v3.dto.profile.enums | ||
|
||
@Suppress("unused") | ||
enum class FulfilmentType { | ||
pickup, shipping, delivery | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/enums/RateType.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,7 @@ | ||
package com.ecwid.apiclient.v3.dto.profile.enums | ||
|
||
@Suppress("unused") | ||
enum class RateType { | ||
ABSOLUTE, | ||
PERCENT | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/enums/RatesCalculationType.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,18 @@ | ||
package com.ecwid.apiclient.v3.dto.profile.enums | ||
|
||
@Suppress("unused") | ||
enum class RatesCalculationType { | ||
|
||
carrier_calculated, | ||
table, | ||
flat, | ||
app; | ||
|
||
override fun toString(): String { | ||
return asApiString() | ||
} | ||
|
||
fun asApiString(): String { | ||
return super.toString().replace("_", "-") | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/enums/ScheduledTimePrecisionType.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,7 @@ | ||
package com.ecwid.apiclient.v3.dto.profile.enums | ||
|
||
@Suppress("unused") | ||
enum class ScheduledTimePrecisionType { | ||
DATE, | ||
DATE_AND_TIME_SLOT, | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/request/UpdateShippingOptionRequest.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,23 @@ | ||
package com.ecwid.apiclient.v3.dto.profile.request | ||
|
||
import com.ecwid.apiclient.v3.dto.ApiRequest | ||
import com.ecwid.apiclient.v3.httptransport.HttpBody | ||
import com.ecwid.apiclient.v3.impl.RequestInfo | ||
|
||
data class UpdateShippingOptionRequest( | ||
private val optionId: String = "", | ||
private val updatedShippingOption: UpdatedShippingOption = UpdatedShippingOption() | ||
) : ApiRequest { | ||
override fun toRequestInfo(): RequestInfo { | ||
return RequestInfo.createPutRequest( | ||
pathSegments = listOf( | ||
"profile", | ||
"shippingOptions", | ||
optionId | ||
), | ||
httpBody = HttpBody.JsonBody( | ||
obj = updatedShippingOption | ||
) | ||
) | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/request/UpdatedShippingOption.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,123 @@ | ||
package com.ecwid.apiclient.v3.dto.profile.request | ||
|
||
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO | ||
import com.ecwid.apiclient.v3.dto.profile.enums.* | ||
import com.ecwid.apiclient.v3.dto.profile.result.FetchedShippingOption | ||
import java.util.* | ||
|
||
data class UpdatedShippingOption( | ||
val id: String? = null, | ||
val appClientId: String? = null, | ||
val title: String? = null, | ||
val titleTranslated: Map<String, String>? = null, | ||
val description: String? = null, | ||
val descriptionTranslated: Map<String, String>? = null, | ||
val enabled: Boolean? = null, | ||
val orderBy: Int? = null, | ||
val fulfilmentType: FulfilmentType? = null, | ||
val minimumOrderSubtotal: Double? = null, | ||
val destinationZone: Zone? = null, | ||
val ratesCalculationType: RatesCalculationType? = null, | ||
val locationId: String? = null, | ||
val flatRate: FlatRate? = null, | ||
val shippingCostMarkup: Double? = null, | ||
val ratesTable: TableRates? = null, | ||
val pickupInstruction: String? = null, | ||
val pickupInstructionTranslated: Map<String, String>? = null, | ||
val pickupPreparationTimeHours: Int? = null, | ||
val pickupBusinessHours: String? = null, | ||
val scheduledPickup: Boolean? = null, | ||
val type: String? = null, | ||
val carrier: String? = null, | ||
val carrierMethods: List<CarrierMethod>? = null, | ||
val carrierSettings: CarrierSettings? = null, | ||
val businessHours: String? = null, | ||
val businessHoursLimitationType: ApiBusinessHoursLimitationType? = null, | ||
val allowSameDayDelivery: Boolean? = null, | ||
val deliveryTimeDays: String? = null, | ||
val availabilityPeriod: AvailabilityPeriodType? = null, | ||
val customAvailabilityPeriodInDays: Int? = null, | ||
val scheduled: Boolean? = null, | ||
val scheduledTimePrecisionType: ScheduledTimePrecisionType? = null, | ||
val timeSlotLengthInMinutes: Int? = null, | ||
val cutoffTimeForSameDayDelivery: String? = null, | ||
val fulfillmentTimeInMinutes: Int? = null, | ||
val blackoutDates: List<BlackoutPeriodItem>? = null, | ||
val estimatedShippingTimeAtCheckoutSettings: EstimatedShippingTimeAtCheckoutSettings? = null, | ||
) : ApiUpdatedDTO { | ||
data class Zone( | ||
val id: String? = null, | ||
val name: String? = null, | ||
val countryCodes: List<String>? = null, | ||
val stateOrProvinceCodes: List<String>? = null, | ||
val postCodes: List<String>? = null, | ||
) | ||
|
||
data class FlatRate( | ||
val rateType: RateType? = null, | ||
val rate: Double? = null, | ||
) | ||
|
||
data class TableRates( | ||
val tableBasedOn: String? = null, | ||
val rates: List<Rates>? = null, | ||
) | ||
|
||
data class Rates( | ||
val conditions: Conditions? = null, | ||
val rate: Rate? = null, | ||
) | ||
|
||
data class Conditions( | ||
val subtotalFrom: Double? = null, | ||
val subtotalTo: Double? = null, | ||
val discountedSubtotalFrom: Double? = null, | ||
val discountedSubtotalTo: Double? = null, | ||
val weightFrom: Double? = null, | ||
val weightTo: Double? = null, | ||
) | ||
|
||
data class Rate( | ||
val perOrder: Double? = null, | ||
val percent: Double? = null, | ||
val perItem: Double? = null, | ||
val perWeight: Double? = null, | ||
) | ||
|
||
data class CarrierMethod( | ||
val id: String? = null, | ||
val name: String? = null, | ||
val enabled: Boolean? = null, | ||
val orderBy: Int? = null | ||
) | ||
|
||
data class BlackoutPeriodItem( | ||
val fromDate: Date? = null, | ||
val toDate: Date? = null, | ||
val repeatedAnnually: Boolean? = null, | ||
) | ||
|
||
data class EstimatedShippingTimeAtCheckoutSettings( | ||
val estimatedDeliveryDateAtCheckoutEnabled: Boolean? = null, | ||
val estimatedTransitTimeInDays: List<Int>? = null, | ||
val fulfillmentTimeInDays: List<Int>? = null, | ||
val shippingBusinessDays: List<String>? = null, | ||
val deliveryDays: List<String>? = null, | ||
val cutoffTimeForSameDayPacking: String? = null, | ||
) | ||
|
||
data class CarrierSettings( | ||
val defaultCarrierAccountEnabled: Boolean? = null, | ||
val defaultPostageDimensions: DefaultPostageDimensions? = null | ||
) | ||
|
||
data class DefaultPostageDimensions( | ||
val length: Double? = null, | ||
val width: Double? = null, | ||
val height: Double? = null | ||
) | ||
|
||
override fun getModifyKind(): ApiUpdatedDTO.ModifyKind { | ||
return ApiUpdatedDTO.ModifyKind.ReadWrite(FetchedShippingOption::class) | ||
} | ||
} |
Oops, something went wrong.