use of org.olat.resource.accesscontrol.provider.paypal.model.PaypalTransaction in project OpenOLAT by OpenOLAT.
the class PaypalAccessHandler method createTransactionDetailsController.
@Override
public FormController createTransactionDetailsController(UserRequest ureq, WindowControl wControl, Order order, OrderPart part, AccessMethod method, Form form) {
PaypalManager paypalManager = CoreSpringFactory.getImpl(PaypalManager.class);
PaypalTransaction transaction = paypalManager.loadTransaction(order, part);
return new PaypalTransactionDetailsController(ureq, wControl, transaction, form);
}
use of org.olat.resource.accesscontrol.provider.paypal.model.PaypalTransaction 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 org.olat.resource.accesscontrol.provider.paypal.model.PaypalTransaction in project OpenOLAT by OpenOLAT.
the class PaypalAccessController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormTitle("access.paypal.title");
setFormDescription("access.paypal.desc");
setFormTitleIconCss("o_icon o_icon-fw " + PaypalAccessHandler.METHOD_CSS_CLASS + "_icon");
String uuid = (String) ureq.getUserSession().getEntry("paypal-uuid");
if (StringHelper.containsNonWhitespace(uuid)) {
PaypalTransaction transaction = paypalManager.loadTransactionByUUID(uuid);
PaypalTransactionStatus status = transaction.getStatus();
if (status == PaypalTransactionStatus.CANCELED) {
setFormWarning("paypal.cancelled.transaction");
} else if (status == PaypalTransactionStatus.ERROR) {
setFormWarning("paypal.error.transaction");
}
}
String description = link.getOffer().getDescription();
if (StringHelper.containsNonWhitespace(description)) {
description = StringHelper.xssScan(description);
uifactory.addStaticTextElement("offer.description", description, formLayout);
}
Price price = link.getOffer().getPrice();
String priceStr = PriceFormat.fullFormat(price);
uifactory.addStaticTextElement("offer.price", priceStr, formLayout);
final FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonLayout", getTranslator());
buttonGroupLayout.setRootForm(mainForm);
formLayout.add(buttonGroupLayout);
uifactory.addFormSubmitButton("access.button", formLayout);
}
use of org.olat.resource.accesscontrol.provider.paypal.model.PaypalTransaction in project OpenOLAT by OpenOLAT.
the class PaypalTransactionStatusRenderer method render.
@Override
public void render(Renderer renderer, StringOutput sb, Object cellValue, int row, FlexiTableComponent source, URLBuilder ubu, Translator translator) {
if (cellValue instanceof PaypalTransaction) {
PaypalTransaction trx = (PaypalTransaction) cellValue;
PaypalMergedState mState = PaypalMergedState.value(trx);
sb.append("<i class='o_icon o_icon-fw ").append(mState.cssClass()).append("'> </i>");
}
}
use of org.olat.resource.accesscontrol.provider.paypal.model.PaypalTransaction in project openolat by klemens.
the class PaypalManagerImpl method updateTransaction.
@Override
public void updateTransaction(String uuid) {
PaypalTransaction trx = loadTransactionByUUID(uuid);
if (uuid.equals(trx.getSecureSuccessUUID())) {
log.audit("Paypal transaction success: " + trx);
completeTransaction(trx, null);
} else if (uuid.equals(trx.getSecureCancelUUID())) {
// cancel -> return to the access panel
log.audit("Paypal transaction canceled by user: " + trx);
cancelTransaction(trx);
}
}
Aggregations