Search in sources :

Example 1 with CurrencyConversionList

use of com.paypal.svcs.types.ap.CurrencyConversionList 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;
    }
}
Also used : AdaptivePaymentsService(com.paypal.svcs.services.AdaptivePaymentsService) InvalidCredentialException(com.paypal.exception.InvalidCredentialException) ConvertCurrencyResponse(com.paypal.svcs.types.ap.ConvertCurrencyResponse) ConvertCurrencyRequest(com.paypal.svcs.types.ap.ConvertCurrencyRequest) CurrencyList(com.paypal.svcs.types.ap.CurrencyList) HttpErrorException(com.paypal.exception.HttpErrorException) ClientActionRequiredException(com.paypal.exception.ClientActionRequiredException) CurrencyConversionList(com.paypal.svcs.types.ap.CurrencyConversionList) OAuthException(com.paypal.sdk.exceptions.OAuthException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) OAuthException(com.paypal.sdk.exceptions.OAuthException) SSLConfigurationException(com.paypal.exception.SSLConfigurationException) InvalidResponseDataException(com.paypal.exception.InvalidResponseDataException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidCredentialException(com.paypal.exception.InvalidCredentialException) HttpErrorException(com.paypal.exception.HttpErrorException) MissingCredentialException(com.paypal.exception.MissingCredentialException) IOException(java.io.IOException) ClientActionRequiredException(com.paypal.exception.ClientActionRequiredException) SSLConfigurationException(com.paypal.exception.SSLConfigurationException) MissingCredentialException(com.paypal.exception.MissingCredentialException) InvalidResponseDataException(com.paypal.exception.InvalidResponseDataException) CurrencyCodeList(com.paypal.svcs.types.ap.CurrencyCodeList) CurrencyType(com.paypal.svcs.types.common.CurrencyType)

Example 2 with CurrencyConversionList

use of com.paypal.svcs.types.ap.CurrencyConversionList 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;
    }
}
Also used : AdaptivePaymentsService(com.paypal.svcs.services.AdaptivePaymentsService) InvalidCredentialException(com.paypal.exception.InvalidCredentialException) ConvertCurrencyResponse(com.paypal.svcs.types.ap.ConvertCurrencyResponse) ConvertCurrencyRequest(com.paypal.svcs.types.ap.ConvertCurrencyRequest) CurrencyList(com.paypal.svcs.types.ap.CurrencyList) HttpErrorException(com.paypal.exception.HttpErrorException) ClientActionRequiredException(com.paypal.exception.ClientActionRequiredException) CurrencyConversionList(com.paypal.svcs.types.ap.CurrencyConversionList) OAuthException(com.paypal.sdk.exceptions.OAuthException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) OAuthException(com.paypal.sdk.exceptions.OAuthException) SSLConfigurationException(com.paypal.exception.SSLConfigurationException) InvalidResponseDataException(com.paypal.exception.InvalidResponseDataException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidCredentialException(com.paypal.exception.InvalidCredentialException) HttpErrorException(com.paypal.exception.HttpErrorException) MissingCredentialException(com.paypal.exception.MissingCredentialException) IOException(java.io.IOException) ClientActionRequiredException(com.paypal.exception.ClientActionRequiredException) SSLConfigurationException(com.paypal.exception.SSLConfigurationException) MissingCredentialException(com.paypal.exception.MissingCredentialException) InvalidResponseDataException(com.paypal.exception.InvalidResponseDataException) CurrencyCodeList(com.paypal.svcs.types.ap.CurrencyCodeList) CurrencyType(com.paypal.svcs.types.common.CurrencyType)

Aggregations

ClientActionRequiredException (com.paypal.exception.ClientActionRequiredException)2 HttpErrorException (com.paypal.exception.HttpErrorException)2 InvalidCredentialException (com.paypal.exception.InvalidCredentialException)2 InvalidResponseDataException (com.paypal.exception.InvalidResponseDataException)2 MissingCredentialException (com.paypal.exception.MissingCredentialException)2 SSLConfigurationException (com.paypal.exception.SSLConfigurationException)2 OAuthException (com.paypal.sdk.exceptions.OAuthException)2 AdaptivePaymentsService (com.paypal.svcs.services.AdaptivePaymentsService)2 ConvertCurrencyRequest (com.paypal.svcs.types.ap.ConvertCurrencyRequest)2 ConvertCurrencyResponse (com.paypal.svcs.types.ap.ConvertCurrencyResponse)2 CurrencyCodeList (com.paypal.svcs.types.ap.CurrencyCodeList)2 CurrencyConversionList (com.paypal.svcs.types.ap.CurrencyConversionList)2 CurrencyList (com.paypal.svcs.types.ap.CurrencyList)2 CurrencyType (com.paypal.svcs.types.common.CurrencyType)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 BigDecimal (java.math.BigDecimal)2