Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECWID-144507 New customer extrafields #422

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added src/.DS_Store
Binary file not shown.
5 changes: 4 additions & 1 deletion src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ open class ApiClient private constructor(
instantSiteRedirectsApiClient: InstantSiteRedirectsApiClientImpl,
slugInfoApiClient: SlugInfoApiClientImpl,
productReviewsApiClient: ProductReviewsApiClientImpl,
storeExtrafieldsApiClient: StoreExtrafieldsApiClientImpl,
) :
StoreProfileApiClient by storeProfileApiClient,
ProductsApiClient by productsApiClient,
Expand All @@ -92,7 +93,8 @@ open class ApiClient private constructor(
SubscriptionsApiClient by subscriptionsApiClient,
InstantSiteRedirectsApiClient by instantSiteRedirectsApiClient,
SlugInfoApiClient by slugInfoApiClient,
ProductReviewsApiClient by productReviewsApiClient {
ProductReviewsApiClient by productReviewsApiClient,
StoreExtrafieldsApiClient by storeExtrafieldsApiClient {

constructor(apiClientHelper: ApiClientHelper) : this(
apiClientHelper = apiClientHelper,
Expand All @@ -115,6 +117,7 @@ open class ApiClient private constructor(
instantSiteRedirectsApiClient = InstantSiteRedirectsApiClientImpl(apiClientHelper),
slugInfoApiClient = SlugInfoApiClientImpl(apiClientHelper),
productReviewsApiClient = ProductReviewsApiClientImpl(apiClientHelper),
storeExtrafieldsApiClient = StoreExtrafieldsApiClientImpl(apiClientHelper),
)

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.ecwid.apiclient.v3

import com.ecwid.apiclient.v3.dto.extrafield.request.*
import com.ecwid.apiclient.v3.dto.extrafield.result.*


interface StoreExtrafieldsApiClient {
fun searchCustomersConfigs(request: CustomersConfigsSearchRequest): CustomersConfigsSearchResult
fun getCustomersConfig(request: CustomersConfigDetailsRequest): FetchedCustomersConfig
fun createCustomersConfig(request: CustomersConfigCreateRequest): CustomersConfigCreateResult
fun updateCustomersConfig(request: CustomersConfigUpdateRequest): CustomersConfigUpdateResult
fun deleteCustomersConfig(request: CustomersConfigDeleteRequest): CustomersConfigDeleteResult
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fun FetchedCustomer.toUpdated(): UpdatedCustomer {
lang = lang,
privateAdminNotes = privateAdminNotes,
commercialRelationshipScheme = commercialRelationshipScheme,
extrafields = extrafields?.map(FetchedCustomer.CustomerExtrafield::toUpdated)
)
}

Expand Down Expand Up @@ -61,3 +62,12 @@ fun FetchedCustomer.CustomerContact.toUpdated(): UpdatedCustomer.CustomerContact
orderBy = orderBy,
)
}

fun FetchedCustomer.CustomerExtrafield.toUpdated(): UpdatedCustomer.CustomerExtrafield {
return UpdatedCustomer.CustomerExtrafield(
key = key,
title = title,
value = value,
type = type,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.ecwid.apiclient.v3.converter

import com.ecwid.apiclient.v3.dto.extrafield.request.UpdatedCustomersConfig
import com.ecwid.apiclient.v3.dto.extrafield.result.FetchedCustomersConfig


fun FetchedCustomersConfig.toUpdated(): UpdatedCustomersConfig {
return UpdatedCustomersConfig(
key = key,
title = title,
type = type,
shownOnOrderDetails = shownOnOrderDetails,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO.ModifyKind
import com.ecwid.apiclient.v3.dto.customer.enums.CommercialRelationshipScheme
import com.ecwid.apiclient.v3.dto.customer.result.FetchedCustomer
import com.ecwid.apiclient.v3.dto.extrafield.enums.ExtrafieldType
import com.ecwid.apiclient.v3.jsontransformer.JsonFieldName

data class UpdatedCustomer(
Expand All @@ -19,6 +20,7 @@ data class UpdatedCustomer(
val acceptMarketing: Boolean? = null,
val lang: String? = null,
val privateAdminNotes: String? = null,
val extrafields: List<CustomerExtrafield>? = null,

@JsonFieldName("b2b_b2c")
val commercialRelationshipScheme: CommercialRelationshipScheme? = null,
Expand Down Expand Up @@ -60,5 +62,12 @@ data class UpdatedCustomer(
val orderBy: Int? = null,
)

data class CustomerExtrafield(
val key: String? = null,
val title: String? = null,
val value: String? = null,
val type: ExtrafieldType? = null,
)

override fun getModifyKind() = ModifyKind.ReadWrite(FetchedCustomer::class)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO
import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO.ModifyKind
import com.ecwid.apiclient.v3.dto.customer.enums.CommercialRelationshipScheme
import com.ecwid.apiclient.v3.dto.customer.request.UpdatedCustomer
import com.ecwid.apiclient.v3.dto.extrafield.enums.ExtrafieldEntityType
import com.ecwid.apiclient.v3.dto.extrafield.enums.ExtrafieldType
import com.ecwid.apiclient.v3.jsontransformer.JsonFieldName
import java.util.*
import kotlin.collections.ArrayList

data class FetchedCustomer(
val id: Int = 0,
Expand All @@ -26,6 +27,7 @@ data class FetchedCustomer(
val stats: CustomerStats? = null,
val privateAdminNotes: String? = null,
val favorites: List<CustomerFavorite> = ArrayList(),
val extrafields: List<CustomerExtrafield>? = null,

@JsonFieldName("b2b_b2c")
val commercialRelationshipScheme: CommercialRelationshipScheme = CommercialRelationshipScheme.b2c,
Expand Down Expand Up @@ -89,5 +91,14 @@ data class FetchedCustomer(
val addedTimestamp: Date? = null,
)

data class CustomerExtrafield(
val key: String? = null,
val title: String? = null,
val value: String? = null,
val orderBy: Int = 0,
val type: ExtrafieldType? = null,
val entityTypes: List<ExtrafieldEntityType> = emptyList(),
)

override fun getModifyKind() = ModifyKind.ReadWrite(UpdatedCustomer::class)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.ecwid.apiclient.v3.dto.extrafield.enums

enum class ExtrafieldEntityType {
CHECKOUT,
CUSTOMERS,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ecwid.apiclient.v3.dto.profile.enums
package com.ecwid.apiclient.v3.dto.extrafield.enums

enum class ExtrafieldType {
TEXT,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.ecwid.apiclient.v3.dto.extrafield.request

import com.ecwid.apiclient.v3.dto.ApiRequest
import com.ecwid.apiclient.v3.httptransport.HttpBody
import com.ecwid.apiclient.v3.impl.RequestInfo

data class CustomersConfigCreateRequest(
val newConfig: UpdatedCustomersConfig = UpdatedCustomersConfig()
) : ApiRequest {
override fun toRequestInfo() = RequestInfo.createPostRequest(
pathSegments = listOf(
"store_extrafields",
"customers"
),
httpBody = HttpBody.JsonBody(
obj = newConfig
)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.ecwid.apiclient.v3.dto.extrafield.request

import com.ecwid.apiclient.v3.dto.ApiRequest
import com.ecwid.apiclient.v3.impl.RequestInfo

data class CustomersConfigDeleteRequest(
val extrafieldKey: String = ""
) : ApiRequest {
override fun toRequestInfo() = RequestInfo.createDeleteRequest(
pathSegments = listOf(
"store_extrafields",
"customers",
extrafieldKey
),
params = mapOf()
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ecwid.apiclient.v3.dto.extrafield.request

import com.ecwid.apiclient.v3.dto.ApiRequest
import com.ecwid.apiclient.v3.impl.RequestInfo
import com.ecwid.apiclient.v3.responsefields.ResponseFields

data class CustomersConfigDetailsRequest(
val extrafieldKey: String = "",
val responseFields: ResponseFields = ResponseFields.All,
) : ApiRequest {
override fun toRequestInfo() = RequestInfo.createGetRequest(
pathSegments = listOf(
"store_extrafields",
"customers",
extrafieldKey
),
params = mapOf(),
responseFields = responseFields,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.ecwid.apiclient.v3.dto.extrafield.request

import com.ecwid.apiclient.v3.dto.ApiRequest
import com.ecwid.apiclient.v3.httptransport.HttpBody
import com.ecwid.apiclient.v3.impl.RequestInfo

data class CustomersConfigUpdateRequest(
val extrafieldKey: String = "",
val updatedConfig: UpdatedCustomersConfig = UpdatedCustomersConfig()
) : ApiRequest {
override fun toRequestInfo() = RequestInfo.createPutRequest(
pathSegments = listOf(
"store_extrafields",
"customers",
extrafieldKey
),
httpBody = HttpBody.JsonBody(
obj = updatedConfig
)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.ecwid.apiclient.v3.dto.extrafield.request

import com.ecwid.apiclient.v3.dto.ApiRequest
import com.ecwid.apiclient.v3.impl.RequestInfo
import com.ecwid.apiclient.v3.responsefields.ResponseFields


data class CustomersConfigsSearchRequest(
val responseFields: ResponseFields = ResponseFields.All,
) : ApiRequest {
override fun toRequestInfo() = RequestInfo.createGetRequest(
pathSegments = listOf(
"store_extrafields",
"customers"
),
params = mapOf(),
responseFields = responseFields,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.ecwid.apiclient.v3.dto.extrafield.request

import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO.ModifyKind
import com.ecwid.apiclient.v3.dto.extrafield.enums.ExtrafieldType
import com.ecwid.apiclient.v3.dto.extrafield.result.FetchedCustomersConfig

data class UpdatedCustomersConfig(
val key: String? = null,
val title: String? = null,
val type: ExtrafieldType? = null,
val shownOnOrderDetails: Boolean? = null,
) : ApiUpdatedDTO {

override fun getModifyKind() = ModifyKind.ReadWrite(FetchedCustomersConfig::class)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.ecwid.apiclient.v3.dto.extrafield.result

import com.ecwid.apiclient.v3.dto.common.ApiResultDTO

data class CustomersConfigCreateResult(
val createCount: Int = 0,
val key: String = ""
) : ApiResultDTO
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.ecwid.apiclient.v3.dto.extrafield.result

import com.ecwid.apiclient.v3.dto.common.ApiResultDTO

data class CustomersConfigDeleteResult(
val deleteCount: Int = 0
) : ApiResultDTO
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.ecwid.apiclient.v3.dto.extrafield.result

import com.ecwid.apiclient.v3.dto.common.ApiResultDTO

data class CustomersConfigUpdateResult(
val updateCount: Int = 0
) : ApiResultDTO
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.ecwid.apiclient.v3.dto.extrafield.result

import com.ecwid.apiclient.v3.dto.common.ApiResultDTO

data class CustomersConfigsSearchResult(
val items: List<FetchedCustomersConfig> = listOf(),
) : ApiResultDTO
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ecwid.apiclient.v3.dto.extrafield.result

import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO
Fixed Show fixed Hide fixed
import com.ecwid.apiclient.v3.dto.extrafield.enums.ExtrafieldEntityType
import com.ecwid.apiclient.v3.dto.extrafield.enums.ExtrafieldType
import com.ecwid.apiclient.v3.dto.extrafield.request.UpdatedCustomersConfig
import java.util.*

data class FetchedCustomersConfig(
val key: String? = null,
val title: String? = null,
val entityTypes: ExtrafieldEntityType? = null,
val type: ExtrafieldType? = null,
val shownOnOrderDetails: Boolean? = null,
val createdDate: Date? = null,
val lastModifiedDate: Date? = null,
) : ApiFetchedDTO {

override fun getModifyKind() = ApiFetchedDTO.ModifyKind.ReadWrite(UpdatedCustomersConfig::class)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data class ExtrafieldConfigUpdateRequest(
pathSegments = listOf(
"profile",
"extrafields",
"$extrafieldKey"
extrafieldKey
),
httpBody = HttpBody.JsonBody(
obj = updatedConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,38 @@ package com.ecwid.apiclient.v3.dto.profile.request
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO.ModifyKind
import com.ecwid.apiclient.v3.dto.common.LocalizedValueMap
import com.ecwid.apiclient.v3.dto.extrafield.enums.ExtrafieldType
import com.ecwid.apiclient.v3.dto.profile.enums.CheckoutDisplaySection
import com.ecwid.apiclient.v3.dto.profile.enums.ExtrafieldType
import com.ecwid.apiclient.v3.dto.profile.enums.OrderDetailsDisplaySection
import com.ecwid.apiclient.v3.dto.profile.enums.SurchargeType
import com.ecwid.apiclient.v3.dto.profile.result.FetchedExtrafieldConfig

data class UpdatedExtrafieldConfig(
val key: String? = null,
val title: String? = null,
val type: ExtrafieldType? = null,
val textPlaceholder: String? = null,
val tip: String? = null,
val options: List<UpdatedExtrafieldOptionConfig>? = null,
val value: String? = null,
val available: Boolean? = null,
val required: Boolean? = null,
val checkoutDisplaySection: CheckoutDisplaySection? = null,
val orderDetailsDisplaySection: OrderDetailsDisplaySection? = null,
val showForCountry: List<String>? = null,
val showForPaymentMethodIds: List<String>? = null,
val showForShippingMethodIds: List<String>? = null,
val showInInvoice: Boolean? = null,
val showInNotifications: Boolean? = null,
val orderBy: Int? = null,
val surchargeType: SurchargeType? = null,
val surchargeTaxable: Boolean? = null,
val showZeroSurchargeInTotal: Boolean? = null,
val surchargeShortName: UpdatedExtrafieldSurchargeConfig? = null,
val titleTranslated: LocalizedValueMap? = null,
val textPlaceholderTranslated: LocalizedValueMap? = null,
val tipTranslated: LocalizedValueMap? = null,
val valueTranslated: LocalizedValueMap? = null
val key: String? = null,
val title: String? = null,
val type: ExtrafieldType? = null,
val textPlaceholder: String? = null,
val tip: String? = null,
val options: List<UpdatedExtrafieldOptionConfig>? = null,
val value: String? = null,
val available: Boolean? = null,
val required: Boolean? = null,
val checkoutDisplaySection: CheckoutDisplaySection? = null,
val orderDetailsDisplaySection: OrderDetailsDisplaySection? = null,
val showForCountry: List<String>? = null,
val showForPaymentMethodIds: List<String>? = null,
val showForShippingMethodIds: List<String>? = null,
val showInInvoice: Boolean? = null,
val showInNotifications: Boolean? = null,
val orderBy: Int? = null,
val surchargeType: SurchargeType? = null,
val surchargeTaxable: Boolean? = null,
val showZeroSurchargeInTotal: Boolean? = null,
val surchargeShortName: UpdatedExtrafieldSurchargeConfig? = null,
val titleTranslated: LocalizedValueMap? = null,
val textPlaceholderTranslated: LocalizedValueMap? = null,
val tipTranslated: LocalizedValueMap? = null,
val valueTranslated: LocalizedValueMap? = null
) : ApiUpdatedDTO {

data class UpdatedExtrafieldOptionConfig(
Expand Down
Loading
Loading