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

Commit 26f6190

Browse files
committed
Update customer APi
1 parent f11ad0f commit 26f6190

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@ class CustomerRestClient @Inject constructor(private val wooNetwork: WooNetwork)
115115
return response.toWooPayload()
116116
}
117117

118+
/**
119+
* Makes a PUT call to `/wc/v3/customers/[remoteCustomerId]` to update a customer
120+
*
121+
* @param [remoteCustomerId] Unique server id of the customer to update
122+
*/
123+
suspend fun updateCustomer(
124+
site: SiteModel,
125+
remoteCustomerId: Long,
126+
customer: CustomerDTO
127+
): WooPayload<CustomerDTO> {
128+
val url = WOOCOMMERCE.customers.id(remoteCustomerId).pathV3
129+
130+
val response = wooNetwork.executePutGsonRequest(
131+
site = site,
132+
path = url,
133+
body = customer.toMap(),
134+
clazz = CustomerDTO::class.java
135+
)
136+
137+
return response.toWooPayload()
138+
}
139+
118140
/**
119141
* Makes a GET call to `wc-analytics/reports/customers` to fetch customers
120142
*

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,27 @@ class WCCustomerStore @Inject constructor(
186186
}
187187
}
188188

189+
/**
190+
* updates a customer on the backend
191+
*/
192+
suspend fun updateCustomer(
193+
site: SiteModel,
194+
customer: WCCustomerModel
195+
): WooResult<WCCustomerModel> {
196+
return coroutineEngine.withDefaultContext(AppLog.T.API, this, "updateCustomer") {
197+
val response = restClient.updateCustomer(
198+
site,
199+
customer.remoteCustomerId,
200+
mapper.mapToDTO(customer)
201+
)
202+
when {
203+
response.isError -> WooResult(response.error)
204+
response.result != null -> WooResult(mapper.mapToModel(site, response.result))
205+
else -> WooResult(WooError(GENERIC_ERROR, UNKNOWN))
206+
}
207+
}
208+
}
209+
189210
/**
190211
* returns customers from analytics
191212
*/

0 commit comments

Comments
 (0)