Search in sources :

Example 1 with Offer

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;
}
Also used : Order(org.olat.resource.accesscontrol.Order) ClientActionRequiredException(com.paypal.exception.ClientActionRequiredException) AdaptivePaymentsService(com.paypal.svcs.services.AdaptivePaymentsService) OAuthException(com.paypal.sdk.exceptions.OAuthException) Receiver(com.paypal.svcs.types.ap.Receiver) InvalidCredentialException(com.paypal.exception.InvalidCredentialException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ReceiverList(com.paypal.svcs.types.ap.ReceiverList) IOException(java.io.IOException) 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) PayRequest(com.paypal.svcs.types.ap.PayRequest) PaypalTransaction(org.olat.resource.accesscontrol.provider.paypal.model.PaypalTransaction) Offer(org.olat.resource.accesscontrol.Offer) Price(org.olat.resource.accesscontrol.Price) SSLConfigurationException(com.paypal.exception.SSLConfigurationException) MissingCredentialException(com.paypal.exception.MissingCredentialException) InvalidResponseDataException(com.paypal.exception.InvalidResponseDataException) PayResponse(com.paypal.svcs.types.ap.PayResponse) HttpErrorException(com.paypal.exception.HttpErrorException)

Example 2 with Offer

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;
}
Also used : Offer(org.olat.resource.accesscontrol.Offer) OfferImpl(org.olat.resource.accesscontrol.model.OfferImpl)

Example 3 with Offer

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);
}
Also used : Offer(org.olat.resource.accesscontrol.Offer) AccessResult(org.olat.resource.accesscontrol.AccessResult) OLATResource(org.olat.resource.OLATResource) Date(java.util.Date)

Example 4 with Offer

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);
    }
}
Also used : OfferAccess(org.olat.resource.accesscontrol.OfferAccess) Offer(org.olat.resource.accesscontrol.Offer) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler)

Example 5 with Offer

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));
}
Also used : HelpTooltip(org.olat.core.gui.components.helpTooltip.HelpTooltip) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) Offer(org.olat.resource.accesscontrol.Offer) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler)

Aggregations

Offer (org.olat.resource.accesscontrol.Offer)38 OfferAccess (org.olat.resource.accesscontrol.OfferAccess)16 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)12 Test (org.junit.Test)8 OLATResource (org.olat.resource.OLATResource)8 Date (java.util.Date)6 Identity (org.olat.core.id.Identity)6 AccessMethodHandler (org.olat.resource.accesscontrol.method.AccessMethodHandler)6 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)4 BusinessGroup (org.olat.group.BusinessGroup)4 BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)4 OpenBusinessGroupRow (org.olat.group.model.OpenBusinessGroupRow)4 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)4 AccessResult (org.olat.resource.accesscontrol.AccessResult)3 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