use of com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException in project connect-sdk-client-android by Ingenico-ePayments.
the class C2sCommunicator method getPaymentProductGroup.
/**
* Retrieves a single paymentProductGroup from the GC gateway including all its fields
*
* @param groupId, used to retrieve the BasicPaymentProductGroup that is associated with this id
* @param context, used for reading device metada which is send to the GC gateway
* @param paymentContext, PaymentContext which contains all neccesary data to retrieve a paymentProductGroup
*
* @return PaymentProduct, or null when an error has occured
*/
public PaymentProductGroup getPaymentProductGroup(String groupId, Context context, PaymentContext paymentContext) {
if (groupId == null) {
throw new InvalidParameterException("Error getting paymentProductGroup, groupId may not be null");
}
HttpURLConnection connection = null;
try {
// Build the complete url which is called
String baseUrl = configuration.getBaseUrl();
String paymentProductPath = Constants.GC_GATEWAY_RETRIEVE_PAYMENTPRODUCTGROUP_PATH.replace("[cid]", configuration.getCustomerId()).replace("[gid]", groupId);
String completePath = baseUrl + paymentProductPath;
// Add query parameters
StringBuilder queryString = new StringBuilder();
queryString.append("?countryCode=").append(paymentContext.getCountryCode());
queryString.append("&amount=").append(paymentContext.getAmountOfMoney().getAmount());
queryString.append("&isRecurring=").append(paymentContext.isRecurring());
queryString.append("¤cyCode=").append(paymentContext.getAmountOfMoney().getCurrencyCode());
queryString.append("&").append(createCacheBusterParameter());
completePath += queryString.toString();
// Do the call and deserialise the result to PaymentProduct
connection = doHTTPGetRequest(completePath, configuration.getClientSessionId(), configuration.getMetadata(context));
String responseBody = new Scanner(connection.getInputStream(), "UTF-8").useDelimiter("\\A").next();
// Log the response
if (Constants.ENABLE_REQUEST_LOGGING) {
logResponse(connection, responseBody);
}
return gson.fromJson(responseBody, PaymentProductGroup.class);
} catch (CommunicationException e) {
Log.i(TAG, "Error while getting paymentProductGroup:" + e.getMessage());
return null;
} catch (Exception e) {
Log.i(TAG, "Error while getting paymentProductGroup:" + e.getMessage());
return null;
} finally {
try {
if (connection != null) {
connection.getInputStream().close();
connection.disconnect();
}
} catch (IOException e) {
Log.i(TAG, "Error while getting paymentProductGroup: " + e.getMessage());
}
}
}
use of com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException in project connect-sdk-client-android by Ingenico-ePayments.
the class GcSessionPreparePaymentRequestTest method testGetPreparedPaymentRequestWithAccountOnFileAndValidRequest.
@Test
public void testGetPreparedPaymentRequestWithAccountOnFileAndValidRequest() throws InterruptedException {
try {
initializeValidGcSessionMocksAndSessionWithToken();
CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
PaymentRequest paymentRequest = constructValidPaymentRequest(true, false);
Listener listener = new Listener(waitForAsyncCallBack);
getSession().preparePaymentRequest(paymentRequest, getContext(), listener);
// Test that the request is prepared within 'PREPAREPAYMENTREQUEST_CALLBACK_TEST_TIMEOUT_SEC' seconds
assertTrue(waitForAsyncCallBack.await(PREPAREPAYMENTREQUEST_CALLBACK_TEST_TIMEOUT_SEC, TimeUnit.SECONDS));
PreparedPaymentRequest preparedPaymentRequest = listener.getPreparedPaymentRequest();
// Test that the encrypted blob that will be used for the payment has been created successfully
validateValidPreparedPaymentRequest(preparedPaymentRequest);
} catch (CommunicationException e) {
e.printStackTrace();
} finally {
deleteToken();
}
}
use of com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException in project connect-sdk-client-android by Ingenico-ePayments.
the class BaseAsyncTaskTest method initializeValidMocksAndSessionWithToken.
/**
* Create a mocked configuration that produces valid requests and contains an AccountOnFile
*/
void initializeValidMocksAndSessionWithToken() throws CommunicationException {
CreateTokenRequest body = GsonHelper.fromResourceJson("getTokenJSONCard.json", CreateTokenRequest.class);
try {
token = tokenUtil.createToken(testMerchantId, body);
} catch (ApiException e) {
throw new CommunicationException("ApiException while creating token. Token is: " + token, e);
}
initializeValidMocksAndSession();
}
use of com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException in project connect-sdk-client-android by Ingenico-ePayments.
the class BaseAsyncTaskTest method initializeValidMocksAndSession.
/**
* Creates a mocked configuration that produces valid requests
*/
void initializeValidMocksAndSession() throws CommunicationException {
SessionRequest request = new SessionRequest();
if (token != null) {
request.setTokens(Collections.singletonList(token));
}
try {
SessionResponse response = sessionUtil.createSession(testMerchantId, request);
initializeValidMocks(response);
} catch (ApiException e) {
throw new CommunicationException("ApiException while creating session", e);
}
}
use of com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException in project connect-sdk-client-android by Ingenico-ePayments.
the class C2sCommunicator method getBasicPaymentProducts.
/**
* Retrieves a list of basicpaymentproducts from the GC gateway without any fields
*
* @param context, used for reading device metadata which is send to the GC gateway
* @param paymentContext, payment information that is used to retrieve the correct payment products
*
* @return list of BasicPaymentProducts, or null when an error has occured
*/
public BasicPaymentProducts getBasicPaymentProducts(PaymentContext paymentContext, Context context) {
if (paymentContext == null) {
throw new InvalidParameterException("Error getting BasicPaymentProducts, request may not be null");
}
HttpURLConnection connection = null;
try {
// Build the complete url which is called
String baseUrl = configuration.getBaseUrl();
String paymentProductPath = Constants.GC_GATEWAY_RETRIEVE_PAYMENTPRODUCTS_PATH.replace("[cid]", configuration.getCustomerId());
String completePath = baseUrl + paymentProductPath;
// Add query parameters
StringBuilder queryString = new StringBuilder();
queryString.append("?countryCode=").append(paymentContext.getCountryCode());
queryString.append("&amount=").append(paymentContext.getAmountOfMoney().getAmount());
queryString.append("&isRecurring=").append(paymentContext.isRecurring());
queryString.append("¤cyCode=").append(paymentContext.getAmountOfMoney().getCurrencyCode());
queryString.append("&hide=fields");
queryString.append("&").append(createCacheBusterParameter());
// Add query string to complete path
completePath += queryString.toString();
// Do the call and deserialise the result to BasicPaymentProducts
connection = doHTTPGetRequest(completePath, configuration.getClientSessionId(), configuration.getMetadata(context));
String responseBody = new Scanner(connection.getInputStream(), "UTF-8").useDelimiter("\\A").next();
// Log the response
if (Constants.ENABLE_REQUEST_LOGGING) {
logResponse(connection, responseBody);
}
BasicPaymentProducts basicPaymentProducts = gson.fromJson(responseBody, BasicPaymentProducts.class);
// Set the logos for all paymentproducts
for (BasicPaymentProduct paymentProduct : basicPaymentProducts.getBasicPaymentProducts()) {
AssetManager manager = AssetManager.getInstance(context);
Drawable logo = manager.getLogo(paymentProduct.getId());
paymentProduct.getDisplayHints().setLogo(logo);
}
return basicPaymentProducts;
} catch (CommunicationException e) {
Log.i(TAG, "Error while getting paymentproducts:" + e.getMessage());
return null;
} catch (Exception e) {
Log.i(TAG, "Error while getting paymentproducts:" + e.getMessage());
return null;
} finally {
try {
if (connection != null) {
connection.getInputStream().close();
connection.disconnect();
}
} catch (IOException e) {
Log.i(TAG, "Error while getting paymentproducts:" + e.getMessage());
}
}
}
Aggregations