Search in sources :

Example 1 with ShoppingCartItem

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

the class HeaderViewImpl method renderOrderDetails.

private void renderOrderDetails(ShoppingCart cart, PaymentContext paymentContext) {
    Context context = rootView.getContext();
    // Get the shoppingcartview
    LinearLayout totalCostDetailsLayout = (LinearLayout) rootView.findViewById(R.id.totalCostDetailsLayout);
    // Add all shoppingcartitems to the totalCostDetailsLayout
    // Set layout params
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    LinearLayout.LayoutParams descriptionParams = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 4f);
    LinearLayout.LayoutParams quantityParams = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f);
    LinearLayout.LayoutParams costParams = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 3f);
    for (ShoppingCartItem item : cart.getShoppingCartItems()) {
        // Add the relative layout which contains the texts
        LinearLayout layout = new LinearLayout(context);
        layout.setLayoutParams(params);
        // Show the description
        TextView label = new TextView(context);
        label.setText(item.getDescription());
        label.setTextAppearance(context, R.style.TotalCostLayoutSmallText);
        label.setGravity(Gravity.LEFT);
        layout.addView(label, descriptionParams);
        // Show the quantity
        TextView quantity = new TextView(context);
        quantity.setText("" + item.getQuantity());
        quantity.setTextAppearance(context, R.style.TotalCostLayoutSmallText);
        quantity.setGravity(Gravity.LEFT);
        layout.addView(quantity, quantityParams);
        // Show the amount formatted
        TextView cost = new TextView(context);
        cost.setText(CurrencyUtil.formatAmount(item.getAmountInCents(), paymentContext.getCountryCode(), paymentContext.getAmountOfMoney().getCurrencyCode()));
        cost.setTextAppearance(context, R.style.TotalCostLayoutSmallText);
        cost.setGravity(Gravity.RIGHT);
        layout.addView(cost, costParams);
        totalCostDetailsLayout.addView(layout, 1, params);
    }
}
Also used : Context(android.content.Context) PaymentContext(com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentContext) ShoppingCartItem(com.globalcollect.gateway.sdk.client.android.exampleapp.model.ShoppingCartItem) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 2 with ShoppingCartItem

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

the class StartPageActivity method payButtonPressed.

public void payButtonPressed(View view) {
    // SETUP THE PAYMENT:
    // Get text from clientSessionIdentifierEditText
    String clientSessionIdentifier = ((EditText) findViewById(R.id.client_session_identifier)).getText().toString();
    // Null check
    if (clientSessionIdentifier == null) {
        return;
    }
    if (clientSessionIdentifier.isEmpty()) {
        return;
    }
    // Get text from customerIdentifierEditText
    String customerId = ((EditText) findViewById(R.id.customer_identifier)).getText().toString();
    // Null check
    if (customerId == null) {
        return;
    }
    if (customerId.isEmpty()) {
        return;
    }
    // Get text from spinnerRegion
    String region = ((Spinner) findViewById(R.id.region)).getSelectedItem().toString();
    // Null check
    if (region == null) {
        return;
    }
    // Get text from spinnerEnvironment
    String environment = ((Spinner) findViewById(R.id.environment)).getSelectedItem().toString();
    // Null check
    if (environment == null) {
        return;
    }
    // Get text from amount in cents edittext
    String amount = ((EditText) findViewById(R.id.amount)).getText().toString();
    // Null check
    if (amount == null) {
        return;
    }
    if (amount.isEmpty()) {
        return;
    }
    String countryCodeString = ((Spinner) findViewById(R.id.country_code)).getSelectedItem().toString();
    // Null check
    if (countryCodeString == null) {
        return;
    }
    if (countryCodeString.isEmpty()) {
        return;
    }
    // Get text from spinnerCurrency
    String currencyCodeString = ((Spinner) findViewById(R.id.currency_code)).getSelectedItem().toString();
    // Null check
    if (currencyCodeString == null) {
        return;
    }
    if (currencyCodeString.isEmpty()) {
        return;
    }
    // Get boolean from checkBox
    boolean isRecurring = ((CheckBox) findViewById(R.id.payment_is_recurring)).isChecked();
    // Get boolean from checkBox
    boolean groupPaymentProducts = ((CheckBox) findViewById(R.id.group_paymentproducts)).isChecked();
    // Country code
    CountryCode countryCode = null;
    List<CountryCode> listOfCountryCodes = new ArrayList<CountryCode>(EnumSet.allOf(CountryCode.class));
    // Convert locale to country code, since global collect doesn't support all countries!
    for (CountryCode code : listOfCountryCodes) {
        if (code.name().equals(countryCodeString)) {
            countryCode = code;
            break;
        }
    }
    if (countryCode == null) {
        return;
    }
    // Country code can also be determined from the location of the android device by:
    // Locale locale = Locale.getDefault();
    // String country = locale.getCountry();
    // Currency code
    CurrencyCode currencyCode = null;
    List<CurrencyCode> listOfCurrencyCodes = new ArrayList<CurrencyCode>(EnumSet.allOf(CurrencyCode.class));
    for (CurrencyCode code : listOfCurrencyCodes) {
        if (code.name().equals(currencyCodeString)) {
            currencyCode = code;
        }
    }
    if (currencyCode == null) {
        return;
    }
    ShoppingCart cart = new ShoppingCart();
    cart.addItemToShoppingCart(new ShoppingCartItem("Something", Long.parseLong(amount), 1));
    // Create the PaymentContext object
    AmountOfMoney amountOfMoney = new AmountOfMoney(cart.getTotalAmount(), currencyCode);
    PaymentContext paymentContext = new PaymentContext(amountOfMoney, countryCode, isRecurring);
    // and show the PaymentProductSelectionActivity
    Intent paymentIntent = new Intent(this, PaymentProductSelectionActivity.class);
    // Attach the following objects to the paymentIntent
    paymentIntent.putExtra(Constants.INTENT_PAYMENT_CONTEXT, paymentContext);
    paymentIntent.putExtra(Constants.INTENT_SHOPPINGCART, cart);
    paymentIntent.putExtra(Constants.MERCHANT_CLIENT_SESSION_IDENTIFIER, clientSessionIdentifier);
    paymentIntent.putExtra(Constants.MERCHANT_CUSTOMER_IDENTIFIER, customerId);
    paymentIntent.putExtra(Constants.MERCHANT_REGION, region);
    paymentIntent.putExtra(Constants.MERCHANT_ENVIRONMENT, environment);
    paymentIntent.putExtra(Constants.INTENT_GROUP_PAYMENTPRODUCTS, groupPaymentProducts);
    // Start paymentIntent
    startActivity(paymentIntent);
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) PaymentContext(com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentContext) AmountOfMoney(com.globalcollect.gateway.sdk.client.android.sdk.model.AmountOfMoney) CurrencyCode(com.globalcollect.gateway.sdk.client.android.sdk.model.CurrencyCode) ShoppingCart(com.globalcollect.gateway.sdk.client.android.exampleapp.model.ShoppingCart) CheckBox(android.widget.CheckBox) ShoppingCartItem(com.globalcollect.gateway.sdk.client.android.exampleapp.model.ShoppingCartItem) CountryCode(com.globalcollect.gateway.sdk.client.android.sdk.model.CountryCode)

Aggregations

ShoppingCartItem (com.globalcollect.gateway.sdk.client.android.exampleapp.model.ShoppingCartItem)2 PaymentContext (com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentContext)2 Context (android.content.Context)1 Intent (android.content.Intent)1 CheckBox (android.widget.CheckBox)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 ShoppingCart (com.globalcollect.gateway.sdk.client.android.exampleapp.model.ShoppingCart)1 AmountOfMoney (com.globalcollect.gateway.sdk.client.android.sdk.model.AmountOfMoney)1 CountryCode (com.globalcollect.gateway.sdk.client.android.sdk.model.CountryCode)1 CurrencyCode (com.globalcollect.gateway.sdk.client.android.sdk.model.CurrencyCode)1 ArrayList (java.util.ArrayList)1