public class CustomerServiceImpl extends java.lang.Object implements CustomerService
| Modifier and Type | Field and Description |
|---|---|
protected ProjectEndpoints |
endpoints |
protected org.codehaus.jackson.type.TypeReference<QueryResult<T>> |
queryResultTypeReference |
protected RequestFactory |
requestFactory |
protected org.codehaus.jackson.type.TypeReference<T> |
typeReference |
| Constructor and Description |
|---|
CustomerServiceImpl(RequestFactory requestFactory,
ProjectEndpoints endpoints) |
| Modifier and Type | Method and Description |
|---|---|
QueryRequest<Customer> |
all()
Deprecated.
|
FetchRequest<Customer> |
byId(java.lang.String id)
Finds a customer by id.
|
FetchRequest<Customer> |
byToken(java.lang.String token)
Finds a customer by a token value.
|
CommandRequest<Customer> |
changePassword(VersionedId customerId,
java.lang.String currentPassword,
java.lang.String newPassword)
Sets a new password for a customer.
|
CommandRequest<Customer> |
confirmEmail(VersionedId customerId,
java.lang.String token)
Sets
Customer.isEmailVerified to true. |
protected CommandRequest<T> |
createCommandRequest(java.lang.String url,
Command command) |
CommandRequest<CustomerToken> |
createEmailVerificationToken(VersionedId customerId,
int ttlMinutes)
Creates a token used to verify customer's email.
|
CommandRequest<CustomerToken> |
createPasswordResetToken(java.lang.String email)
Creates a password reset token for the customer with the given email.
|
CommandRequest<CustomerToken> |
createPasswordResetToken(java.lang.String email,
int ttlMinutes) |
QueryRequest<Customer> |
query()
Queries customers.
|
protected QueryRequest<T> |
queryImpl(java.lang.String url) |
CommandRequest<Customer> |
resetPassword(VersionedId customerId,
java.lang.String token,
java.lang.String newPassword)
Sets a new password for a customer.
|
CommandRequest<SignInResult> |
signIn(java.lang.String email,
java.lang.String password)
Signs in a customer.
|
CommandRequest<SignInResult> |
signIn(java.lang.String email,
java.lang.String password,
java.lang.String cartId)
Signs in a customer and associates an existing anonymous cart to the customer.
|
CommandRequest<SignInResult> |
signUp(SignUpBuilder builder)
Creates a new customer.
|
CommandRequest<SignInResult> |
signUp(java.lang.String email,
java.lang.String password,
CustomerName name)
Creates a new customer.
|
CommandRequest<SignInResult> |
signUp(java.lang.String email,
java.lang.String password,
CustomerName name,
java.lang.String cartId)
Creates a new customer and associates an existing anonymous cart to the customer.
|
CommandRequest<Customer> |
update(VersionedId customerId,
CustomerUpdate customerUpdate)
Updates a customer.
|
protected ProjectEndpoints endpoints
protected RequestFactory requestFactory
protected org.codehaus.jackson.type.TypeReference<T> typeReference
protected org.codehaus.jackson.type.TypeReference<QueryResult<T>> queryResultTypeReference
public CustomerServiceImpl(RequestFactory requestFactory, ProjectEndpoints endpoints)
public FetchRequest<Customer> byId(java.lang.String id)
CustomerServicebyId in interface CustomerServicepublic FetchRequest<Customer> byToken(java.lang.String token)
CustomerServicebyToken in interface CustomerService@Deprecated public QueryRequest<Customer> all()
CustomerServiceall in interface CustomerServicepublic QueryRequest<Customer> query()
CustomerServicequery in interface CustomerServicepublic CommandRequest<SignInResult> signUp(java.lang.String email, java.lang.String password, CustomerName name)
CustomerServicesignUp in interface CustomerServiceEmailAlreadyInUseException if the email is already taken.
public CommandRequest<SignInResult> signUp(java.lang.String email, java.lang.String password, CustomerName name, java.lang.String cartId)
CustomerServiceIf the customer already had a cart, the given anonymous cart is merged with customer's cart. If no cart existed for the customer, the anonymous cart becomes customer's cart.
signUp in interface CustomerServicecartId - The id of the anonymous cart that should be merged / associated to the customer. Can't be empty.EmailAlreadyInUseException if the email is already taken.
public CommandRequest<SignInResult> signUp(SignUpBuilder builder)
CustomerServiceIf the customer already had a cart, the given anonymous cart is merged with customer's cart. If no cart existed for the customer, the anonymous cart becomes customer's cart.
signUp in interface CustomerServiceEmailAlreadyInUseException if the email is already taken.
public CommandRequest<SignInResult> signIn(java.lang.String email, java.lang.String password)
CustomerServicesignIn in interface CustomerServiceInvalidCredentialsException if no customer with given credentials exists.
public CommandRequest<SignInResult> signIn(java.lang.String email, java.lang.String password, java.lang.String cartId)
CustomerServiceIf the customer already had a cart, the given anonymous cart is merged with customer's cart. If no cart existed for the customer, the anonymous cart becomes customer's cart.
signIn in interface CustomerServicecartId - The id of the anonymous cart that should be merged / associated to the customer. Can't be empty.InvalidCredentialsException if no customer with given credentials exists.
public CommandRequest<Customer> changePassword(VersionedId customerId, java.lang.String currentPassword, java.lang.String newPassword)
CustomerServicechangePassword in interface CustomerServiceInvalidPasswordException if the current password is invalid.
public CommandRequest<Customer> update(VersionedId customerId, CustomerUpdate customerUpdate)
CustomerServiceupdate in interface CustomerServicepublic CommandRequest<CustomerToken> createPasswordResetToken(java.lang.String email)
CustomerServiceThe typical workflow is the following:
CustomerService.byToken(java.lang.String) and remember customer's id and version in hidden form fields.
If the customer can't be found, the token has expired or is invalid.
CustomerService.resetPassword(io.sphere.client.model.VersionedId, java.lang.String, java.lang.String),
passing in the customer id and version, the new password and the token (the token is extracted from the URL).
createPasswordResetToken in interface CustomerServiceemail - Email address for which the token should be created.public CommandRequest<CustomerToken> createPasswordResetToken(java.lang.String email, int ttlMinutes)
createPasswordResetToken in interface CustomerServiceemail - Email address for which the token should be created.ttlMinutes - A hint for the backend how long the token should be valid.
The actual timeout could be shorter.CustomerService.createPasswordResetToken(java.lang.String)public CommandRequest<Customer> resetPassword(VersionedId customerId, java.lang.String token, java.lang.String newPassword)
CustomerServiceCustomerService.createPasswordResetToken(String) method.resetPassword in interface CustomerServicepublic CommandRequest<CustomerToken> createEmailVerificationToken(VersionedId customerId, int ttlMinutes)
CustomerServiceTypically, verification emails are sent as part of the signup process but the decision is when and whether to verify customer emails is up to you.
The typical workflow is the following:
CustomerService.confirmEmail(io.sphere.client.model.VersionedId, java.lang.String),
passing in current customer's id, version and the token, extracted from the URL.
CustomerService.createEmailVerificationToken in interface CustomerServicettlMinutes - Validity of the token in minutes. The maximum allowed value is 43200 (30 days).public CommandRequest<Customer> confirmEmail(VersionedId customerId, java.lang.String token)
CustomerServiceCustomer.isEmailVerified to true.
Requires a token that was previously generated using the CustomerService.createEmailVerificationToken(io.sphere.client.model.VersionedId, int) method.confirmEmail in interface CustomerServiceprotected CommandRequest<T> createCommandRequest(java.lang.String url, Command command)
protected QueryRequest<T> queryImpl(java.lang.String url)