use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct in project connect-sdk-client-android by Ingenico-ePayments.
the class GetPaymentProductAsyncTaskTest method testGetPaymentProductAsyncTaskWithValidRequest.
/**
* Tests that a PaymentProduct can successfully be retrieved and has the minimal fields
* Also tests that the input fields are there.
*/
@Test
public void testGetPaymentProductAsyncTaskWithValidRequest() throws InterruptedException, CommunicationException {
initializeValidMocksAndSession();
final CountDownLatch waitForAsyncTaskCallBack = new CountDownLatch(1);
// Create the PaymentProductsAsyncTask and then begin the test by calling execute.
List<PaymentProductAsyncTask.OnPaymentProductCallCompleteListener> listeners = new ArrayList<>(1);
Listener listener = new Listener(waitForAsyncTaskCallBack);
listeners.add(listener);
PaymentProductAsyncTask paymentProductAsyncTask = new PaymentProductAsyncTask(getContext(), "1", minimalValidPaymentContext, getCommunicator(), listeners);
paymentProductAsyncTask.execute();
// Test that the response is received within 'ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC' seconds
assertTrue(waitForAsyncTaskCallBack.await(ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC, TimeUnit.SECONDS));
// Retrieve the paymentProduct from the listener and validate that it has the correct fields
PaymentProduct paymentProduct = listener.getPaymentProduct();
validatePaymentProduct(paymentProduct);
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct in project connect-sdk-client-android by Ingenico-ePayments.
the class GetPaymentProductAsyncTaskTest method testGetPaymentProductAsyncTaskWithValidRequestAndAccountOnFile.
/**
* Tests that a PaymentProduct can successfully be retrieved and has the minimal fields
* Also tests that the input fields are there.
*/
@Test
public void testGetPaymentProductAsyncTaskWithValidRequestAndAccountOnFile() throws InterruptedException, CommunicationException {
try {
initializeValidMocksAndSessionWithToken();
final CountDownLatch waitForAsyncTaskCallBack = new CountDownLatch(1);
// Create the PaymentProductsAsyncTask and then begin the test by calling execute.
List<PaymentProductAsyncTask.OnPaymentProductCallCompleteListener> listeners = new ArrayList<>(1);
Listener listener = new Listener(waitForAsyncTaskCallBack);
listeners.add(listener);
PaymentProductAsyncTask paymentProductAsyncTask = new PaymentProductAsyncTask(getContext(), "1", minimalValidPaymentContext, getCommunicator(), listeners);
paymentProductAsyncTask.execute();
// Test that the response is received within 'ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC' seconds
assertTrue(waitForAsyncTaskCallBack.await(ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC, TimeUnit.SECONDS));
// Retrieve the paymentProduct from the listener and validate that it has the correct fields
PaymentProduct paymentProduct = listener.getPaymentProduct();
validatePaymentProduct(paymentProduct);
validateAccountOnFile(paymentProduct);
} finally {
deleteToken();
}
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct in project connect-sdk-client-android by Ingenico-ePayments.
the class GcSession method getPaymentProduct.
/**
* Gets PaymentProduct with fields from the GC gateway
*
* @param context, used for reading device metada which is send to the GC gateway
* @param productId, the productId of the product which needs to be retrieved from the GC gateway
* @param paymentContext, PaymentContext which contains all neccesary data for doing call to the GC gateway to retrieve BasicPaymentProducts
* @param listener, listener which will be called by the AsyncTask when the PaymentProduct with fields is retrieved
*/
public void getPaymentProduct(Context context, String productId, PaymentContext paymentContext, OnPaymentProductCallCompleteListener listener) {
if (context == null) {
throw new InvalidParameterException("Error getting paymentproduct, context may not be null");
}
if (productId == null) {
throw new InvalidParameterException("Error getting paymentproduct, groupId may not be null");
}
if (paymentContext == null) {
throw new InvalidParameterException(("Error getting paymentproduct, paymentContext may not be null"));
}
if (listener == null) {
throw new InvalidParameterException("Error getting paymentproduct, listener may not be null");
}
this.paymentContext = paymentContext;
// Create the cache key for this paymentProduct
PaymentItemCacheKey key = createPaymentItemCacheKey(paymentContext, productId);
// If the paymentProduct is already in the cache, call the listener with that paymentproduct
if (paymentItemMapping.containsKey(key)) {
PaymentProduct cachedPP = (PaymentProduct) paymentItemMapping.get(key);
listener.onPaymentProductCallComplete(cachedPP);
} else {
// Add OnPaymentProductsCallComplete listener and this class to list of listeners so we can store the paymentproduct here
List<OnPaymentProductCallCompleteListener> listeners = new ArrayList<OnPaymentProductCallCompleteListener>();
listeners.add(this);
listeners.add(listener);
// Do the call to the GC gateway
PaymentProductAsyncTask task = new PaymentProductAsyncTask(context, productId, paymentContext, communicator, listeners);
task.execute();
}
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct in project connect-sdk-client-android by Ingenico-ePayments.
the class PaymentProductSelectionActivity method determineAndStartDetailInputActivity.
private void determineAndStartDetailInputActivity(PaymentItem paymentItem) {
// Determine what DetailInputActivity to load. The base-class just renders the fields and
// performs default validation on the fields. In some cases this is not enough however. In
// these cases a subclass of the DetailInputActivity will be loaded that has additional
// functionality for these specific products/methods.
Intent detailInputActivityIntent = null;
if (paymentItem instanceof PaymentProductGroup && PAYMENTPRODUCTGROUPID_CARDS.equals(paymentItem.getId()) || ((PaymentProduct) paymentItem).getPaymentMethod().equals("card")) {
detailInputActivityIntent = new Intent(this, DetailInputActivityCreditCards.class);
} else if (PAYMENTPRODUCTID_BOLETOBANCARIO.equals(paymentItem.getId())) {
detailInputActivityIntent = new Intent(this, DetailInputActivityBoletoBancario.class);
} else if (PAYMENTPRODUCTID_AFTERPAY_INSTALLMENTS.equals(paymentItem.getId()) || PAYMENTPRODUCTID_AFTERPAY_INVOICE.equals(paymentItem.getId())) {
detailInputActivityIntent = new Intent(this, DetailInputActivityAfterpay.class);
} else {
detailInputActivityIntent = new Intent(this, DetailInputActivity.class);
}
detailInputActivityIntent.putExtra(Constants.INTENT_SELECTED_ITEM, paymentItem);
startNextActivity(detailInputActivityIntent);
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct in project connect-sdk-client-android by Ingenico-ePayments.
the class PaymentProductSelectionActivity method retrievePaymentProductFieldsBcmc.
private void retrievePaymentProductFieldsBcmc(PaymentItem bcmc) {
if (PAYMENTPRODUCTID_BanContact.equals(bcmc.getId())) {
// Because the BanContact payment product (BCMC, PPid 3012) has, apart from regular
// credit card inputFields, other ways for the customer to complete the transaction, it
// is required that a payment is created first, before rendering the Input Fields. A create
// payment call cannot be made via this Client 2 Server API, but should be made from your
// payment server instead. You should add code here that triggers that payment and then
// have the result sent back to the Client.
// Since this is an example application, we will simply pretend that the call has been
// made and load an example JSON response from the resources. This resource is not the
// full createPaymentResponse, but only the MerchantAction, which contains the fields and
// showdata required to render the qrCode/button for BCMC.
Reader reader = new InputStreamReader(getResources().openRawResource(R.raw.bcmc_merchantaction_example));
MerchantAction bcmcMerchantActionExample = new Gson().fromJson(reader, MerchantAction.class);
// Add the payment product fields from the merchantAction to the payment item, so that the
// DetailInputActivity can render them as usual.
((PaymentProduct) bcmc).setPaymentProductFields(bcmcMerchantActionExample.getFormFields());
Intent bcmcDetailInputActivityIntent = new Intent(this, DetailInputActivityBCMC.class);
bcmcDetailInputActivityIntent.putExtra(Constants.INTENT_SELECTED_ITEM, bcmc);
bcmcDetailInputActivityIntent.putExtra(Constants.INTENT_BCMC_SHOWDATA, ((Serializable) bcmcMerchantActionExample.getShowData()));
startNextActivity(bcmcDetailInputActivityIntent);
} else {
throw new InvalidParameterException("Can not retrieve fields for BCMC, payment item is not BCMC");
}
}
Aggregations