Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 6186393

Browse files
committed
Delete customer API
1 parent 26f6190 commit 6186393

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/customer/CustomerRestClient.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,22 @@ class CustomerRestClient @Inject constructor(private val wooNetwork: WooNetwork)
137137
return response.toWooPayload()
138138
}
139139

140+
/**
141+
* Makes a DELETE call to `/wc/v3/customers/[remoteCustomerId]` to delete a customer
142+
*
143+
* @param [remoteCustomerId] Unique server id of the customer to delete
144+
*/
145+
suspend fun deleteCustomer(site: SiteModel, remoteCustomerId: Long): WooPayload<CustomerDTO> {
146+
val url = WOOCOMMERCE.customers.id(remoteCustomerId).pathV3
147+
148+
val response = wooNetwork.executeDeleteGsonRequest(
149+
site = site,
150+
path = url,
151+
clazz = CustomerDTO::class.java
152+
)
153+
154+
return response.toWooPayload()
155+
140156
/**
141157
* Makes a GET call to `wc-analytics/reports/customers` to fetch customers
142158
*

plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCCustomerStore.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,23 @@ class WCCustomerStore @Inject constructor(
207207
}
208208
}
209209

210+
/**
211+
* delete customer on the backend
212+
*/
213+
suspend fun deleteCustomer(
214+
site: SiteModel,
215+
customer: WCCustomerModel,
216+
): WooResult<WCCustomerModel> {
217+
return coroutineEngine.withDefaultContext(AppLog.T.API, this, "deleteCustomer") {
218+
val response = restClient.deleteCustomer(site, customer.remoteCustomerId)
219+
when {
220+
response.isError -> WooResult(response.error)
221+
response.result != null -> WooResult(mapper.mapToModel(site, response.result))
222+
else -> WooResult(WooError(GENERIC_ERROR, UNKNOWN))
223+
}
224+
}
225+
}
226+
210227
/**
211228
* returns customers from analytics
212229
*/

0 commit comments

Comments
 (0)