use of org.olat.resource.accesscontrol.Price 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.Price in project OpenOLAT by OpenOLAT.
the class PaypalAccessConfigurationController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
String desc = null;
if (link.getOffer() != null) {
desc = link.getOffer().getDescription();
}
descEl = uifactory.addTextAreaElement("offer-desc", "offer.description", 2000, 6, 80, false, desc, formLayout);
Price price = null;
if (link.getOffer() != null && link.getOffer().getPrice() != null) {
price = link.getOffer().getPrice();
}
String amount = null;
if (price != null && price.getAmount() != null) {
amount = price.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN).toString();
}
priceEl = uifactory.addTextElement("price", "price", 32, amount, formLayout);
currencyEl = uifactory.addDropdownSingleselect("currency", "currency", formLayout, currencies, currencies, null);
boolean selected = false;
if (price != null && price.getCurrencyCode() != null) {
for (String currency : currencies) {
if (currency.equals(price.getCurrencyCode())) {
currencyEl.select(currency, true);
selected = true;
}
}
}
if (!selected) {
if (StringHelper.containsNonWhitespace(paypalModule.getPaypalCurrency())) {
currencyEl.select(paypalModule.getPaypalCurrency(), true);
currencyEl.setEnabled(false);
} else {
currencyEl.select("CHF", true);
}
}
vatEnabledEl = uifactory.addCheckboxesHorizontal("vat.enabled", "vat.enabled", formLayout, vatKeys, vatValues);
if (acModule.isVatEnabled()) {
vatEnabledEl.select(vatKeys[0], true);
}
vatEnabledEl.setEnabled(false);
dateFrom = uifactory.addDateChooser("from_" + link.getKey(), "from", link.getValidFrom(), formLayout);
dateFrom.setHelpText(translate("from.hint"));
dateTo = uifactory.addDateChooser("to_" + link.getKey(), "to", link.getValidTo(), formLayout);
dateTo.setHelpText(translate("from.hint"));
super.initForm(formLayout, listener, ureq);
}
use of org.olat.resource.accesscontrol.Price in project OpenOLAT by OpenOLAT.
the class ACMethodDAO method getAccessMethodForResources.
public List<OLATResourceAccess> getAccessMethodForResources(Collection<Long> resourceKeys, String resourceType, String excludedResourceType, boolean valid, Date atDate) {
// quicker to filter in java, numerous keys in "in" are slow
final int maxResourcesEntries = 250;
StringBuilder sb = new StringBuilder();
sb.append("select access.method, resource, offer.price from acofferaccess access, ").append(OLATResourceImpl.class.getName()).append(" resource").append(" inner join access.offer offer").append(" inner join offer.resource oResource").append(" where access.valid=").append(valid).append(" and offer.valid=").append(valid).append(" and resource.key=oResource.key");
if (resourceKeys != null && !resourceKeys.isEmpty()) {
if (resourceKeys.size() < maxResourcesEntries) {
sb.append(" and resource.key in (:resourceKeys) ");
}
sb.append(" and oResource.key=resource.key");
}
if (StringHelper.containsNonWhitespace(resourceType)) {
sb.append(" and oResource.resName =:resourceType ");
}
if (StringHelper.containsNonWhitespace(excludedResourceType)) {
sb.append(" and not(oResource.resName=:excludedResourceType)");
}
if (atDate != null) {
sb.append(" and (offer.validFrom is null or offer.validFrom<=:atDate)").append(" and (offer.validTo is null or offer.validTo>=:atDate)");
}
TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class);
if (atDate != null) {
query.setParameter("atDate", atDate, TemporalType.TIMESTAMP);
}
Set<Long> resourceKeysSet = null;
if (resourceKeys != null && !resourceKeys.isEmpty()) {
if (resourceKeys.size() < maxResourcesEntries) {
query.setParameter("resourceKeys", resourceKeys);
} else {
resourceKeysSet = new HashSet<Long>(resourceKeys);
}
}
if (StringHelper.containsNonWhitespace(resourceType)) {
query.setParameter("resourceType", resourceType);
}
if (StringHelper.containsNonWhitespace(excludedResourceType)) {
query.setParameter("excludedResourceType", excludedResourceType);
}
List<Object[]> rawResults = query.getResultList();
Map<Long, OLATResourceAccess> rawResultsMap = new HashMap<Long, OLATResourceAccess>();
for (Object[] rawResult : rawResults) {
AccessMethod method = (AccessMethod) rawResult[0];
OLATResource resource = (OLATResource) rawResult[1];
if (resourceKeysSet != null && !resourceKeysSet.contains(resource.getKey())) {
continue;
}
if (!method.isVisibleInGui()) {
continue;
}
Price price = (Price) rawResult[2];
if (rawResultsMap.containsKey(resource.getKey())) {
rawResultsMap.get(resource.getKey()).addBundle(price, method);
} else {
rawResultsMap.put(resource.getKey(), new OLATResourceAccess(resource, price, method));
}
}
return new ArrayList<OLATResourceAccess>(rawResultsMap.values());
}
use of org.olat.resource.accesscontrol.Price 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.Price in project OpenOLAT by OpenOLAT.
the class RepositoryEntryACColumnDescriptor method render.
@Override
public void render(StringOutput sb, Renderer renderer, Object val, Locale locale, int alignment, String action) {
if (val instanceof Collection) {
Collection<?> accessTypes = (Collection<?>) val;
for (Object accessType : accessTypes) {
if (accessType instanceof String) {
String type = (String) accessType;
sb.append("<i class='o_icon ").append(type).append("_icon o_icon-lg'></i>");
}
}
} else if (val instanceof Boolean) {
boolean acessControlled = ((Boolean) val).booleanValue();
if (acessControlled) {
sb.append("<i class='o_icon o_ac_group_icon o_icon-lg'></i>");
}
} else if (val instanceof OLATResourceAccess) {
OLATResourceAccess access = (OLATResourceAccess) val;
for (PriceMethodBundle bundle : access.getMethods()) {
Price price = bundle.getPrice();
String type = bundle.getMethod().getMethodCssClass();
if (price == null || price.isEmpty()) {
sb.append("<i class='o_icon ").append(type).append("_icon o_icon-lg'></i>");
} else {
String p = PriceFormat.fullFormat(price);
sb.append("<span class='o_nowrap'><i class='o_icon ").append(type).append("_icon o_icon-lg'></i> ").append(p).append("</span>");
}
}
}
}
Aggregations