Skip to content

Commit

Permalink
Merge pull request #454 from Ecwid/ECWID-155668
Browse files Browse the repository at this point in the history
ECWID-155668 Add "updateShippingOption" method to ecwid-java-api-client
  • Loading branch information
RomanTimchenkoLightspeed authored Jan 30, 2025
2 parents 3ee595d + 31cae48 commit 0e287cf
Show file tree
Hide file tree
Showing 22 changed files with 582 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface StoreProfileApiClient {
fun getShippingOptions(request: ShippingOptionsRequest): ShippingOptionsResult

// fun addShippingOption()
// fun updateShippingOption()
fun updateShippingOption(request: UpdateShippingOptionRequest): UpdateShippingOptionResult
fun getPaymentOptions(request: PaymentOptionsRequest): PaymentOptionsResult
fun createPaymentOption(request: PaymentOptionCreateRequest): PaymentOptionCreateResult
fun deletePaymentOption(request: PaymentOptionDeleteRequest): PaymentOptionDeleteResult
Expand Down
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,
)
}
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
}
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)
}
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)
}
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
}
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
}
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("_", "-")
}
}
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,
}
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
)
)
}
}
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)
}
}
Loading

0 comments on commit 0e287cf

Please sign in to comment.