question

georgi avatar image
georgi asked anthonypinto answered

How to add a new customer for merchant?

I am using this code to create a customer. I can click on it from the Orders screen but it is not attached to merchant. How can I attach it for the current merchant so it will be visible on the Customers screen?

customerConnector.addEmailAddress(newCustomer.getId(), getText(email));
newCustomer = customerConnector.createCustomer(getText(firstName), getText(lastName), true);
customerConnector.addPhoneNumber(newCustomer.getId(), getText(phone));
customerConnector.setAddress(newCustomer.getId(), getText(address), null, null, null, null, null, null);
MerchantCustomers
10 |2000 characters needed characters left characters exceeded

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

1 Answer

anthonypinto avatar image
anthonypinto answered

In your code you are referencing newCustomer before you assign it in the second line.

I switched the order, and subbed your getTexts for string literals:

Customer newCustomer = customerConnector.createCustomer("John", "Doe", true);
customerConnector.addEmailAddress(newCustomer.getId(), "JDoe@foo.bar");
customerConnector.addPhoneNumber(newCustomer.getId(), "8004444444");
customerConnector.setAddress(newCustomer.getId(), "addressaddressaddressaddress", null, null, null, null, null, null);

Then I called your code in an async task and it ran fine, and resulted in a new customer for my merchant.

Make sure that you are passing all the values you expect, and that you have instantiated the Connecter, and run the connect() method on the instance.

10 |2000 characters needed characters left characters exceeded

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