Search in sources :

Example 1 with PriceImpl

use of org.olat.resource.accesscontrol.model.PriceImpl in project OpenOLAT by OpenOLAT.

the class PaypalAccessConfigurationController method commitChanges.

@Override
public OfferAccess commitChanges() {
    BigDecimal amount = new BigDecimal(priceEl.getValue());
    String currencyCode = currencyEl.getSelectedKey();
    PriceImpl price = new PriceImpl();
    price.setAmount(amount);
    price.setCurrencyCode(currencyCode);
    Offer offer = link.getOffer();
    offer.setPrice(price);
    offer.setDescription(descEl.getValue());
    offer.setValidFrom(dateFrom.getDate());
    offer.setValidTo(dateTo.getDate());
    link.setValidFrom(dateFrom.getDate());
    link.setValidTo(dateTo.getDate());
    return link;
}
Also used : PriceImpl(org.olat.resource.accesscontrol.model.PriceImpl) Offer(org.olat.resource.accesscontrol.Offer) BigDecimal(java.math.BigDecimal)

Example 2 with PriceImpl

use of org.olat.resource.accesscontrol.model.PriceImpl in project OpenOLAT by OpenOLAT.

the class ACOrderManagerTest method testSaveOneClickOrderWithPrice.

@Test
public void testSaveOneClickOrderWithPrice() {
    // make extensiv test on one order
    // create some offers to buy
    OLATResource randomOres1 = createResource();
    Offer offer1 = acService.createOffer(randomOres1, "TestSaveOneClickOrder 1");
    Price price1 = new PriceImpl(new BigDecimal("20.00"), "CHF");
    offer1.setPrice(price1);
    offer1 = acService.save(offer1);
    dbInstance.commitAndCloseSession();
    // create a link offer to method
    List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(FreeAccessMethod.class);
    assertNotNull(methods);
    assertEquals(1, methods.size());
    AccessMethod method = methods.get(0);
    OfferAccess access1 = acMethodManager.createOfferAccess(offer1, method);
    acMethodManager.save(access1);
    dbInstance.commitAndCloseSession();
    // one clicks
    Order order = acOrderManager.saveOneClick(ident7, access1);
    dbInstance.commitAndCloseSession();
    // load order
    Order retrivedOrder = acOrderManager.loadOrderByKey(order.getKey());
    // check order
    assertNotNull(retrivedOrder);
    assertNotNull(retrivedOrder.getCreationDate());
    assertNotNull(retrivedOrder.getDelivery());
    assertNotNull(retrivedOrder.getOrderNr());
    assertNotNull(retrivedOrder.getParts());
    assertNotNull(retrivedOrder.getTotal());
    assertNotNull(retrivedOrder.getTotalOrderLines());
    assertEquals(ident7, retrivedOrder.getDelivery());
    assertEquals(1, retrivedOrder.getParts().size());
    assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), retrivedOrder.getTotalOrderLines().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(price1.getCurrencyCode(), retrivedOrder.getTotalOrderLines().getCurrencyCode());
    assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), retrivedOrder.getTotal().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(price1.getCurrencyCode(), retrivedOrder.getTotal().getCurrencyCode());
    // check order part
    OrderPart orderPart = retrivedOrder.getParts().get(0);
    assertNotNull(orderPart);
    assertNotNull(orderPart.getTotal());
    assertNotNull(orderPart.getTotalOrderLines());
    assertEquals(1, orderPart.getOrderLines().size());
    assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), orderPart.getTotalOrderLines().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(price1.getCurrencyCode(), orderPart.getTotalOrderLines().getCurrencyCode());
    assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), orderPart.getTotal().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(price1.getCurrencyCode(), orderPart.getTotal().getCurrencyCode());
    // check order line
    OrderLine line = orderPart.getOrderLines().get(0);
    Assert.assertNotNull(line);
    Assert.assertNotNull(line.getOffer());
    Assert.assertNotNull(line.getUnitPrice());
    Assert.assertNotNull(line.getTotal());
    Assert.assertEquals(offer1, line.getOffer());
    Assert.assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), line.getUnitPrice().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    Assert.assertEquals(price1.getCurrencyCode(), line.getUnitPrice().getCurrencyCode());
    Assert.assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), line.getTotal().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    Assert.assertEquals(price1.getCurrencyCode(), line.getTotal().getCurrencyCode());
}
Also used : PriceImpl(org.olat.resource.accesscontrol.model.PriceImpl) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OLATResource(org.olat.resource.OLATResource) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with PriceImpl

use of org.olat.resource.accesscontrol.model.PriceImpl in project openolat by klemens.

the class ACOrderManagerTest method testSaveOneClickOrderWithPrice.

@Test
public void testSaveOneClickOrderWithPrice() {
    // make extensiv test on one order
    // create some offers to buy
    OLATResource randomOres1 = createResource();
    Offer offer1 = acService.createOffer(randomOres1, "TestSaveOneClickOrder 1");
    Price price1 = new PriceImpl(new BigDecimal("20.00"), "CHF");
    offer1.setPrice(price1);
    offer1 = acService.save(offer1);
    dbInstance.commitAndCloseSession();
    // create a link offer to method
    List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(FreeAccessMethod.class);
    assertNotNull(methods);
    assertEquals(1, methods.size());
    AccessMethod method = methods.get(0);
    OfferAccess access1 = acMethodManager.createOfferAccess(offer1, method);
    acMethodManager.save(access1);
    dbInstance.commitAndCloseSession();
    // one clicks
    Order order = acOrderManager.saveOneClick(ident7, access1);
    dbInstance.commitAndCloseSession();
    // load order
    Order retrivedOrder = acOrderManager.loadOrderByKey(order.getKey());
    // check order
    assertNotNull(retrivedOrder);
    assertNotNull(retrivedOrder.getCreationDate());
    assertNotNull(retrivedOrder.getDelivery());
    assertNotNull(retrivedOrder.getOrderNr());
    assertNotNull(retrivedOrder.getParts());
    assertNotNull(retrivedOrder.getTotal());
    assertNotNull(retrivedOrder.getTotalOrderLines());
    assertEquals(ident7, retrivedOrder.getDelivery());
    assertEquals(1, retrivedOrder.getParts().size());
    assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), retrivedOrder.getTotalOrderLines().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(price1.getCurrencyCode(), retrivedOrder.getTotalOrderLines().getCurrencyCode());
    assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), retrivedOrder.getTotal().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(price1.getCurrencyCode(), retrivedOrder.getTotal().getCurrencyCode());
    // check order part
    OrderPart orderPart = retrivedOrder.getParts().get(0);
    assertNotNull(orderPart);
    assertNotNull(orderPart.getTotal());
    assertNotNull(orderPart.getTotalOrderLines());
    assertEquals(1, orderPart.getOrderLines().size());
    assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), orderPart.getTotalOrderLines().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(price1.getCurrencyCode(), orderPart.getTotalOrderLines().getCurrencyCode());
    assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), orderPart.getTotal().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(price1.getCurrencyCode(), orderPart.getTotal().getCurrencyCode());
    // check order line
    OrderLine line = orderPart.getOrderLines().get(0);
    Assert.assertNotNull(line);
    Assert.assertNotNull(line.getOffer());
    Assert.assertNotNull(line.getUnitPrice());
    Assert.assertNotNull(line.getTotal());
    Assert.assertEquals(offer1, line.getOffer());
    Assert.assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), line.getUnitPrice().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    Assert.assertEquals(price1.getCurrencyCode(), line.getUnitPrice().getCurrencyCode());
    Assert.assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), line.getTotal().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    Assert.assertEquals(price1.getCurrencyCode(), line.getTotal().getCurrencyCode());
}
Also used : PriceImpl(org.olat.resource.accesscontrol.model.PriceImpl) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OLATResource(org.olat.resource.OLATResource) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 4 with PriceImpl

use of org.olat.resource.accesscontrol.model.PriceImpl in project openolat by klemens.

the class PaypalAccessConfigurationController method commitChanges.

@Override
public OfferAccess commitChanges() {
    BigDecimal amount = new BigDecimal(priceEl.getValue());
    String currencyCode = currencyEl.getSelectedKey();
    PriceImpl price = new PriceImpl();
    price.setAmount(amount);
    price.setCurrencyCode(currencyCode);
    Offer offer = link.getOffer();
    offer.setPrice(price);
    offer.setDescription(descEl.getValue());
    offer.setValidFrom(dateFrom.getDate());
    offer.setValidTo(dateTo.getDate());
    link.setValidFrom(dateFrom.getDate());
    link.setValidTo(dateTo.getDate());
    return link;
}
Also used : PriceImpl(org.olat.resource.accesscontrol.model.PriceImpl) Offer(org.olat.resource.accesscontrol.Offer) BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)4 PriceImpl (org.olat.resource.accesscontrol.model.PriceImpl)4 Test (org.junit.Test)2 OLATResource (org.olat.resource.OLATResource)2 Offer (org.olat.resource.accesscontrol.Offer)2 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)2 FreeAccessMethod (org.olat.resource.accesscontrol.model.FreeAccessMethod)2 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)2