use of org.olat.resource.accesscontrol.Offer 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.Offer in project OpenOLAT by OpenOLAT.
the class TokenAccessConfigurationController method commitChanges.
@Override
public OfferAccess commitChanges() {
Offer offer = link.getOffer();
if (offer instanceof OfferImpl) {
((OfferImpl) offer).setToken(tokenEl.getValue());
}
offer.setDescription(descEl.getValue());
offer.setValidFrom(dateFrom.getDate());
offer.setValidTo(dateTo.getDate());
link.setValidFrom(dateFrom.getDate());
link.setValidTo(dateTo.getDate());
return link;
}
use of org.olat.resource.accesscontrol.Offer in project OpenOLAT by OpenOLAT.
the class ACFrontendManager method isAccessible.
/**
* The rule to access a business group:<br/>
* -No offer, access is free<br/>
* -Owners have always access to the resource<br/>
* -Tutors have access to the resource<br/>
* -Participants have access to the resource<br/>
* @param group
* @param forId
* @return
*/
@Override
public AccessResult isAccessible(BusinessGroup group, Identity forId, boolean allowNonInteractiveAccess) {
if (!accessModule.isEnabled()) {
return new AccessResult(true);
}
List<String> roles = businessGroupRelationDao.getRoles(forId, group);
if (roles.contains(GroupRoles.coach.name())) {
return new AccessResult(true);
}
if (roles.contains(GroupRoles.participant.name())) {
return new AccessResult(true);
}
Date now = dateNow();
OLATResource resource = OLATResourceManager.getInstance().findResourceable(group);
List<Offer> offers = accessManager.findOfferByResource(resource, true, now);
if (offers.isEmpty()) {
if (methodManager.isValidMethodAvailable(resource, null)) {
// not open for the moment: no valid offer at this date but some methods are defined
return new AccessResult(false);
} else {
return new AccessResult(true);
}
}
return isAccessible(forId, offers, allowNonInteractiveAccess);
}
use of org.olat.resource.accesscontrol.Offer in project OpenOLAT by OpenOLAT.
the class AccessConfigurationController method addMethod.
protected void addMethod(UserRequest ureq, AccessMethod method) {
boolean confirmationEmail = confirmationEmailEl.isVisible() && confirmationEmailEl.isAtLeastSelected(1);
Offer offer = acService.createOffer(resource, displayName);
offer.setConfirmationEmail(confirmationEmail);
OfferAccess link = acService.createOfferAccess(offer, method);
removeAsListenerAndDispose(newMethodCtrl);
AccessMethodHandler handler = acModule.getAccessMethodHandler(link.getMethod().getType());
if (handler != null) {
newMethodCtrl = handler.createConfigurationController(ureq, getWindowControl(), link);
}
if (newMethodCtrl != null) {
listenTo(newMethodCtrl);
String title = handler.getMethodName(getLocale());
cmc = new CloseableModalController(getWindowControl(), translate("close"), newMethodCtrl.getInitialComponent(), true, title);
cmc.activate();
listenTo(cmc);
} else {
OfferAccess newLink = acService.saveOfferAccess(link);
addConfiguration(newLink);
}
}
use of org.olat.resource.accesscontrol.Offer in project OpenOLAT by OpenOLAT.
the class AccessConfigurationController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
// contextHelptexts for Label
HelpTooltip acMethodsLabelHelp = new HelpTooltip("acMethodsLabelHelp", "Legen Sie fest unter welchen Bedingungen Benutzer diese Ressource buchen können.", "Course Settings#_buchungsmethode", getLocale());
((FormLayoutContainer) formLayout).put("acMethodsLabelHelp", acMethodsLabelHelp);
if (editable) {
List<AccessMethod> methods = acService.getAvailableMethods(getIdentity(), ureq.getUserSession().getRoles());
for (AccessMethod method : methods) {
AccessMethodHandler handler = acModule.getAccessMethodHandler(method.getType());
if (handler.isPaymentMethod() && !allowPaymentMethod) {
continue;
}
String title = handler.getMethodName(getLocale());
FormLink add = uifactory.addFormLink("create." + handler.getType(), title, null, formLayout, Link.LINK | Link.NONTRANSLATED);
add.setUserObject(method);
add.setIconLeftCSS(("o_icon " + method.getMethodCssClass() + "_icon o_icon-lg").intern());
addMethods.add(add);
formLayout.add(add.getName(), add);
}
((FormLayoutContainer) formLayout).contextPut("methods", addMethods);
}
String[] onValues = new String[] { "" };
confirmationEmailEl = uifactory.addCheckboxesHorizontal("confirmation.email", formLayout, onKeys, onValues);
confirmationEmailEl.addActionListener(FormEvent.ONCHANGE);
confirmationEmailEl.setVisible(false);
String confPage = velocity_root + "/configuration_list.html";
confControllerContainer = FormLayoutContainer.createCustomFormLayout("conf-controllers", getTranslator(), confPage);
confControllerContainer.setRootForm(mainForm);
formLayout.add(confControllerContainer);
loadConfigurations();
confControllerContainer.contextPut("confControllers", confControllers);
boolean confirmationEmail = false;
for (AccessInfo info : confControllers) {
Offer offer = info.getLink().getOffer();
confirmationEmail |= offer.isConfirmationEmail();
}
if (confirmationEmail) {
confirmationEmailEl.select(onKeys[0], true);
}
if (!embbed) {
setFormTitle("accesscontrol.title");
if (editable) {
final FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonLayout", getTranslator());
buttonGroupLayout.setRootForm(mainForm);
formLayout.add(buttonGroupLayout);
formLayout.add("buttonLayout", buttonGroupLayout);
uifactory.addFormSubmitButton("save", buttonGroupLayout);
}
}
confControllerContainer.contextPut("emptyConfigGrantsFullAccess", Boolean.valueOf(emptyConfigGrantsFullAccess));
}
Aggregations