Set Default Payment on first order

This commit is contained in:
CodeSteak 2020-06-25 11:46:01 +02:00
parent b993700ae4
commit bdd1017232
5 changed files with 14 additions and 6 deletions

View File

@ -1,6 +1,5 @@
package org.hso.ecommerce.components; package org.hso.ecommerce.components;
import org.hso.ecommerce.entities.booking.PaymentMethod;
import org.hso.ecommerce.entities.shop.Address; import org.hso.ecommerce.entities.shop.Address;
import org.hso.ecommerce.entities.user.User; import org.hso.ecommerce.entities.user.User;
import org.hso.ecommerce.repos.user.UserRepository; import org.hso.ecommerce.repos.user.UserRepository;
@ -26,8 +25,7 @@ public class AdminInitializer {
firstAdmin.created = new Timestamp(System.currentTimeMillis()); firstAdmin.created = new Timestamp(System.currentTimeMillis());
firstAdmin.defaultDeliveryAddress = new Address(); firstAdmin.defaultDeliveryAddress = new Address();
firstAdmin.defaultDeliveryAddress.name = "admin"; firstAdmin.defaultDeliveryAddress.name = "admin";
firstAdmin.defaultPayment = new PaymentMethod(); firstAdmin.defaultPayment = null;
firstAdmin.defaultPayment.creditCardNumber = ""; //set empty number
firstAdmin.email = "admin"; firstAdmin.email = "admin";
firstAdmin.isActive = true; firstAdmin.isActive = true;
firstAdmin.isEmployee = true; firstAdmin.isEmployee = true;

View File

@ -1,6 +1,5 @@
package org.hso.ecommerce.controller; package org.hso.ecommerce.controller;
import org.hso.ecommerce.entities.booking.PaymentMethod;
import org.hso.ecommerce.entities.shop.Address; import org.hso.ecommerce.entities.shop.Address;
import org.hso.ecommerce.entities.user.User; import org.hso.ecommerce.entities.user.User;
import org.hso.ecommerce.repos.user.UserRepository; import org.hso.ecommerce.repos.user.UserRepository;
@ -47,7 +46,7 @@ public class RegisterController {
newUser.email = username; newUser.email = username;
newUser.isEmployee = false; newUser.isEmployee = false;
newUser.salutation = salutation; newUser.salutation = salutation;
newUser.defaultPayment = PaymentMethod.fromCreditCardNumber(""); newUser.defaultPayment = null;
newUser.isActive = true; newUser.isActive = true;
newUser.created = new java.sql.Timestamp(System.currentTimeMillis()); newUser.created = new java.sql.Timestamp(System.currentTimeMillis());

View File

@ -140,6 +140,11 @@ public class ShopCheckoutController {
bookingRepository.saveAll(result.bookings); bookingRepository.saveAll(result.bookings);
warehouseBookingRepository.save(result.warehouseBooking); warehouseBookingRepository.save(result.warehouseBooking);
if (user.defaultPayment == null) {
user.defaultPayment = PaymentMethod.fromCreditCardNumber(cardnumber);
userRepository.save(user);
}
shoppingCart.clear(); shoppingCart.clear();
} catch (CreateOrderAction.ArticleNotInStockException e) { } catch (CreateOrderAction.ArticleNotInStockException e) {

View File

@ -97,6 +97,12 @@ Musterstraße 4
th:value="${user.defaultPayment != null ? user.defaultPayment.creditCardNumber : ''}" th:value="${user.defaultPayment != null ? user.defaultPayment.creditCardNumber : ''}"
pattern="[0-9]{6,16}" pattern="[0-9]{6,16}"
required/> required/>
<p th:if="${user.defaultPayment == null}" class="secondary card">
Da dies Ihre erste Bestellung ist, wird die Kreditkarte als Standartzahlungsmittel hinterlegt.
Sie kann unter den Nutzereinstellungen gelöscht oder geändert werden.
</p>
<small th:if="${user.defaultPayment != null}" class="no-padding">Die Standardkreditkarte kann unter
den <a href="/user/settings">Nutzereinstellungen</a> gelöscht oder geändert werden.</small>
</fieldset> </fieldset>
</div> </div>
<div> <div>

View File

@ -21,7 +21,7 @@
<main class="sidebar-layout content-width"> <main class="sidebar-layout content-width">
<nav th:replace="fragments/customer :: sidebar"></nav> <nav th:replace="fragments/customer :: sidebar"></nav>
<div class="content-width"> <div class="content-width">
<form method="POST" th:action="@{/user/settings/changeMail}"> <form class="detailflex" method="POST" th:action="@{/user/settings/changeMail}">
<div> <div>
<h2> Login Daten </h2> <h2> Login Daten </h2>
</div> </div>