Search in sources :

Example 1 with BasicPaymentProduct

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct 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);
}
Also used : BasicPaymentProductGroup(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup) BasicPaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct) BasicPaymentItem(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItem)

Example 2 with BasicPaymentProduct

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct 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);
}
Also used : BasicPaymentProductGroup(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup) BasicPaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct) BasicPaymentItem(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItem)

Example 3 with BasicPaymentProduct

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct 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);
}
Also used : BasicPaymentItems(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItems) AccountOnFile(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFile) BasicPaymentProductGroup(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup) ArrayList(java.util.ArrayList) BasicPaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct) LinkedList(java.util.LinkedList) BasicPaymentItem(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItem)

Example 4 with BasicPaymentProduct

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct in project connect-sdk-client-android by Ingenico-ePayments.

the class RenderPaymentItem method renderPaymentItem.

@SuppressWarnings("deprecation")
@Override
public void renderPaymentItem(BasicPaymentItem product, ViewGroup parent) {
    if (product == null) {
        throw new InvalidParameterException("Error renderingPaymentProduct, product may not be null");
    }
    if (parent == null) {
        throw new InvalidParameterException("Error renderingPaymentProduct, parent may not be null");
    }
    // Inflate the activity_select_payment_product_render layout
    LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View paymentProductLayout = inflater.inflate(R.layout.activity_render_payment_product, parent, false);
    // Set the belonging accountOnFile on the tag of the row so we can retrieve it when clicked
    paymentProductLayout.findViewById(R.id.paymentProductRow).setTag(product);
    // Get the TextView and ImageView which will be filled
    TextView paymentProductNameTextView = (TextView) paymentProductLayout.findViewById(R.id.paymentProductName);
    ImageView paymentProductNameLogoImageView = (ImageView) paymentProductLayout.findViewById(R.id.paymentProductLogo);
    // Set the translated value
    Translator translator = Translator.getInstance(parent.getContext());
    String translatedValue = (product instanceof BasicPaymentProduct) ? translator.getPaymentProductName(product.getId()) : translator.getPaymentProductGroupName(product.getId());
    paymentProductNameTextView.setText(translatedValue);
    if (Build.VERSION.SDK_INT < 16) {
        paymentProductNameLogoImageView.setBackgroundDrawable(product.getDisplayHints().getLogo());
    } else {
        paymentProductNameLogoImageView.setBackground(product.getDisplayHints().getLogo());
    }
    parent.addView(paymentProductLayout);
}
Also used : InvalidParameterException(java.security.InvalidParameterException) Translator(com.globalcollect.gateway.sdk.client.android.exampleapp.translation.Translator) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) BasicPaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View)

Example 5 with BasicPaymentProduct

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct 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("&currencyCode=").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());
        }
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) Scanner(java.util.Scanner) HttpURLConnection(java.net.HttpURLConnection) AssetManager(com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager) CommunicationException(com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException) Drawable(android.graphics.drawable.Drawable) BasicPaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct) IOException(java.io.IOException) CommunicationException(com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException) InvalidParameterException(java.security.InvalidParameterException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BasicPaymentProducts(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts)

Aggregations

BasicPaymentProduct (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct)5 BasicPaymentItem (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItem)3 BasicPaymentProductGroup (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup)3 InvalidParameterException (java.security.InvalidParameterException)2 Drawable (android.graphics.drawable.Drawable)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Translator (com.globalcollect.gateway.sdk.client.android.exampleapp.translation.Translator)1 CommunicationException (com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException)1 AssetManager (com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager)1 AccountOnFile (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFile)1 BasicPaymentItems (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItems)1 BasicPaymentProducts (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts)1 IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1