All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sphere.sdk.customers.commands.CustomerVerifyEmailCommand Maven / Gradle / Ivy

There is a newer version: 1.0.0-M26
Show newest version
package io.sphere.sdk.customers.commands;

import com.fasterxml.jackson.databind.JavaType;
import io.sphere.sdk.client.HttpRequestIntent;
import io.sphere.sdk.commands.CommandImpl;
import io.sphere.sdk.customers.Customer;
import io.sphere.sdk.customers.CustomerToken;
import io.sphere.sdk.models.Versioned;
import io.sphere.sdk.json.SphereJsonUtils;

import static io.sphere.sdk.http.HttpMethod.POST;

/**

 Verifies customer's email using a token.

 {@include.example io.sphere.sdk.customers.commands.CustomerCreateEmailTokenCommandTest#execution()}

 @see Customer
 @see Customer#isEmailVerified()
 @see CustomerCreateEmailTokenCommand
 */
public final class CustomerVerifyEmailCommand extends CommandImpl {

    private final String id;
    private final Long version;
    private final String tokenValue;

    private CustomerVerifyEmailCommand(final String id, final Long version, final String tokenValue) {
        this.id = id;
        this.version = version;
        this.tokenValue = tokenValue;
    }

    @Override
    protected JavaType jacksonJavaType() {
        return SphereJsonUtils.convertToJavaType(Customer.typeReference());
    }

    @Override
    public HttpRequestIntent httpRequestIntent() {
        return HttpRequestIntent.of(POST, "/customers/email/confirm", SphereJsonUtils.toJsonString(this));
    }

    public static CustomerVerifyEmailCommand of(final Versioned customer, final String tokenValue) {
        return new CustomerVerifyEmailCommand(customer.getId(), customer.getVersion(), tokenValue);
    }

    public static CustomerVerifyEmailCommand of(final Versioned customer, final CustomerToken customerToken) {
        return of(customer, customerToken.getValue());
    }

    public String getId() {
        return id;
    }

    public Long getVersion() {
        return version;
    }

    public String getTokenValue() {
        return tokenValue;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy