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)
CustomerService
byId
in interface CustomerService
public FetchRequest<Customer> byToken(java.lang.String token)
CustomerService
byToken
in interface CustomerService
@Deprecated public QueryRequest<Customer> all()
CustomerService
all
in interface CustomerService
public QueryRequest<Customer> query()
CustomerService
query
in interface CustomerService
public CommandRequest<SignInResult> signUp(java.lang.String email, java.lang.String password, CustomerName name)
CustomerService
signUp
in interface CustomerService
EmailAlreadyInUseException
if the email is already taken.
public CommandRequest<SignInResult> signUp(java.lang.String email, java.lang.String password, CustomerName name, java.lang.String cartId)
CustomerService
If 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 CustomerService
cartId
- 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)
CustomerService
If 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 CustomerService
EmailAlreadyInUseException
if the email is already taken.
public CommandRequest<SignInResult> signIn(java.lang.String email, java.lang.String password)
CustomerService
signIn
in interface CustomerService
InvalidCredentialsException
if no customer with given credentials exists.
public CommandRequest<SignInResult> signIn(java.lang.String email, java.lang.String password, java.lang.String cartId)
CustomerService
If 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 CustomerService
cartId
- 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)
CustomerService
changePassword
in interface CustomerService
InvalidPasswordException
if the current password is invalid.
public CommandRequest<Customer> update(VersionedId customerId, CustomerUpdate customerUpdate)
CustomerService
update
in interface CustomerService
public CommandRequest<CustomerToken> createPasswordResetToken(java.lang.String email)
CustomerService
The 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 CustomerService
email
- Email address for which the token should be created.public CommandRequest<CustomerToken> createPasswordResetToken(java.lang.String email, int ttlMinutes)
createPasswordResetToken
in interface CustomerService
email
- 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)
CustomerService
CustomerService.createPasswordResetToken(String)
method.resetPassword
in interface CustomerService
public CommandRequest<CustomerToken> createEmailVerificationToken(VersionedId customerId, int ttlMinutes)
CustomerService
Typically, 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 CustomerService
ttlMinutes
- Validity of the token in minutes. The maximum allowed value is 43200 (30 days).public CommandRequest<Customer> confirmEmail(VersionedId customerId, java.lang.String token)
CustomerService
Customer.isEmailVerified
to true.
Requires a token that was previously generated using the CustomerService.createEmailVerificationToken(io.sphere.client.model.VersionedId, int)
method.confirmEmail
in interface CustomerService
protected CommandRequest<T> createCommandRequest(java.lang.String url, Command command)
protected QueryRequest<T> queryImpl(java.lang.String url)