question

tg avatar image
tg asked tg commented

add customer to order through SDK

Attempting to add a customer to an order via SDK

I can instantiate a v3 customer however cannot seem to find the V3 CustomerConnector.

I am able to create a V1 Customer via CustomerConnector as shown here, however the v3 Order requires a v3 Customer.

Am I missing a step here?

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.

Mark R avatar image
Mark R answered

Did you try to use V1 customer connector? In fact it will work for you though. Use V3 order connector with V1 customer connector. For your requirement of connecting a customer to an order, that will work. if you are getting any specific error or exceptions, pass it on too.

10 |2000

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

Mike M avatar image
Mike M answered tg commented

Basically, you need to stub out a v3 customer object using the ID of the v1 customer. Here's a code stub of the basic operation.

final com.clover.sdk.v3.customers.Customer customerV3 = new com.clover.sdk.v3.customers.Customer();
customerV3.setId(customerV1.getId());
Order currentOrder = orderConnector.getOrder(orderId);
currentOrder.setCustomers(Collections.singletonList(customerV3));
orderConnector.updateOrder(currentOrder);
4 comments
10 |2000

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

tg avatar image tg commented ·

When using this code and then immediately firing the order programmatically, the customer name is often (5/10 times) null on the Order receipt. I will even loop back through every few seconds before firing with the following check

while(currentOrder.getCustomers() == null ||currentOrder.getCustomers().get(0).getFirstName() == null)

And tested updating the order with currentOrder = orderConnector.getOrder(currentOrder.getId()); and currentOrder = orderConnector.updateOrder(currentOrder);

If I go back into the Orders app, the customer information is there. Is there a way to refresh the order

0 Likes 0 ·
Mike M avatar image Mike M commented ·

@tg, how are you firing off the order programmatically? It's possible that the async updateOrder was not complete at that time.

0 Likes 0 ·
tg avatar image tg commented ·

using orderConnector.fire(currentOrder.getId());

I have written in a loop that waits for the customer name to not be null before firing, sometimes the customer just never shows up. Each loop I get and then update the order using order connector, even tried disconnecting/reconnecting order connector and creating a new order connector. ~5/10 times it will not show up. Thanks for your help on this mike

0 Likes 0 ·
Mike M avatar image Mike M commented ·

Sorry for the delayed response, is this all within the same async task? can you please post a async task code sample?

0 Likes 0 ·

Welcome to the
Clover Developer Community