Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into ECWID-124685
Browse files Browse the repository at this point in the history
  • Loading branch information
winrokru committed Aug 17, 2023
2 parents 937ea8c + 86f86b7 commit 4376e8d
Show file tree
Hide file tree
Showing 28 changed files with 108 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.ecwid.apiclient.v3.dto.saleschannels.response.*
import com.ecwid.apiclient.v3.dto.storage.request.*
import com.ecwid.apiclient.v3.dto.storage.result.*
import com.ecwid.apiclient.v3.dto.subscriptions.request.SubscriptionsSearchRequest
import com.ecwid.apiclient.v3.dto.subscriptions.result.FetchedSubscription
import com.ecwid.apiclient.v3.dto.subscriptions.result.SubscriptionsSearchResult
import com.ecwid.apiclient.v3.dto.variation.request.*
import com.ecwid.apiclient.v3.dto.variation.result.*
Expand Down Expand Up @@ -348,6 +349,7 @@ interface ReportsApiClient {
// https://api-docs.ecwid.com/reference/get-subscription
interface SubscriptionsApiClient {
fun searchSubscriptions(request: SubscriptionsSearchRequest): SubscriptionsSearchResult
fun searchSubscriptionsAsSequence(request: SubscriptionsSearchRequest): Sequence<FetchedSubscription>
}

interface InstantSiteRedirectsApiClient {
Expand Down
22 changes: 20 additions & 2 deletions src/main/kotlin/com/ecwid/apiclient/v3/ApiClientHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.ecwid.apiclient.v3.config.*
import com.ecwid.apiclient.v3.dto.ApiRequest
import com.ecwid.apiclient.v3.dto.common.EcwidApiError
import com.ecwid.apiclient.v3.dto.product.result.FetchedProduct.ProductOption
import com.ecwid.apiclient.v3.dto.report.result.FetchedReportResponse
import com.ecwid.apiclient.v3.exception.EcwidApiException
import com.ecwid.apiclient.v3.exception.JsonDeserializationException
import com.ecwid.apiclient.v3.httptransport.*
Expand Down Expand Up @@ -50,7 +51,7 @@ class ApiClientHelper private constructor(
credentials = storeCredentials,
loggingSettings = loggingSettings,
httpTransport = httpTransport,
jsonTransformer = jsonTransformerProvider.build(listOf(createProductOptionsPolymorphicType()))
jsonTransformer = jsonTransformerProvider.build(createPolymorphicTypeList())
)

constructor(
Expand All @@ -64,7 +65,7 @@ class ApiClientHelper private constructor(
credentials = credentials,
loggingSettings = loggingSettings,
httpTransport = httpTransport,
jsonTransformer = jsonTransformerProvider.build(listOf(createProductOptionsPolymorphicType()))
jsonTransformer = jsonTransformerProvider.build(createPolymorphicTypeList())
)

@PublishedApi
Expand Down Expand Up @@ -455,6 +456,13 @@ internal fun HttpBody.prepare(jsonTransformer: JsonTransformer): TransportHttpBo
}
}

fun createPolymorphicTypeList(): List<PolymorphicType<*>> {
return listOf(
createProductOptionsPolymorphicType(),
createAdditionalDataPolymorphicType()
)
}

private fun createProductOptionsPolymorphicType(): PolymorphicType<ProductOption> {
return PolymorphicType(
rootClass = ProductOption::class.java,
Expand All @@ -471,3 +479,13 @@ private fun createProductOptionsPolymorphicType(): PolymorphicType<ProductOption
)
)
}

private fun createAdditionalDataPolymorphicType(): PolymorphicType<FetchedReportResponse.FetchedAdditionalData> {
return PolymorphicType(
rootClass = FetchedReportResponse.FetchedAdditionalData::class.java,
jsonFieldName = "type",
childClasses = mapOf(
"utm" to FetchedReportResponse.FetchedAdditionalData.AdditionalUtmData::class.java,
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ fun FetchedOrder.OrderItem.toUpdated(): UpdatedOrder.OrderItem {
taxable = taxable,

selectedOptions = selectedOptions?.map(FetchedOrder.OrderItemSelectedOption::toUpdated),
combinationId = combinationId,
taxes = taxes?.map(FetchedOrder.OrderItemTax::toUpdated),
dimensions = dimensions?.toUpdated(),
discounts = discounts?.map(FetchedOrder.OrderItemDiscounts::toUpdated),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ data class OrderForCalculate(
val shippingOption: ShippingOption? = null,
val handlingFee: HandlingFee? = null,
val paymentOptionsDetails: PaymentOption? = null,
val giftCardCode: String? = null,
val giftCardId: Int? = null,
val giftCardTransactionOrderId: Int? = null,
) : ApiRequestDTO {

data class DiscountInfo(
Expand Down Expand Up @@ -87,6 +90,7 @@ data class OrderForCalculate(
val couponApplied: Boolean? = null,

val selectedOptions: List<OrderItemOption>? = null,
val combinationId: Int? = null,
val taxes: List<OrderItemTax>? = null,
val files: List<OrderItemProductFile>? = null,
val dimensions: ProductDimensions? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ data class CalculateOrderDetailsResult(
val couponApplied: Boolean? = null,

val selectedOptions: List<OrderItemOption>? = null,
val combinationId: Int? = null,
val taxes: List<OrderItemTax>? = null,
val files: List<OrderItemProductFile>? = null,
val dimensions: ProductDimensions? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ data class FetchedCart(
val couponApplied: Boolean? = null,

val selectedOptions: List<OrderItemOption>? = null,
val combinationId: Int? = null,
val taxes: List<OrderItemTax>? = null,
val files: List<OrderItemProductFile>? = null,
val dimensions: ProductDimensions? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ data class UpdatedOrder(
val isGiftCard: Boolean? = null,

val selectedOptions: List<OrderItemSelectedOption>? = null,
val combinationId: Int? = null,
val taxes: List<OrderItemTax>? = null,
val dimensions: ProductDimensions? = null,
val discountsAllowed: Boolean? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ data class FetchedOrder(
val totalBeforeGiftCardRedemption: Double? = null,
val giftCardDoubleSpending: Boolean? = null,
val giftCardCode: String? = null,
val giftCardId: Int? = null,

val total: Double? = null,
val totalWithoutTax: Double? = null,
Expand Down Expand Up @@ -190,6 +191,7 @@ data class FetchedOrder(
val subscriptionId: Long? = null,

val selectedOptions: List<OrderItemSelectedOption>? = null,
val combinationId: Int? = null,
val files: List<OrderItemProductFile>? = null,
val taxable: Boolean? = null,
val taxes: List<OrderItemTax>? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ data class FetchedProduct(
val defaultDisplayedCompareToPriceDiscountPercentFormatted: String? = null,

val lowestPrice: Double? = null,
val lowestPriceFormatted: String? = null,
val defaultDisplayedLowestPrice: Double? = null,
val defaultDisplayedLowestPriceFormatted: String? = null,

val weight: Double? = null,
val dimensions: ProductDimensions? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,32 @@ data class FetchedReportResponse(
val percentage: Double? = null,
val comparePeriodStartTimeStamp: Long? = null,
val comparePeriodEndTimeStamp: Long? = null,
val additionalData: FetchedAdditionalData? = null,
)

data class FetchedDataItem(
val dataId: String = "",
val dataValue: Double = 0.0,
)

sealed class FetchedAdditionalData(
val type: AdditionalDataType,
) {
data class AdditionalUtmData(
val utmList: List<FetchedUtmDataItem> = emptyList(),
) : FetchedAdditionalData(AdditionalDataType.UTM)

enum class AdditionalDataType {
UTM
}
}

data class FetchedUtmDataItem(
val utmSource: String = "",
val utmMedium: String = "",
val utmCampaign: String = "",
)

override fun getModifyKind() = ApiFetchedDTO.ModifyKind.ReadOnly

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ enum class SubscriptionStatus {
CANCELLED,
LAST_CHARGE_FAILED,
REQUIRES_PAYMENT_CONFIRMATION,
PAUSED,
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ data class SubscriptionsSearchRequest(
val updatedFrom: Date? = null,
val updatedTo: Date? = null,
val customerId: Int? = null,
val status: SubscriptionStatus? = null,
val status: List<SubscriptionStatus>? = null,
val nextChargeFrom: Date? = null,
val nextChargeTo: Date? = null,
val recurringInterval: SubscriptionInterval? = null,
Expand All @@ -29,9 +29,10 @@ data class SubscriptionsSearchRequest(
val orderTotal: Double? = null,
val orderCreatedFrom: Date? = null,
val orderCreatedTo: Date? = null,
val offset: Int? = null,
val limit: Int? = null,
val offset: Int = 0,
val limit: Int = 100,
val sortBy: SortOrder = SortOrder.DATE_CREATED_DESC,
val lang: String? = null,
val responseFields: ResponseFields = ResponseFields.All,
) : ApiRequest {

Expand All @@ -53,7 +54,7 @@ data class SubscriptionsSearchRequest(
updatedFrom?.let { put("updatedFrom", TimeUnit.MILLISECONDS.toSeconds(it.time).toString()) }
updatedTo?.let { put("updatedTo", TimeUnit.MILLISECONDS.toSeconds(it.time).toString()) }
customerId?.let { put("customerId", it.toString()) }
status?.let { put("status", it.name) }
status?.let { put("status", it.joinToString(",")) }
nextChargeFrom?.let { put("nextChargeFrom", TimeUnit.MILLISECONDS.toSeconds(it.time).toString()) }
nextChargeTo?.let { put("nextChargeTo", TimeUnit.MILLISECONDS.toSeconds(it.time).toString()) }
recurringInterval?.let { put("recurringInterval", it.name) }
Expand All @@ -67,6 +68,7 @@ data class SubscriptionsSearchRequest(
offset?.let { put("offset", it.toString()) }
limit?.let { put("limit", it.toString()) }
put("sortBy", sortBy.name)
lang?.let { put("lang", it) }
}.toMap()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.ecwid.apiclient.v3.dto.subscriptions.result

import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO
import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO.ModifyKind
import com.ecwid.apiclient.v3.dto.common.LocalizedValueMap
import com.ecwid.apiclient.v3.dto.subscriptions.enums.PriceModifierType
import com.ecwid.apiclient.v3.dto.subscriptions.enums.ProductOptionType
import com.ecwid.apiclient.v3.dto.subscriptions.enums.SubscriptionInterval
Expand All @@ -17,6 +18,7 @@ data class FetchedSubscription(
val created: Date = Date(),
val cancelled: Date? = null,
val nextCharge: Date = Date(),
val nextChargeFormatted: String = "",
val createTimestamp: Long? = null,
val updateTimestamp: Long? = null,
val chargeSettings: ChargeSettings = ChargeSettings(),
Expand Down Expand Up @@ -110,6 +112,7 @@ data class FetchedSubscription(

val sku: String? = null,
val name: String? = null,
val nameTranslated: LocalizedValueMap? = null,
val shortDescription: String? = null,
val quantity: Int? = null,
val quantityInStock: Int? = null,
Expand All @@ -120,7 +123,10 @@ data class FetchedSubscription(

val digital: Boolean? = null,
val productAvailable: Boolean? = null,

val imageUrl: String? = null,
val smallThumbnailUrl: String? = null,
val hdThumbnailUrl: String? = null,

val recurringChargeSettings: RecurringChargeSettings? = null,
val selectedOptions: List<SelectedOptions>? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ data class FetchedVariation(
val costPrice: Double? = null,
val compareToPrice: Double? = null,
val lowestPrice: Double? = null,
val lowestPriceFormatted: String? = null,
val defaultDisplayedLowestPrice: Double? = null,
val defaultDisplayedLowestPriceFormatted: String? = null,
val wholesalePrices: List<WholesalePrice>? = null,

val quantity: Int? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.ecwid.apiclient.v3.ApiClientHelper
import com.ecwid.apiclient.v3.SubscriptionsApiClient
import com.ecwid.apiclient.v3.dto.subscriptions.request.SubscriptionsSearchRequest
import com.ecwid.apiclient.v3.dto.subscriptions.result.SubscriptionsSearchResult
import com.ecwid.apiclient.v3.responsefields.AS_SEQUENCE_SEARCH_RESULT_REQUIRED_FIELDS

class SubscriptionsApiClientImpl(
private val apiClientHelper: ApiClientHelper
Expand All @@ -12,4 +13,15 @@ class SubscriptionsApiClientImpl(
override fun searchSubscriptions(request: SubscriptionsSearchRequest) =
apiClientHelper.makeObjectResultRequest<SubscriptionsSearchResult>(request)

override fun searchSubscriptionsAsSequence(request: SubscriptionsSearchRequest) = sequence {
var offsetRequest = request.copy(
responseFields = request.responseFields + AS_SEQUENCE_SEARCH_RESULT_REQUIRED_FIELDS
)
do {
val searchResult = searchSubscriptions(offsetRequest)
yieldAll(searchResult.items)
offsetRequest = offsetRequest.copy(offset = offsetRequest.offset + searchResult.count)
} while (searchResult.count >= searchResult.limit)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class DtoContractUnitTest {
val ignoreNullablePropertiesCount = nullablePropertyRules
.filterIsInstance<IgnoreNullable<*, *>>()
.size
assertEquals(975, ignoreNullablePropertiesCount) {
assertEquals(976, ignoreNullablePropertiesCount) {
"You MUST NOT add exclusion with type IgnoreNullable() which is used only for old fields until they are fixed.\n" +
"Please make added property non-nullable if possible.\n" +
"If Ecwid API sometimes return null as value for this property you CAN add it to as `AllowNullable()` exclusion type instead."
Expand Down
3 changes: 3 additions & 0 deletions src/test/kotlin/com/ecwid/apiclient/v3/entity/CartsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class CartsTest : BaseEntityTest() {
assertEquals(orderSelectedOption.type, cartSelectedOptions.type)
// TODO Discover why after each create field `valuesArray` some times resets to null
}
assertEquals(orderItem.combinationId, cartItem.combinationId)

assertEquals(orderItem.taxes?.count(), cartItem.taxes?.count())
cartItem.taxes?.forEachIndexed { taxIndex, cartTaxes ->
Expand Down Expand Up @@ -316,6 +317,7 @@ class CartsTest : BaseEntityTest() {
calculatedOrderItemOptions.files?.count()
) // TODO Discover why after each calculation this field resets to null
}
assertEquals(forCalculateItem.combinationId, calculatedItem.combinationId)

assertEquals(forCalculateItem.files?.count(), calculatedItem.files?.count())
calculatedItem.files?.forEachIndexed { taxIndex, calculatedFile ->
Expand Down Expand Up @@ -488,6 +490,7 @@ class CartsTest : BaseEntityTest() {
generateDateSelectedOption(),
generateFilesSelectedOption()
),
combinationId = randomId(),
taxes = listOf(
generateTestOrderItemTax()
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ val nonUpdatablePropertyRules: List<NonUpdatablePropertyRule<*, *>> = listOf(
ReadOnly(FetchedProduct::defaultDisplayedCompareToPriceDiscountPercent),
ReadOnly(FetchedProduct::defaultDisplayedCompareToPriceDiscountPercentFormatted),
Ignored(FetchedProduct::lowestPrice),
ReadOnly(FetchedProduct::lowestPriceFormatted),
ReadOnly(FetchedProduct::defaultDisplayedLowestPrice),
ReadOnly(FetchedProduct::defaultDisplayedLowestPriceFormatted),
Ignored(FetchedProduct.AttributeValue::name),
Ignored(FetchedProduct.AttributeValue::type),
Ignored(FetchedProduct.AttributeValue::show),
Expand Down Expand Up @@ -150,6 +151,7 @@ val nonUpdatablePropertyRules: List<NonUpdatablePropertyRule<*, *>> = listOf(
ReadOnly(FetchedOrder::orderExtraFields),
ReadOnly(FetchedOrder::giftCardCode),
ReadOnly(FetchedOrder::giftCardDoubleSpending),
ReadOnly(FetchedOrder::giftCardId),
ReadOnly(FetchedOrder::giftCardRedemption),
ReadOnly(FetchedOrder::totalBeforeGiftCardRedemption),
ReadOnly(FetchedOrder::totalWithoutTax),
Expand Down Expand Up @@ -254,7 +256,8 @@ val nonUpdatablePropertyRules: List<NonUpdatablePropertyRule<*, *>> = listOf(
ReadOnly(FetchedVariation::inStock),
Ignored(FetchedVariation::borderInfo),
Ignored(FetchedVariation::lowestPrice),
ReadOnly(FetchedVariation::lowestPriceFormatted),
ReadOnly(FetchedVariation::defaultDisplayedLowestPrice),
ReadOnly(FetchedVariation::defaultDisplayedLowestPriceFormatted),
Ignored(FetchedVariation.AttributeValue::name),
Ignored(FetchedVariation.AttributeValue::type),
Ignored(FetchedVariation.AttributeValue::show),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ val otherNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
AllowNullable(FetchedReportResponse.FetchedDataset::percentage),
AllowNullable(FetchedReportResponse.FetchedDataset::comparePeriodStartTimeStamp),
AllowNullable(FetchedReportResponse.FetchedDataset::comparePeriodEndTimeStamp),
AllowNullable(FetchedReportResponse.FetchedDataset::additionalData),

AllowNullable(InstantSiteRedirectsSearchRequest::keyword),
AllowNullable(InstantSiteRedirectsSearchRequest::limit),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ val calculateOrderDetailsResultNullablePropertyRules: List<NullablePropertyRule<
IgnoreNullable(CalculateOrderDetailsResult.OrderItem::quantity),
IgnoreNullable(CalculateOrderDetailsResult.OrderItem::quantityInStock),
IgnoreNullable(CalculateOrderDetailsResult.OrderItem::selectedOptions),
AllowNullable(CalculateOrderDetailsResult.OrderItem::combinationId),
IgnoreNullable(CalculateOrderDetailsResult.OrderItem::shipping),
IgnoreNullable(CalculateOrderDetailsResult.OrderItem::shortDescription),
IgnoreNullable(CalculateOrderDetailsResult.OrderItem::sku),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.ecwid.apiclient.v3.rule.nullablepropertyrules

import com.ecwid.apiclient.v3.dto.cart.result.FetchedCart
import com.ecwid.apiclient.v3.rule.NullablePropertyRule
import com.ecwid.apiclient.v3.rule.NullablePropertyRule.IgnoreNullable
import com.ecwid.apiclient.v3.rule.NullablePropertyRule.*

val fetchedCartNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
IgnoreNullable(FetchedCart::acceptMarketing),
Expand Down Expand Up @@ -97,6 +97,7 @@ val fetchedCartNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
IgnoreNullable(FetchedCart.OrderItem::quantity),
IgnoreNullable(FetchedCart.OrderItem::quantityInStock),
IgnoreNullable(FetchedCart.OrderItem::selectedOptions),
AllowNullable(FetchedCart.OrderItem::combinationId),
IgnoreNullable(FetchedCart.OrderItem::shipping),
IgnoreNullable(FetchedCart.OrderItem::shortDescription),
IgnoreNullable(FetchedCart.OrderItem::sku),
Expand Down
Loading

0 comments on commit 4376e8d

Please sign in to comment.