Reputation:
I was trying to integrate the PayPal in iOS as well as Android native application for in India & Qatar, which currencies are INR & QAR, As much i know PayPal does not support such Currency so is there only option to use currency convertor?
If yes, can anybody tell me how can i achieve it step by step.
Upvotes: 0
Views: 221
Reputation: 2189
Unfortunately, PayPal does not support yet lot of currencies. See supported currency code.
Anyway if you want to achieve thing you must need to use currency convertor you can use Google API or Yahoo API for that.
You can visit here & you can talk with your backend developer regarding this he will assist you even better & easy way,
I have used it once in Android native app Yahoo exchange rates like,
Step 1:
private String fromCurrency = "QAR";
private String toCurrency = "USD";
private String urlString = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20csv%20where%20url%3D%22http%3A%2F%2Ffinance.yahoo.com%2Fd%2Fquotes.csv%3Fe%3D.csv%26f%3Dc4l1%26s%3D" + fromCurrency + toCurrency + "%3DX%22%3B&format=json";
Step 2:
private void apiCallCurrencyConversion() {
//Don't mind you can you retrofit call too,
OkHttpClient client = new OkHttpClient();
final Request request = new Request.Builder()
.url(urlString)
.build();
client.newCall(request).enqueue(new okhttp3.Callback() {
@Override
public void onFailure(@NonNull okhttp3.Call call, @NonNull IOException e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this,"Fail", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onResponse(@NonNull okhttp3.Call call, @NonNull okhttp3.Response response) throws IOException {
runOnUiThread(new Runnable() {
@Override
public void run() {
}
});
if (response.code() == 200 && response.isSuccessful()) {
final CurrencyYahooApiJSON currencyYahooApiJSON = new Gson().fromJson(response.body().string(), CurrencyYahooApiJSON.class);
Log.d(TAG, currencyYahooApiJSON.getQuery().getResults().getRow().getConvertedValue());
runOnUiThread(new Runnable() {
@Override
public void run() {
proceedToPay(currencyYahooApiJSON);
}
});
}
}
});
}
You can download the ResponseJsonObject pojo from here
Now you are ready to use the converted value with USD,
Step 3:
private void proceedToPay(CurrencyYahooApiJSON currencyYahooApiJSON) {
//Getting the amount from editText
String paymentAmount = "100";
Row row = currencyYahooApiJSON.getQuery().getResults().getRow();
double val = Double.valueOf(paymentAmount);
double convertedAmount = val * Double.valueOf(row.getConvertedValue());
// convertedAmount here will us get is near about 27.41
//PayPal Configuration & payment process ahead.
}
Cheers
Upvotes: 1