Search in sources :

Example 1 with Encryptor

use of com.globalcollect.gateway.sdk.client.android.sdk.encryption.Encryptor in project connect-sdk-client-android by Ingenico-ePayments.

the class EncryptDataAsyncTask method doInBackground.

@Override
protected String doInBackground(String... params) {
    EncryptData encryptData = new EncryptData();
    // Format all values based on their paymentproductfield.type and them to the encryptedValues
    Map<String, String> formattedPaymentValues = new HashMap<String, String>();
    for (PaymentProductField field : paymentRequest.getPaymentProduct().getPaymentProductFields()) {
        String value = paymentRequest.getValue(field.getId());
        // If the masks given by the GC gateway are correct
        if (field.getType() != null && value != null) {
            if (field.getType().equals(Type.NUMERICSTRING)) {
                formattedPaymentValues.put(field.getId(), value.replaceAll("[^\\d.]", ""));
            } else {
                formattedPaymentValues.put(field.getId(), value);
            }
        }
    }
    encryptData.setPaymentValues(formattedPaymentValues);
    // Add the clientSessionId
    encryptData.setClientSessionId(clientSessionId);
    // Add UUID nonce
    encryptData.setNonce(UUID.randomUUID().toString());
    // Add paymentproductId and accountOnFileId to the encryptData
    if (paymentRequest.getAccountOnFile() != null) {
        encryptData.setAccountOnFileId(paymentRequest.getAccountOnFile().getId());
    }
    encryptData.setPaymentProductId(Integer.parseInt(paymentRequest.getPaymentProduct().getId()));
    // See if the payment must be remembered
    if (paymentRequest.getTokenize()) {
        encryptData.setTokenize(true);
    }
    // Encrypt all the fields in the paymentproduct
    Encryptor encryptor = new Encryptor(publicKeyResponse);
    return encryptor.encrypt(encryptData);
}
Also used : HashMap(java.util.HashMap) PaymentProductField(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductField) Encryptor(com.globalcollect.gateway.sdk.client.android.sdk.encryption.Encryptor) EncryptData(com.globalcollect.gateway.sdk.client.android.sdk.encryption.EncryptData)

Aggregations

EncryptData (com.globalcollect.gateway.sdk.client.android.sdk.encryption.EncryptData)1 Encryptor (com.globalcollect.gateway.sdk.client.android.sdk.encryption.Encryptor)1 PaymentProductField (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductField)1 HashMap (java.util.HashMap)1