woocommerce-ios
woocommerce-ios copied to clipboard
Update Networking layer with GET `/wp-json/wc/v3/customers/<id>`
Part of #7741
Description
For merchants to be able to see and choose existing customers from their store when creating or editing orders, we need to know who are these existing customers. At the moment we can only get partial customer data based on other API properties, like Orders.
This PR adds the initial networking layer that we need in order to fetch existing customers from a Store. We do so by performing a GET request to the /wp-json/wc/v3/customers/<id>
API endpoint
Why don't we fetch the entirety of /customers/
endpoint?
We discovered that this endpoint does not search for first and last names, the proposed workaround is to use /wc-analytics/customers?search=
instead, which returns the customer's ID, then use /customers/<id>
to fetch the actual data.
For the moment, we're only modelling the Customer entity with a limited number of properties, the ones we actually use within the Order Creation screen (email
, firstName
, lastName
, billing
details, and shipping
details), rather than all available properties. We can include more later as needed.
Changes
- Added
CustomerRemote
,CustomerMapper
, andCustomer
objects to the Networking layer. This retrieves, decodes, maps, and models an individual Customer entity from its JSON representation received from the API. - Modified
Networking.generated
andModels+Copiable.generated
viarake generate
, due addingGeneratedCopiable
andGeneratedFakeable
conformance to the model. - Added a
customer.json
file replicating a dummy/wp-json/wc/v3/customers/<id>
API response, so we can Unit Test without hitting the actual network.
To avoid this PR to become too big, I'll add further Unit Tests on a different one.
Testing instructions
- Make sure that Unit Tests pass
You can test the changes from this Pull Request by:
- Clicking here or scanning the QR code below to access App Center
- Then installing the build number
pr7746-32dfe2a
on your iPhone