use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItem in project connect-sdk-client-android by Ingenico-ePayments.
the class RenderIinCoBranding method addCoBrandToolTip.
private void addCoBrandToolTip(List<BasicPaymentItem> paymentProductsAllowedInContext, ViewGroup rowView, String fieldId, AssetManager logoManager, View.OnClickListener listener, Context context) {
// Create a new LinearLayout and add it under the rowView.
LinearLayout coBrandTooltipLayout = new LinearLayout(rowView.getContext());
coBrandTooltipLayout.setOrientation(LinearLayout.VERTICAL);
coBrandTooltipLayout.setBackgroundResource(R.drawable.special_section_background);
coBrandTooltipLayout.setTag(COBRAND_TOOLTIP_TAG_PREFIX + fieldId);
LinearLayout.LayoutParams coBrandTooltipLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
coBrandTooltipLayoutParams.setMargins(TOOLTIP_TEXT_MARGIN, TOOLTIP_TEXT_MARGIN, TOOLTIP_TEXT_MARGIN, TOOLTIP_TEXT_MARGIN);
// Create a new TextView and add it to the coBrandToolTipLayout
TextView tooltipTextView = new TextView(rowView.getContext());
tooltipTextView.setText(translate(INTRO_TEXT, context));
coBrandTooltipLayout.addView(tooltipTextView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
// Render the paymentproducts the user can choose from in the tooltip box
for (BasicPaymentItem basicPaymentItem : paymentProductsAllowedInContext) {
// Inflate the activity_select_payment_product_render layout
LayoutInflater inflater = (LayoutInflater) coBrandTooltipLayout.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View paymentProductLayout = inflater.inflate(R.layout.activity_render_cobrand_payment_product, coBrandTooltipLayout, false);
// Set a tag, so we can find it back after it has been clicked
paymentProductLayout.setTag(basicPaymentItem);
// Get the TextView and ImageView which will be filled
TextView paymentProductNameTextView = (TextView) paymentProductLayout.findViewById(R.id.coBrandPaymentProductName);
ImageView paymentProductNameLogoImageView = (ImageView) paymentProductLayout.findViewById(R.id.coBrandPaymentProductLogo);
// Set the translated value
Translator translator = Translator.getInstance(coBrandTooltipLayout.getContext());
paymentProductNameTextView.setText(translator.getPaymentProductName(basicPaymentItem.getId()));
// Get the logo for the product and set it as the background
BitmapDrawable drawable = (BitmapDrawable) logoManager.getLogo(basicPaymentItem.getId());
if (Build.VERSION.SDK_INT < 16) {
paymentProductNameLogoImageView.setBackgroundDrawable(drawable);
} else {
paymentProductNameLogoImageView.setBackground(drawable);
}
paymentProductLayout.setOnClickListener(listener);
coBrandTooltipLayout.addView(paymentProductLayout);
}
// Add the tooltip view to the ViewGroup
ViewGroup parentViewGroup = (ViewGroup) rowView.getParent();
parentViewGroup.addView(coBrandTooltipLayout, parentViewGroup.indexOfChild(rowView) + 1, coBrandTooltipLayoutParams);
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItem in project connect-sdk-client-android by Ingenico-ePayments.
the class GetBasicPaymentItemsAsyncTaskTest method validateProductsAndGroups.
/**
* Test that the first paymentProduct and the first paymentProductGroup in the returned list
* have the required fields and that there are both products and groups
*/
private void validateProductsAndGroups(BasicPaymentItems bpis) {
boolean productFound = false;
boolean groupFound = false;
for (BasicPaymentItem basicPaymentItem : bpis.getBasicPaymentItems()) {
if (!productFound && basicPaymentItem instanceof BasicPaymentProduct) {
validateBasicPaymentProduct((BasicPaymentProduct) basicPaymentItem);
productFound = true;
}
if (!groupFound && basicPaymentItem instanceof BasicPaymentProductGroup) {
validateBasicPaymentProductGroup((BasicPaymentProductGroup) basicPaymentItem);
groupFound = true;
}
if (productFound && groupFound) {
break;
}
}
// Check that there are both groups and products in the item list
assertTrue(groupFound && productFound);
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItem in project connect-sdk-client-android by Ingenico-ePayments.
the class GetBasicPaymentItemsAsyncTaskTest method validateOnlyProducts.
/**
* Validate that the first paymentProduct in the returned list
* has the required fields and that there are only products in the list
*/
private void validateOnlyProducts(BasicPaymentItems bpis) {
boolean productFound = false;
boolean groupFound = false;
for (BasicPaymentItem basicPaymentItem : bpis.getBasicPaymentItems()) {
if (!productFound && basicPaymentItem instanceof BasicPaymentProduct) {
validateBasicPaymentProduct((BasicPaymentProduct) basicPaymentItem);
productFound = true;
}
if (!groupFound && basicPaymentItem instanceof BasicPaymentProductGroup) {
groupFound = true;
}
if (productFound && groupFound) {
break;
}
}
// Check that there only products in the item list
assertTrue(!groupFound && productFound);
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItem in project connect-sdk-client-android by Ingenico-ePayments.
the class BasicPaymentItemsAsyncTask method createBasicPaymentItems.
private BasicPaymentItems createBasicPaymentItems(BasicPaymentProducts basicPaymentProducts, BasicPaymentProductGroups basicPaymentProductGroups) {
// Validate the results of the calls
if (basicPaymentProducts == null && basicPaymentProductGroups == null) {
// If both basicPaymentProducts and basicPaymentProductGroups are null, return nul
return null;
} else if (basicPaymentProductGroups == null) {
// If basicPaymentProductGroups == null, return just the basicPaymentProducts
return new BasicPaymentItems(basicPaymentProducts.getPaymentProductsAsItems(), basicPaymentProducts.getAccountsOnFile());
} else if (basicPaymentProducts == null) {
// If basicPaymentProducts == null, return just the basicPaymentProductGroups
return new BasicPaymentItems(basicPaymentProductGroups.getPaymentProductGroupsAsItems(), basicPaymentProductGroups.getAccountsOnFile());
}
// Else: Merge the paymentItems together.
// Create a list of PaymentProductSelectables that will be filled and stored in the basicPaymentItems object that is returned
List<BasicPaymentItem> basicPaymentItems = new ArrayList<>();
// Create a list of AccountOnFiles that will be filled and stored in the basicPaymentItems object that is returned
List<AccountOnFile> accountsOnFile = new LinkedList<>();
// list of basicPaymentItems that will be returned.
for (BasicPaymentProduct paymentProduct : basicPaymentProducts.getBasicPaymentProducts()) {
// Add the accountsOnFile of the current paymentProduct to the collection of accountOnFiles.
accountsOnFile.addAll(paymentProduct.getAccountsOnFile());
// becomes true if the paymentProduct has been matched with a group.
boolean groupMatch = false;
for (BasicPaymentProductGroup paymentProductGroup : basicPaymentProductGroups.getBasicPaymentProductGroups()) {
// Does the current paymentProduct belong to the current paymentProductGroup
if (paymentProduct.getPaymentProductGroup() != null && paymentProduct.getPaymentProductGroup().equals(paymentProductGroup.getId())) {
// Add the paymentProductGroup to the basicPaymentItems that will be returned if it is not already in the list
if (!basicPaymentItems.contains(paymentProductGroup)) {
// Set the displayOrder of the group to the displayOrder of the first paymentProduct match
paymentProductGroup.getDisplayHints().setDisplayOrder(paymentProduct.getDisplayHints().getDisplayOrder());
basicPaymentItems.add(paymentProductGroup);
}
// Product has been matched to a group
groupMatch = true;
// Products can not match with more then one group
break;
}
}
if (!groupMatch) {
// If the paymentProduct does not belong to a paymentProductGroup, add the paymentProduct to the
// basicPaymentItems that will be returned
basicPaymentItems.add(paymentProduct);
}
}
// Return a new BasicPaymentItems object that contains the paymentItems and the accountsOnFile
return new BasicPaymentItems(basicPaymentItems, accountsOnFile);
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItem in project connect-sdk-client-android by Ingenico-ePayments.
the class AssetManager method updateLogos.
/**
* Update the logos for the given paymentProducts if there is a new version
*
* @param region, region determines what baseurl is used for loading images
* @param environment, environment determines what baseurl is used for loading images
* @param basicPaymentItems, PaymentProductSelectables for which the logo will be updated if there is a new version
*/
public void updateLogos(Region region, EnvironmentType environment, List<BasicPaymentItem> basicPaymentItems, Size size) {
// Get the map containg all logos per paymentProductId from the preferences
Type listType = new TypeToken<Map<String, String>>() {
}.getType();
Map<String, String> logoMapping = preferences.getMapFromSharedPreferences(Constants.PREFERENCES_LOGO_MAP, context, listType, new HashMap<String, String>());
// Store that mapping in the user preferences so it will be cached there.
if (logoMapping == null) {
logoMapping = readInitialLogoMapping();
}
if (logoMapping != null && basicPaymentItems != null) {
// Loop trough all BasicPaymentProducts to see if their logo must be updated
for (BasicPaymentItem product : basicPaymentItems) {
String url = logoMapping.get(product.getId());
// Check if the logo url is different for the paymentproduct
if (url == null || !url.equals(product.getDisplayHints().getLogoUrl())) {
// Update the image
getImageFromUrl(region, environment, logoMapping, product, size);
}
}
}
}
Aggregations