question

georgi avatar image
georgi asked georgi answered

Associate customer with order

I want to achieve this functionality within my app. I allow the merchant to create a customer and then associate it with an order. Questions:

  1. Do I return just the CUSTOMER_ID in the setResult of the activity?
  2. Do I have to modify the order and set new customers array?
  3. Why does order.setCustomers receive v3 customers and customer connector return v1 customers !?!?!?!?

Guys, I feel like programming for Clover is one of the greatest challenges in my life... It really makes me think if it is worth.

OrdersCustomers
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

georgi avatar image
georgi answered

So the problem is you have to work with v3.Customer class and v1.Customer class. order.setCustomers(List<v3.customer> customers) - accepts only v3.Customer list. To fight thing you need to make a mapping between v1 and v3 Customer class like this:

List<com.clover.sdk.v3.customers.Customer> customers = new ArrayList<>();

// Believe it or not gson transformation to json string does not work. It is not the needed string
com.clover.sdk.v3.customers.Customer newCustomer = new com.clover.sdk.v3.customers.Customer(gson.toJson(customer));

// This works
newCustomer.setId(customer.getId());
newCustomer.setFirstName(customer.getFirstName());
newCustomer.setLastName(customer.getLastName());

Is there a method which contains the mapping or I have to make an util method?

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community