There are a number of ways you can query and select the available currencies within ChipDNA Mobile using the old API (1.19).
It's important to note that prior to every fetching of the available currencies, an updated CardEaseMobileProperties object will need to be fetched using the snippets below:
For Android:CardEaseMobileProperties CEMP = CardEaseMobileProperties.fetch();
For iOS:properties = [[CardEaseMobileProperties alloc]init];
At least one TMS update will be required on the device to fill the properties with the correct values from our platform. If you receive a null object error, this is normally due to the fact a TMS update has not been initiated.
Below are two examples of how to query and select currency for Android and iOS:
Android:
private void getCurrencies() { // Fetch the latest CardEaseMobileProperties final CardEaseMobileProperties CEMP = CardEaseMobileProperties.fetch(); // Create our HashMap of the available currencies final HashMap<PaymentMethod, ArrayList> CurrencyMap = CEMP.getAvailableCurrencies(); // Build an ArrayList of all currencies for PaymentMethod.Card final ArrayList currencyList = CurrencyMap.get(PaymentMethod.Card); List list = new ArrayList(); // Display a list of all currencies within the currencyList ArrayList for(int i =0;i<currencyList.size();i++) { // Add currency to our list which could be used to populate a Spinner list.add(currencyList.get(i).getCharCode()); // Log the currency for debug purposes log(currencyList.get(i).getCharCode()); // Currency can be hard-coded for debug purposes: if (currencyList.get(i).getCharCode().contains("EUR")) { try { log("Setting currency to EUR..."); // Set the currency desired... CEMP.setCurrency(currencyList.get(i)); // Save changes to our CardEaseMobileProperties CEMP.save(); } catch (ConfigurationException e) { log("Error: " + e.getConfigurationErrorCode().getCode()); } catch (StorageException e) { log("Failed to save CEM credentials"); Log.e(LOGGER_STR, e.getLocalizedMessage(), e); } } } }
iOS:
NSError *error = nil; [[CardEaseMobile sharedInstance] setDelegate:self]; // Fetch the latest CardEaseMobileProperties properties = [[CardEaseMobileProperties alloc]init]; // Currency can be hard-coded for debug purposes: NSString * sWantedCurrency = @"GBP"; // Fetch a list of available currencies NSDictionary * availableCurrencies = [properties availableCurrencies]; [self log:[NSString stringWithFormat: @"Available Currencies:"]]; // Iterate through our list of available currencies for key PaymentMethod.Card for (id currency in availableCurrencies[@"PaymentMethod.Card"]) { // If the wanted currency string is the same as the iterated currency charCode, // set the currency, otherwise log which currency is available if ([sWantedCurrency isEqualToString:currency.charCode]) { [properties setCurrency:(currency) configurationError:&error]; [self log:[NSString stringWithFormat: @"Set Currency = %@", currency.charCode]]; } else { [self log:[NSString stringWithFormat: @"Currency: %@", currency.charCode]]; } } // Save our properties changes and log any errors reported NSError *err = nil; [properties save:&err]; if (err) { [self log:[NSString stringWithFormat: @" CardEaseMobile properties save failed <%lld>", (long long)error.code]]; }
If you receive the error "1020 Currency Is Not Set", this occurs when more than one currency is set against the merchant account, but the currency to be used for that transaction has not been defined within the integration.
On a test terminal, as multiple currencies are set for a default terminal ID, this error may appear and your integration will need to handle choosing a currency if more than one is set.