use of com.paypal.svcs.types.ap.CurrencyCodeList in project openolat by klemens.
the class PaypalManagerImpl method convertCurrency.
@Override
public boolean convertCurrency() {
try {
String[] fromcodes = new String[] { "CHF" };
String[] tocodes = new String[] { "USD" };
BigDecimal[] amountItems = new BigDecimal[] { new BigDecimal("20.00") };
CurrencyList list = new CurrencyList();
CurrencyCodeList cclist = new CurrencyCodeList();
for (int i = 0; i < amountItems.length; i++) {
CurrencyType ct = new CurrencyType();
ct.setAmount(amountItems[i].doubleValue());
ct.setCode(fromcodes[i]);
list.getCurrency().add(ct);
}
for (int i = 0; i < tocodes.length; i++) {
cclist.getCurrencyCode().add(tocodes[i]);
}
ConvertCurrencyRequest req = new ConvertCurrencyRequest();
req.setBaseAmountList(list);
req.setConvertToCurrencyList(cclist);
req.setRequestEnvelope(getAppRequestEnvelope());
AdaptivePaymentsService ap = new AdaptivePaymentsService(getAccountProperties());
ConvertCurrencyResponse resp = ap.convertCurrency(req);
for (Iterator<CurrencyConversionList> iterator = resp.getEstimatedAmountTable().getCurrencyConversionList().iterator(); iterator.hasNext(); ) {
CurrencyConversionList ccclist = iterator.next();
log.info(ccclist.getBaseAmount().getCode() + " :: " + ccclist.getBaseAmount().getAmount());
List<CurrencyType> l = ccclist.getCurrencyList().getCurrency();
for (int i = 0; i < l.size(); i++) {
CurrencyType ct = l.get(i);
log.info(ct.getCode() + " :: " + ct.getAmount());
}
}
return true;
} catch (SSLConfigurationException e) {
log.error("Paypal error", e);
return false;
} catch (InvalidCredentialException e) {
log.error("Paypal error", e);
return false;
} catch (UnsupportedEncodingException e) {
log.error("Paypal error", e);
return false;
} catch (HttpErrorException e) {
log.error("Paypal error", e);
return false;
} catch (InvalidResponseDataException e) {
log.error("Paypal error", e);
return false;
} catch (ClientActionRequiredException e) {
log.error("Paypal error", e);
return false;
} catch (MissingCredentialException e) {
log.error("Paypal error", e);
return false;
} catch (OAuthException e) {
log.error("Paypal error", e);
return false;
} catch (IOException | InterruptedException e) {
log.error("Paypal error", e);
return false;
} catch (Exception e) {
log.error("", e);
return false;
}
}
use of com.paypal.svcs.types.ap.CurrencyCodeList in project OpenOLAT by OpenOLAT.
the class PaypalManagerImpl method convertCurrency.
@Override
public boolean convertCurrency() {
try {
String[] fromcodes = new String[] { "CHF" };
String[] tocodes = new String[] { "USD" };
BigDecimal[] amountItems = new BigDecimal[] { new BigDecimal("20.00") };
CurrencyList list = new CurrencyList();
CurrencyCodeList cclist = new CurrencyCodeList();
for (int i = 0; i < amountItems.length; i++) {
CurrencyType ct = new CurrencyType();
ct.setAmount(amountItems[i].doubleValue());
ct.setCode(fromcodes[i]);
list.getCurrency().add(ct);
}
for (int i = 0; i < tocodes.length; i++) {
cclist.getCurrencyCode().add(tocodes[i]);
}
ConvertCurrencyRequest req = new ConvertCurrencyRequest();
req.setBaseAmountList(list);
req.setConvertToCurrencyList(cclist);
req.setRequestEnvelope(getAppRequestEnvelope());
AdaptivePaymentsService ap = new AdaptivePaymentsService(getAccountProperties());
ConvertCurrencyResponse resp = ap.convertCurrency(req);
for (Iterator<CurrencyConversionList> iterator = resp.getEstimatedAmountTable().getCurrencyConversionList().iterator(); iterator.hasNext(); ) {
CurrencyConversionList ccclist = iterator.next();
log.info(ccclist.getBaseAmount().getCode() + " :: " + ccclist.getBaseAmount().getAmount());
List<CurrencyType> l = ccclist.getCurrencyList().getCurrency();
for (int i = 0; i < l.size(); i++) {
CurrencyType ct = l.get(i);
log.info(ct.getCode() + " :: " + ct.getAmount());
}
}
return true;
} catch (SSLConfigurationException e) {
log.error("Paypal error", e);
return false;
} catch (InvalidCredentialException e) {
log.error("Paypal error", e);
return false;
} catch (UnsupportedEncodingException e) {
log.error("Paypal error", e);
return false;
} catch (HttpErrorException e) {
log.error("Paypal error", e);
return false;
} catch (InvalidResponseDataException e) {
log.error("Paypal error", e);
return false;
} catch (ClientActionRequiredException e) {
log.error("Paypal error", e);
return false;
} catch (MissingCredentialException e) {
log.error("Paypal error", e);
return false;
} catch (OAuthException e) {
log.error("Paypal error", e);
return false;
} catch (IOException | InterruptedException e) {
log.error("Paypal error", e);
return false;
} catch (Exception e) {
log.error("", e);
return false;
}
}
Aggregations