Search in sources :

Example 1 with CountryCode

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

Example 2 with CountryCode

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

the class StartPageActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_startpage);
    // Get all values for Region spinner
    List<Region> spinnerArrayRegion = new ArrayList<Region>(EnumSet.allOf(Region.class));
    // Make adapters of list and put it inside spinner
    ArrayAdapter<Region> adapterRegion = new ArrayAdapter<Region>(this, android.R.layout.simple_spinner_item, spinnerArrayRegion);
    adapterRegion.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    Spinner spinnerRegion = (Spinner) findViewById(R.id.region);
    spinnerRegion.setAdapter(adapterRegion);
    // Get all values for Environment spinner
    List<EnvironmentType> spinnerArrayEnvironment = new ArrayList<EnvironmentType>(EnumSet.allOf(EnvironmentType.class));
    // Make adapters of list and put it inside spinner
    ArrayAdapter<EnvironmentType> adapterEnvironment = new ArrayAdapter<EnvironmentType>(this, android.R.layout.simple_spinner_item, spinnerArrayEnvironment);
    // adapterRegion.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    Spinner spinnerEnvironment = (Spinner) findViewById(R.id.environment);
    spinnerEnvironment.setAdapter(adapterEnvironment);
    // Get all values for CountryCode spinner
    List<CountryCode> spinnerArrayCountry = new ArrayList<CountryCode>(EnumSet.allOf(CountryCode.class));
    Collections.sort(spinnerArrayCountry);
    // Make adapters of list and put it inside spinner
    ArrayAdapter<CountryCode> adapterCountry = new ArrayAdapter<CountryCode>(this, android.R.layout.simple_spinner_item, spinnerArrayCountry);
    adapterCountry.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    Spinner spinnerCountry = (Spinner) findViewById(R.id.country_code);
    spinnerCountry.setAdapter(adapterCountry);
    spinnerCountry.setSelection(adapterCountry.getPosition(CountryCode.US));
    // Get all values for CurrencyCode spinner
    List<CurrencyCode> spinnerArrayCurrency = new ArrayList<CurrencyCode>(EnumSet.allOf(CurrencyCode.class));
    Collections.sort(spinnerArrayCurrency);
    // Make adapters of list and put it inside spinner
    ArrayAdapter<CurrencyCode> adapterCurrency = new ArrayAdapter<CurrencyCode>(this, android.R.layout.simple_spinner_item, spinnerArrayCurrency);
    adapterCurrency.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    Spinner spinnerCurrency = (Spinner) findViewById(R.id.currency_code);
    spinnerCurrency.setAdapter(adapterCurrency);
    spinnerCurrency.setSelection(adapterCurrency.getPosition(CurrencyCode.EUR));
}
Also used : Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) CurrencyCode(com.globalcollect.gateway.sdk.client.android.sdk.model.CurrencyCode) EnvironmentType(com.globalcollect.gateway.sdk.client.android.sdk.model.Environment.EnvironmentType) Region(com.globalcollect.gateway.sdk.client.android.sdk.model.Region) CountryCode(com.globalcollect.gateway.sdk.client.android.sdk.model.CountryCode) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

CountryCode (com.globalcollect.gateway.sdk.client.android.sdk.model.CountryCode)2 CurrencyCode (com.globalcollect.gateway.sdk.client.android.sdk.model.CurrencyCode)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 ArrayAdapter (android.widget.ArrayAdapter)1 CheckBox (android.widget.CheckBox)1 Spinner (android.widget.Spinner)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 EnvironmentType (com.globalcollect.gateway.sdk.client.android.sdk.model.Environment.EnvironmentType)1 PaymentContext (com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentContext)1 Region (com.globalcollect.gateway.sdk.client.android.sdk.model.Region)1