use of com.paypal.exception.InvalidCredentialException in project OpenOLAT by OpenOLAT.
the class PaypalManagerImpl method request.
public PayResponse request(Identity delivery, OfferAccess offerAccess, String mapperUri, String sessionId) {
StringBuilder url = new StringBuilder();
url.append(Settings.createServerURI()).append(mapperUri);
Offer offer = offerAccess.getOffer();
Price amount = offer.getPrice();
Order order = orderManager.saveOneClick(delivery, offerAccess, OrderStatus.PREPAYMENT);
PaypalTransaction trx = createAndPersistTransaction(amount, order, order.getParts().get(0), offerAccess.getMethod());
// !!!! make a trace of the process
dbInstance.commit();
ReceiverList list = new ReceiverList();
Receiver rec1 = new Receiver();
rec1.setAmount(amount.getAmount().doubleValue());
rec1.setEmail(paypalModule.getPaypalFirstReceiverEmailAddress());
rec1.setInvoiceId(order.getOrderNr());
list.getReceiver().add(rec1);
String returnURL = url.toString() + "/" + trx.getSecureSuccessUUID() + ".html;jsessionid=" + sessionId + "?status=success";
String cancelURL = url.toString() + "/" + trx.getSecureCancelUUID() + ".html;jsessionid=" + sessionId + "?status=cancel";
PayRequest payRequest = new PayRequest();
payRequest.setCancelUrl(cancelURL);
payRequest.setReturnUrl(returnURL);
payRequest.setTrackingId(order.getOrderNr());
payRequest.setCurrencyCode(amount.getCurrencyCode());
payRequest.setClientDetails(getAppDetails());
payRequest.setReceiverList(list);
payRequest.setRequestEnvelope(getAppRequestEnvelope());
payRequest.setActionType("PAY");
payRequest.setIpnNotificationUrl(Settings.getServerContextPathURI() + "/paypal/ipn");
PayResponse payResp = null;
try {
AdaptivePaymentsService ap = new AdaptivePaymentsService(getAccountProperties());
payResp = ap.pay(payRequest);
log.audit("Paypal send PayRequest: " + (payResp == null ? "no response" : payResp.getPayKey() + "/" + payResp.getPaymentExecStatus()));
return payResp;
} catch (SSLConfigurationException e) {
log.error("Paypal error", e);
} catch (InvalidCredentialException e) {
log.error("Paypal error", e);
} catch (UnsupportedEncodingException e) {
log.error("Paypal error", e);
} catch (HttpErrorException e) {
log.error("Paypal error", e);
} catch (InvalidResponseDataException e) {
log.error("Paypal error", e);
} catch (ClientActionRequiredException e) {
log.error("Paypal error", e);
} catch (MissingCredentialException e) {
log.error("Paypal error", e);
} catch (OAuthException e) {
log.error("Paypal error", e);
} catch (IOException | InterruptedException e) {
log.error("Paypal error", e);
} catch (Exception e) {
log.error("Paypal error", e);
} finally {
if (payResp == null) {
updateTransaction(trx, PaypalTransactionStatus.ERROR);
} else {
updateTransaction(payResp, trx);
}
}
return null;
}
use of com.paypal.exception.InvalidCredentialException 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.exception.InvalidCredentialException in project openolat by klemens.
the class PaypalManagerImpl method request.
public PayResponse request(Identity delivery, OfferAccess offerAccess, String mapperUri, String sessionId) {
StringBuilder url = new StringBuilder();
url.append(Settings.createServerURI()).append(mapperUri);
Offer offer = offerAccess.getOffer();
Price amount = offer.getPrice();
Order order = orderManager.saveOneClick(delivery, offerAccess, OrderStatus.PREPAYMENT);
PaypalTransaction trx = createAndPersistTransaction(amount, order, order.getParts().get(0), offerAccess.getMethod());
// !!!! make a trace of the process
dbInstance.commit();
ReceiverList list = new ReceiverList();
Receiver rec1 = new Receiver();
rec1.setAmount(amount.getAmount().doubleValue());
rec1.setEmail(paypalModule.getPaypalFirstReceiverEmailAddress());
rec1.setInvoiceId(order.getOrderNr());
list.getReceiver().add(rec1);
String returnURL = url.toString() + "/" + trx.getSecureSuccessUUID() + ".html;jsessionid=" + sessionId + "?status=success";
String cancelURL = url.toString() + "/" + trx.getSecureCancelUUID() + ".html;jsessionid=" + sessionId + "?status=cancel";
PayRequest payRequest = new PayRequest();
payRequest.setCancelUrl(cancelURL);
payRequest.setReturnUrl(returnURL);
payRequest.setTrackingId(order.getOrderNr());
payRequest.setCurrencyCode(amount.getCurrencyCode());
payRequest.setClientDetails(getAppDetails());
payRequest.setReceiverList(list);
payRequest.setRequestEnvelope(getAppRequestEnvelope());
payRequest.setActionType("PAY");
payRequest.setIpnNotificationUrl(Settings.getServerContextPathURI() + "/paypal/ipn");
PayResponse payResp = null;
try {
AdaptivePaymentsService ap = new AdaptivePaymentsService(getAccountProperties());
payResp = ap.pay(payRequest);
log.audit("Paypal send PayRequest: " + (payResp == null ? "no response" : payResp.getPayKey() + "/" + payResp.getPaymentExecStatus()));
return payResp;
} catch (SSLConfigurationException e) {
log.error("Paypal error", e);
} catch (InvalidCredentialException e) {
log.error("Paypal error", e);
} catch (UnsupportedEncodingException e) {
log.error("Paypal error", e);
} catch (HttpErrorException e) {
log.error("Paypal error", e);
} catch (InvalidResponseDataException e) {
log.error("Paypal error", e);
} catch (ClientActionRequiredException e) {
log.error("Paypal error", e);
} catch (MissingCredentialException e) {
log.error("Paypal error", e);
} catch (OAuthException e) {
log.error("Paypal error", e);
} catch (IOException | InterruptedException e) {
log.error("Paypal error", e);
} catch (Exception e) {
log.error("Paypal error", e);
} finally {
if (payResp == null) {
updateTransaction(trx, PaypalTransactionStatus.ERROR);
} else {
updateTransaction(payResp, trx);
}
}
return null;
}
use of com.paypal.exception.InvalidCredentialException 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