Search in sources :

Example 1 with ShoppingCart

use of com.globalcollect.gateway.sdk.client.android.exampleapp.model.ShoppingCart 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

Intent (android.content.Intent)1 CheckBox (android.widget.CheckBox)1 ShoppingCart (com.globalcollect.gateway.sdk.client.android.exampleapp.model.ShoppingCart)1 ShoppingCartItem (com.globalcollect.gateway.sdk.client.android.exampleapp.model.ShoppingCartItem)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 PaymentContext (com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentContext)1 ArrayList (java.util.ArrayList)1