Search in sources :

Example 1 with DeleteTokenParams

use of com.ingenico.connect.gateway.sdk.java.merchant.tokens.DeleteTokenParams in project connect-sdk-client-android by Ingenico-ePayments.

the class TokenUtil method createToken.

public String createToken(String merchantId, CreateTokenRequest body) throws CommunicationException {
    TokensClient tokensClient = client.merchant(merchantId).tokens();
    CreateTokenResponse response = tokensClient.create(body);
    if (response.getIsNewToken()) {
        return response.getToken();
    }
    String tokenId = response.getToken();
    tokensClient.delete(tokenId, new DeleteTokenParams());
    response = tokensClient.create(body);
    return response.getToken();
}
Also used : DeleteTokenParams(com.ingenico.connect.gateway.sdk.java.merchant.tokens.DeleteTokenParams) CreateTokenResponse(com.ingenico.connect.gateway.sdk.java.domain.token.CreateTokenResponse) TokensClient(com.ingenico.connect.gateway.sdk.java.merchant.tokens.TokensClient)

Example 2 with DeleteTokenParams

use of com.ingenico.connect.gateway.sdk.java.merchant.tokens.DeleteTokenParams in project connect-sdk-java by Ingenico-ePayments.

the class TokenTest method test.

/**
 * Smoke test for token calls.
 */
@Test
public void test() throws URISyntaxException, IOException {
    CreateTokenRequest createTokenRequest = new CreateTokenRequest();
    createTokenRequest.setPaymentProductId(1);
    TokenCard card = new TokenCard();
    createTokenRequest.setCard(card);
    CustomerToken customer = new CustomerToken();
    card.setCustomer(customer);
    Address billingAddress = new Address();
    customer.setBillingAddress(billingAddress);
    billingAddress.setCountryCode("NL");
    TokenCardData mandate = new TokenCardData();
    card.setData(mandate);
    CardWithoutCvv cardWithoutCvv = new CardWithoutCvv();
    mandate.setCardWithoutCvv(cardWithoutCvv);
    cardWithoutCvv.setCardholderName("Jan");
    cardWithoutCvv.setIssueNumber("12");
    cardWithoutCvv.setCardNumber("4567350000427977");
    cardWithoutCvv.setExpiryDate("0820");
    Client client = getClient();
    try {
        CreateTokenResponse createTokenResponse = client.merchant("9991").tokens().create(createTokenRequest);
        Assert.assertNotNull(createTokenResponse.getToken());
        DeleteTokenParams deleteTokenRequest = new DeleteTokenParams();
        client.merchant("9991").tokens().delete(createTokenResponse.getToken(), deleteTokenRequest);
    } finally {
        client.close();
    }
}
Also used : CreateTokenRequest(com.ingenico.connect.gateway.sdk.java.domain.token.CreateTokenRequest) TokenCard(com.ingenico.connect.gateway.sdk.java.domain.token.definitions.TokenCard) TokenCardData(com.ingenico.connect.gateway.sdk.java.domain.token.definitions.TokenCardData) CardWithoutCvv(com.ingenico.connect.gateway.sdk.java.domain.definitions.CardWithoutCvv) Address(com.ingenico.connect.gateway.sdk.java.domain.definitions.Address) CustomerToken(com.ingenico.connect.gateway.sdk.java.domain.token.definitions.CustomerToken) DeleteTokenParams(com.ingenico.connect.gateway.sdk.java.merchant.tokens.DeleteTokenParams) Client(com.ingenico.connect.gateway.sdk.java.Client) CreateTokenResponse(com.ingenico.connect.gateway.sdk.java.domain.token.CreateTokenResponse) Test(org.junit.Test)

Aggregations

CreateTokenResponse (com.ingenico.connect.gateway.sdk.java.domain.token.CreateTokenResponse)2 DeleteTokenParams (com.ingenico.connect.gateway.sdk.java.merchant.tokens.DeleteTokenParams)2 Client (com.ingenico.connect.gateway.sdk.java.Client)1 Address (com.ingenico.connect.gateway.sdk.java.domain.definitions.Address)1 CardWithoutCvv (com.ingenico.connect.gateway.sdk.java.domain.definitions.CardWithoutCvv)1 CreateTokenRequest (com.ingenico.connect.gateway.sdk.java.domain.token.CreateTokenRequest)1 CustomerToken (com.ingenico.connect.gateway.sdk.java.domain.token.definitions.CustomerToken)1 TokenCard (com.ingenico.connect.gateway.sdk.java.domain.token.definitions.TokenCard)1 TokenCardData (com.ingenico.connect.gateway.sdk.java.domain.token.definitions.TokenCardData)1 TokensClient (com.ingenico.connect.gateway.sdk.java.merchant.tokens.TokensClient)1 Test (org.junit.Test)1