Skip to content

Commit 0e287cf

Browse files
Merge pull request #454 from Ecwid/ECWID-155668
ECWID-155668 Add "updateShippingOption" method to ecwid-java-api-client
2 parents 3ee595d + 31cae48 commit 0e287cf

22 files changed

Lines changed: 582 additions & 172 deletions

src/main/kotlin/com/ecwid/apiclient/v3/StoreProfileApiClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface StoreProfileApiClient {
1717
fun getShippingOptions(request: ShippingOptionsRequest): ShippingOptionsResult
1818

1919
// fun addShippingOption()
20-
// fun updateShippingOption()
20+
fun updateShippingOption(request: UpdateShippingOptionRequest): UpdateShippingOptionResult
2121
fun getPaymentOptions(request: PaymentOptionsRequest): PaymentOptionsResult
2222
fun createPaymentOption(request: PaymentOptionCreateRequest): PaymentOptionCreateResult
2323
fun deletePaymentOption(request: PaymentOptionDeleteRequest): PaymentOptionDeleteResult
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
package com.ecwid.apiclient.v3.converter
2+
3+
import com.ecwid.apiclient.v3.dto.profile.request.UpdatedShippingOption
4+
import com.ecwid.apiclient.v3.dto.profile.result.FetchedShippingOption
5+
6+
fun FetchedShippingOption.toUpdated(): UpdatedShippingOption {
7+
return UpdatedShippingOption(
8+
id = id,
9+
appClientId = appClientId,
10+
title = title,
11+
titleTranslated = titleTranslated,
12+
description = description,
13+
descriptionTranslated = descriptionTranslated,
14+
enabled = enabled,
15+
orderBy = orderBy,
16+
fulfilmentType = fulfilmentType,
17+
minimumOrderSubtotal = minimumOrderSubtotal,
18+
destinationZone = destinationZone?.toUpdated(),
19+
deliveryTimeDays = deliveryTimeDays,
20+
ratesCalculationType = ratesCalculationType,
21+
locationId = locationId,
22+
flatRate = flatRate?.toUpdated(),
23+
ratesTable = ratesTable?.toUpdated(),
24+
shippingCostMarkup = shippingCostMarkup,
25+
pickupPreparationTimeHours = pickupPreparationTimeHours,
26+
pickupBusinessHours = pickupBusinessHours,
27+
pickupInstruction = pickupInstruction,
28+
pickupInstructionTranslated = pickupInstructionTranslated,
29+
scheduledPickup = scheduledPickup,
30+
type = type,
31+
carrier = carrier,
32+
carrierSettings = carrierSettings?.toUpdate(),
33+
carrierMethods = carrierMethods?.map { it.toUpdated() },
34+
businessHours = businessHours,
35+
businessHoursLimitationType = businessHoursLimitationType,
36+
allowSameDayDelivery = allowSameDayDelivery,
37+
availabilityPeriod = availabilityPeriod,
38+
customAvailabilityPeriodInDays = customAvailabilityPeriodInDays,
39+
scheduled = scheduled,
40+
scheduledTimePrecisionType = scheduledTimePrecisionType,
41+
timeSlotLengthInMinutes = timeSlotLengthInMinutes,
42+
cutoffTimeForSameDayDelivery = cutoffTimeForSameDayDelivery,
43+
fulfillmentTimeInMinutes = fulfillmentTimeInMinutes,
44+
blackoutDates = blackoutDates?.map { it.toUpdated() },
45+
estimatedShippingTimeAtCheckoutSettings = estimatedShippingTimeAtCheckoutSettings?.toUpdated(),
46+
)
47+
}
48+
49+
fun FetchedShippingOption.Zone.toUpdated(): UpdatedShippingOption.Zone {
50+
return UpdatedShippingOption.Zone(
51+
id = id,
52+
name = name,
53+
countryCodes = countryCodes,
54+
stateOrProvinceCodes = stateOrProvinceCodes,
55+
postCodes = postCodes,
56+
)
57+
}
58+
59+
fun FetchedShippingOption.FlatRate.toUpdated(): UpdatedShippingOption.FlatRate {
60+
return UpdatedShippingOption.FlatRate(
61+
rateType = rateType,
62+
rate = rate,
63+
)
64+
}
65+
66+
fun FetchedShippingOption.TableRates.toUpdated(): UpdatedShippingOption.TableRates {
67+
return UpdatedShippingOption.TableRates(
68+
tableBasedOn = tableBasedOn,
69+
rates = rates?.map { it.toUpdated() },
70+
)
71+
}
72+
73+
fun FetchedShippingOption.Rates.toUpdated(): UpdatedShippingOption.Rates {
74+
return UpdatedShippingOption.Rates(
75+
conditions = conditions?.toUpdated(),
76+
rate = rate?.toUpdated(),
77+
)
78+
}
79+
80+
fun FetchedShippingOption.Conditions.toUpdated(): UpdatedShippingOption.Conditions {
81+
return UpdatedShippingOption.Conditions(
82+
subtotalFrom = subtotalFrom,
83+
subtotalTo = subtotalTo,
84+
discountedSubtotalFrom = discountedSubtotalFrom,
85+
discountedSubtotalTo = discountedSubtotalTo,
86+
weightFrom = weightFrom,
87+
weightTo = weightTo,
88+
)
89+
}
90+
91+
fun FetchedShippingOption.Rate.toUpdated(): UpdatedShippingOption.Rate {
92+
return UpdatedShippingOption.Rate(
93+
perOrder = perOrder,
94+
percent = percent,
95+
perItem = perItem,
96+
perWeight = perWeight,
97+
)
98+
}
99+
100+
fun FetchedShippingOption.BlackoutPeriodItem.toUpdated(): UpdatedShippingOption.BlackoutPeriodItem {
101+
return UpdatedShippingOption.BlackoutPeriodItem(
102+
fromDate = fromDate,
103+
toDate = toDate,
104+
repeatedAnnually = repeatedAnnually,
105+
)
106+
}
107+
108+
fun FetchedShippingOption.EstimatedShippingTimeAtCheckoutSettings.toUpdated(): UpdatedShippingOption.EstimatedShippingTimeAtCheckoutSettings {
109+
return UpdatedShippingOption.EstimatedShippingTimeAtCheckoutSettings(
110+
estimatedDeliveryDateAtCheckoutEnabled = estimatedDeliveryDateAtCheckoutEnabled,
111+
estimatedTransitTimeInDays = estimatedTransitTimeInDays,
112+
fulfillmentTimeInDays = fulfillmentTimeInDays,
113+
shippingBusinessDays = shippingBusinessDays,
114+
deliveryDays = deliveryDays,
115+
cutoffTimeForSameDayPacking = cutoffTimeForSameDayPacking,
116+
)
117+
}
118+
119+
fun FetchedShippingOption.CarrierSettings.toUpdate(): UpdatedShippingOption.CarrierSettings {
120+
return UpdatedShippingOption.CarrierSettings(
121+
defaultCarrierAccountEnabled = defaultCarrierAccountEnabled,
122+
defaultPostageDimensions = defaultPostageDimensions?.toUpdate(),
123+
)
124+
}
125+
126+
fun FetchedShippingOption.DefaultPostageDimensions.toUpdate(): UpdatedShippingOption.DefaultPostageDimensions {
127+
return UpdatedShippingOption.DefaultPostageDimensions(
128+
height = height,
129+
length = length,
130+
width = width,
131+
)
132+
}
133+
134+
fun FetchedShippingOption.CarrierMethod.toUpdated(): UpdatedShippingOption.CarrierMethod {
135+
return UpdatedShippingOption.CarrierMethod(
136+
id = id,
137+
name = name,
138+
enabled = enabled,
139+
orderBy = orderBy,
140+
)
141+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.ecwid.apiclient.v3.dto.profile.enums
2+
3+
@Suppress("unused")
4+
enum class ApiBusinessHoursLimitationType {
5+
ALLOW_ORDERS_AND_INFORM_CUSTOMERS,
6+
DISALLOW_ORDERS_AND_INFORM_CUSTOMERS,
7+
ALLOW_ORDERS_AND_DONT_INFORM_CUSTOMERS
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.ecwid.apiclient.v3.dto.profile.enums
2+
3+
private const val MINUTES_IN_DAY = 1_440 // 24 hours * 60 minutes
4+
private const val MINUTES_IN_MONTH = 43_200 // 30 * MINUTES_IN_DAY
5+
6+
@Suppress("unused")
7+
enum class AvailabilityPeriodTimeUnit(val valueInMinutes: Int) {
8+
DAYS(MINUTES_IN_DAY),
9+
MONTHS(MINUTES_IN_MONTH)
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.ecwid.apiclient.v3.dto.profile.enums
2+
3+
private const val DAYS_IN_WEEK = 7
4+
private const val SINGLE_UNIT = 1
5+
private const val MONTHS_IN_CENTURY = 1200
6+
7+
@Suppress("unused")
8+
enum class AvailabilityPeriodType(val unitCount: Int, val unit: AvailabilityPeriodTimeUnit?) {
9+
SEVEN_DAYS(DAYS_IN_WEEK, AvailabilityPeriodTimeUnit.DAYS),
10+
ONE_MONTH(SINGLE_UNIT, AvailabilityPeriodTimeUnit.MONTHS),
11+
UNLIMITED(MONTHS_IN_CENTURY, AvailabilityPeriodTimeUnit.MONTHS)
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.ecwid.apiclient.v3.dto.profile.enums
2+
3+
@Suppress("unused")
4+
enum class FulfilmentType {
5+
pickup, shipping, delivery
6+
}
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.profile.enums
2+
3+
@Suppress("unused")
4+
enum class RateType {
5+
ABSOLUTE,
6+
PERCENT
7+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.ecwid.apiclient.v3.dto.profile.enums
2+
3+
@Suppress("unused")
4+
enum class RatesCalculationType {
5+
6+
carrier_calculated,
7+
table,
8+
flat,
9+
app;
10+
11+
override fun toString(): String {
12+
return asApiString()
13+
}
14+
15+
fun asApiString(): String {
16+
return super.toString().replace("_", "-")
17+
}
18+
}
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.profile.enums
2+
3+
@Suppress("unused")
4+
enum class ScheduledTimePrecisionType {
5+
DATE,
6+
DATE_AND_TIME_SLOT,
7+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.ecwid.apiclient.v3.dto.profile.request
2+
3+
import com.ecwid.apiclient.v3.dto.ApiRequest
4+
import com.ecwid.apiclient.v3.httptransport.HttpBody
5+
import com.ecwid.apiclient.v3.impl.RequestInfo
6+
7+
data class UpdateShippingOptionRequest(
8+
private val optionId: String = "",
9+
private val updatedShippingOption: UpdatedShippingOption = UpdatedShippingOption()
10+
) : ApiRequest {
11+
override fun toRequestInfo(): RequestInfo {
12+
return RequestInfo.createPutRequest(
13+
pathSegments = listOf(
14+
"profile",
15+
"shippingOptions",
16+
optionId
17+
),
18+
httpBody = HttpBody.JsonBody(
19+
obj = updatedShippingOption
20+
)
21+
)
22+
}
23+
}

0 commit comments

Comments
 (0)