Table of Contents
Setting the Currency for a Transaction
Setting the currency for a transaction using Payment Device SDK versions 2.05+ is greatly simplified over the previous releases.
You can set the currency by creating a String with the three-letter currency code required. Prior to calling startTransaction
, you would add this to the list of parameters to be passed into startTransaction
with the parameter key Currency/CCParamCurrency for Android and iOS respectively. Please examine the examples below:
Android:
private static final String CURRENCY = "GBP";
requestParameters.add(ParameterKeys.Currency, CURRENCY);
iOS:
NSString *const CURRENCY = @"GBP";
[request setValue:CURRENCY forKey:CCParamCurrency];
Querying Available Currencies
Prior to querying what currencies are available for the provided Terminal ID, you will need to ensure at least one TMS Update has been carried out to ensure the Payment Device SDK has data to query against. Below are two examples of how to query and select a currency for Android and iOS:
Android:
// Fill our parameters with all available currencies stored within the Payment Device SDK, // cached from the the last TMS Update. Parameters availCurrencies = ChipDnaMobile.getInstance().getAvailableCurrencies(null); try { // Pass the parameter object into the Payment Device SDK Serializer to produce a HashMap of all available currencies. // Due to getAvailableCurrencies returning the result of the function within the parameter object, ensure you query // against the AvailableCurrencies key. HashMap<PaymentMethod, ArrayList> deserializedCurrencies = ChipDnaMobileSerializer.deserializeAvailableCurrencies(availCurrencies.getValue(ParameterKeys.AvailableCurrencies)); // Pull an ArrayList with type Currency (com.creditcall.chipdnamobile.Currency) against the PaymentMethod.Card key. final ArrayList currencyList = deserializedCurrencies.get(PaymentMethod.Card); String availableCurrencies = null; // Iterate through the ArrayList, appending each available currency to the availableCurrencies string for viewing. for(int i =0;i<currencyList.size();i++) availableCurrencies += currencyList.get(i).getCharCode().toString()+"\n"; // Output the available currencies. log("List of available currencies:\n"+availableCurrencies); } catch (XmlPullParserException|IOException e) { e.printStackTrace(); }
iOS:
//Query available currencies [self log:@"Querying available currencies..."];
// Fill our parameters with all available currencies stored within the Payment Device SDK, // cached from the the last TMS Update. CCParameters * paramCurrencies = [[ChipDnaMobile sharedInstance] getAvailableCurrencies:nil];
// Pass the parameter object into the Payment Device SDK Serializer to produce an NSDictionary of all available currencies. // Due to getAvailableCurrencies returning the result of the function within the parameter object, ensure you query // against the CCParamAvailableCurrencies key. NSDictionary * deserializedCurrencies = [ChipDnaMobileSerializer deserializedAvailableCurrencies:[paramCurrencies valueForKey:CCParamAvailableCurrencies]]; NSMutableString * listOfCurrencies = [[NSMutableString alloc] init];
// Iterate through the list of currencies within the deserializedCurrencies NSDictionary against the key "CARD", // and append these currencies to a NSMutableString for viewing. for (Currency * currency in [deserializedCurrencies valueForKey:@"CARD"]) { [listOfCurrencies appendFormat:@"%@\n",[currency charCode]]; }
// Output the available currencies. [self log:[NSString stringWithFormat:@"Available Currencies:\n%@", listOfCurrencies]];