wcUpdateCustomerInfo method
Future<WCCustomerUpdatedResponse>
wcUpdateCustomerInfo({
- String? userToken,
- String? firstName,
- String? lastName,
- String? displayName,
- String? billingFirstName,
- String? billingLastName,
- String? billingCompany,
- String? billingAddress1,
- String? billingAddress2,
- String? billingCity,
- String? billingState,
- String? billingPostcode,
- String? billingCountry,
- String? billingEmail,
- String? billingPhone,
- String? shippingFirstName,
- String? shippingLastName,
- String? shippingCompany,
- String? shippingAddress1,
- String? shippingAddress2,
- String? shippingCity,
- String? shippingState,
- String? shippingPostcode,
- String? shippingCountry,
- String? shippingEmail,
- String? shippingPhone,
Sends a request to update a users WooCommerce details using
a valid userToken
, set optional parameters for updating user.
Returns WCCustomerUpdatedResponse future. Throws an Exception if fails.
Implementation
Future<WCCustomerUpdatedResponse> wcUpdateCustomerInfo(
{String? userToken,
String? firstName,
String? lastName,
String? displayName,
String? billingFirstName,
String? billingLastName,
String? billingCompany,
String? billingAddress1,
String? billingAddress2,
String? billingCity,
String? billingState,
String? billingPostcode,
String? billingCountry,
String? billingEmail,
String? billingPhone,
String? shippingFirstName,
String? shippingLastName,
String? shippingCompany,
String? shippingAddress1,
String? shippingAddress2,
String? shippingCity,
String? shippingState,
String? shippingPostcode,
String? shippingCountry,
String? shippingEmail,
String? shippingPhone}) async {
Map<String, dynamic> payload = {};
if (firstName != null) payload["first_name"] = firstName;
if (lastName != null) payload["last_name"] = lastName;
if (displayName != null) payload["display_name"] = displayName;
Map<String, dynamic> shippingPayload = {};
if (shippingFirstName != null)
shippingPayload["first_name"] = shippingFirstName;
if (shippingLastName != null)
shippingPayload["last_name"] = shippingLastName;
if (shippingCompany != null) shippingPayload["company"] = shippingCompany;
if (shippingAddress1 != null)
shippingPayload["address_1"] = shippingAddress1;
if (shippingAddress2 != null)
shippingPayload["address_2"] = shippingAddress2;
if (shippingCity != null) shippingPayload["city"] = shippingCity;
if (shippingState != null) shippingPayload["state"] = shippingState;
if (shippingPostcode != null)
shippingPayload["postcode"] = shippingPostcode;
if (shippingCountry != null) shippingPayload["country"] = shippingCountry;
if (shippingEmail != null) shippingPayload["email"] = shippingEmail;
if (shippingPhone != null) shippingPayload["phone"] = shippingPhone;
Map<String, dynamic> billingPayload = {};
if (billingFirstName != null)
billingPayload["first_name"] = billingFirstName;
if (billingLastName != null) billingPayload["last_name"] = billingLastName;
if (billingCompany != null) billingPayload["company"] = billingCompany;
if (billingAddress1 != null) billingPayload["address_1"] = billingAddress1;
if (billingAddress2 != null) billingPayload["address_2"] = billingAddress2;
if (billingCity != null) billingPayload["city"] = billingCity;
if (billingState != null) billingPayload["state"] = billingState;
if (billingPostcode != null) billingPayload["postcode"] = billingPostcode;
if (billingCountry != null) billingPayload["country"] = billingCountry;
if (billingEmail != null) billingPayload["email"] = billingEmail;
if (billingPhone != null) billingPayload["phone"] = billingPhone;
if (shippingPayload.isNotEmpty) {
payload["shipping"] = shippingPayload;
}
if (billingPayload.isNotEmpty) {
payload["billing"] = billingPayload;
}
// send http request
final json = await _http(
method: "POST",
url: _urlForRouteType(WPRouteType.WCCustomerUpdateInfo),
body: payload,
userToken: userToken,
shouldAuthRequest: true);
// return response
return _jsonHasBadStatus(json)
? this._throwExceptionForStatusCode(json)
: WCCustomerUpdatedResponse.fromJson(json);
}