Skip to content

Commit

Permalink
payment feature - part 4 : order detail page for payment confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpochat committed Jul 29, 2021
1 parent 71ec13c commit 5b33139
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/**/.vscode
/**/target
/**/*.log
.env
TODO
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public Payment createPayment(Account account, Order order) {
*/
private MolliePaymentTransaction createMolliePaymentTransaction(Payment payment, Account account){
RestTemplate restTemplate = new RestTemplate();
//restTemplate.setInterceptors(List.of(new RestTemplateLoggingInterceptor()));
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.add(HttpHeaders.AUTHORIZATION, String.format("Bearer %s", paymentConfig.getMolliePaymentAPIKey()));
MolliePaymentTransaction transaction = getMolliePaymentTransaction(payment, account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public enum AnimalBreed {
BEEF_LIMOUSIN,
BEEF_CHAROLLAIS;
BEEF_CHAROLAIS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.localeat.core.domains.farm.Farm;
import com.localeat.core.domains.farm.FarmRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -67,7 +66,7 @@ public void getAllSlaughters() throws Exception {
Farm farm2 = farmRepository.findById(2L).orElse(null);
var animal1 = GenericBuilder.of(Animal::new)
.with(Animal::setAnimalType, AnimalType.BEEF_HEIFER)
.with(Animal::setBreed, AnimalBreed.BEEF_CHAROLLAIS)
.with(Animal::setBreed, AnimalBreed.BEEF_CHAROLAIS)
.with(Animal::setFinalFarm, farm1)
.with(Animal::setIdentificationNumber, "ABCD")
.build();
Expand Down Expand Up @@ -107,7 +106,7 @@ public void getAllSlaughters() throws Exception {
" \"id\" : 1,\n" +
" \"animal\" : {\n" +
" \"id\" : 1,\n" +
" \"breed\" : \"BEEF_CHAROLLAIS\",\n" +
" \"breed\" : \"BEEF_CHAROLAIS\",\n" +
" \"animalType\" : \"BEEF_HEIFER\",\n" +
" \"liveWeight\" : 0.0,\n" +
" \"meatWeight\" : 0.0,\n" +
Expand Down Expand Up @@ -152,7 +151,7 @@ public void createSlaughter() throws Exception {
var requestBody = "{\n" +
" \"animal\" : {\n" +
" \"animalType\" : \"BEEF_VEAL\",\n" +
" \"animalBreed\" : \"BEEF_CHAROLLAIS\",\n" +
" \"animalBreed\" : \"BEEF_CHAROLAIS\",\n" +
" \"finalFarm\" : {\"id\" : 2},\n" +
" \"identificationNumber\" : \"ABCD\"\n" +
" },\n" +
Expand Down
20 changes: 10 additions & 10 deletions docker-compose-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ services:
database:
image: postgres:12.2-alpine
volumes:
- <path_to_postgres_datafile_folder_on_real_server>:/var/lib/postgresql/data/pgdata
- ${postgres_datafile_path}:/var/lib/postgresql/data/pgdata
environment:
- POSTGRES_USER=localeat
- POSTGRES_PASSWORD=<password>
- POSTGRES_PASSWORD=${postgres_password}
- PGDATA=/var/lib/postgresql/data/pgdata
ports:
- <published_postgres_port>:5432
- ${postgres_port}:5432

core:
image: benjaminpochat/localeat-core:${DOCKER_IMAGE_TAG:-latest}
Expand All @@ -19,20 +19,20 @@ services:
environment:
- spring_datasource_url=jdbc:postgresql://database:5432/localeat
- spring_datasource_username=localeat
- spring_datasource_password=<password>
- spring_datasource_password=${postgres_password}
- spring_jpa_properties_hibernate_dialect=org.hibernate.dialect.PostgresPlusDialect
- [email protected]
- localeat_smtp_password=localeat
- localeat_http_domainname=<domain_name_for_localeat_server>
- localeat.payment.molliepaymentapikey=<mollie_api_key>
- localeat_smtp_password=${smtp_password}
- localeat_http_domainname=${domain_name}
- localeat_payment_molliepaymentapikey=${mollie_api_key}
ports:
- <published_backend_port>:8080
- ${backend_port}:8080

ui:
image: benjaminpochat/localeat-ui:${DOCKER_IMAGE_TAG:-latest}
depends_on:
- core
volumes:
- <path_to_folder_containing_localeat_ui_config_file_on_real_server>:/usr/local/apache2/htdocs/assets/config
- ${frontend_config_file_path}:/usr/local/apache2/htdocs/assets/config
ports:
- <published_frontend_port>:80
- ${frontend_port}:80
2 changes: 1 addition & 1 deletion scripts/dev/run-database-dev.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker-compose -f docker-compose-build.yml run database
docker-compose -f docker-compose-run.yml run --service-ports database
6 changes: 3 additions & 3 deletions ui/src/app/commons/models/animal-breed.model.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export enum AnimalBreed {
BeefLimousin = 'BEEF_LIMOUSIN',
BeefCharollais = 'BEEF_CHAROLAIS'
BeefCharolais = 'BEEF_CHAROLAIS'
}

export class AnimalBreedUtils {
public static getAnimalBreedLabel(breed: AnimalBreed): string {
switch (breed) {
case AnimalBreed.BeefCharollais:
return 'Charollaise';
case AnimalBreed.BeefCharolais:
return 'Charolaise';
case AnimalBreed.BeefLimousin:
return 'Limousine';
default:
Expand Down
18 changes: 18 additions & 0 deletions ui/src/app/commons/models/order-status.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,21 @@ export enum OrderStatus {
DELIVERED = "DELIVERED",
CANCELLED = "CANCELLED"
}


export class OrderStatusUtils {
static getOrderStatusLabel(orderStatus: OrderStatus) {
switch (orderStatus) {
case OrderStatus.BOOKED:
return 'réservée';
case OrderStatus.PAYED:
return 'payée';
case OrderStatus.DELIVERED:
return 'livrée';
case OrderStatus.CANCELLED:
return 'annulée';
default:
return '';
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.order__title {
top: 0;
z-index: 3;
background-color: darkolivegreen;
color: white;
font-family: "Acme";
padding-left: 1rem;
}

.order__title-text {
font-size: var(--main-menu-font-size);
}

.order__subtitle > div {
padding-right: 0.6rem;
}

.order__paragraph {
padding: 0.4rem;
}

.order__subtitle {
font-family: "Acme";
display: flex;
flex-wrap: wrap;
}

.order__status_cancelled {
color: darkred;
}

.order__status_booked {
color: orangered;
}

.order__status_validated {
color: olivedrab;
}
Original file line number Diff line number Diff line change
@@ -1 +1,61 @@
<p>Commande n° {{order.id}} pour la livraison du {{order.delivery.deliveryStart | date: 'shortDate'}}</p>
<div class="order__title">
<div class="order__title-text">Votre commande de viande</div>
<div class="order__subtitle">
<div>Livraison du {{order.delivery.deliveryStart | date: 'shortDate'}}</div>
<div>{{order.delivery.deliveryAddress.name}}</div>
</div>
</div>

<div class="order__paragraph">
<div class="order__subtitle">Statut de la commande</div>
<div>{{getStatusLabel()}}</div>
<div *ngIf="isStatusCancelled()" class="order__status_cancelled">Votre commande a été annulée</div>
<div *ngIf="isStatusBooked()" class="order__status_booked">Votre commande n'est pas encore validée. Elle sera annulée si le paiement n'est pas finalisé.</div>
<div *ngIf="isStatusValidated()" class="order__status_validated">Merci de votre confiance !</div>
</div>

<div *ngIf="isStatusValidated()" class="order__paragraph">
<div class="order__subtitle">
Date de la livraison
</div>
<div>
le {{order.delivery.deliveryStart | date: 'shortDate'}} entre {{order.delivery.deliveryStart | date: 'shortTime'}} et {{order.delivery.deliveryEnd | date: 'shortTime'}}
</div>
</div>

<div *ngIf="isStatusValidated()" class="order__paragraph">
<div class="order__subtitle">
Adresse de la livraison :
</div>
<div>
<ul><li *ngFor="let addressElement of getDeliveryAddressElements()">{{addressElement}}</li></ul>
</div>
</div>

<div *ngIf="isStatusValidated()" class="order__paragraph">
<div class="order__subtitle">
Montant de la commande
</div>
<div>{{getTotalPrice() | number: '0.2-2'}} €TTC</div>
</div>

<div *ngIf="isStatusValidated()" class="order__paragraph">
<div class="order__subtitle">
Colis commandés
</div>
<div>
<ul>
<li *ngFor="let orderItem of order.orderedItems">
<div>Type de colis : {{orderItem.batch.product.name}}</div>
<div>Description : {{orderItem.batch.product.description}}</div>
<div>Poids net : {{orderItem.batch.product.netWeight}} kg</div>
<div>Quantité commandée : {{orderItem.quantity}}</div>
</li>
</ul>
</div>
</div>

<div class="order__paragraph">
<button mat-flat-button color="accent" (click)="goHome()">Revenir à l'accueil</button>
<button mat-flat-button (click)="print()">Imprimer cette page</button>
</div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { OrderStatus, OrderStatusUtils } from 'src/app/commons/models/order-status.model';
import { Order } from 'src/app/commons/models/order.model';
import { OrderService } from '../../services/order.service';

Expand All @@ -22,4 +23,43 @@ export class OrderDetailsComponent implements OnInit {
this.orderService.getOrder(routeParams.get('orderId')).subscribe(order => this.order = order);
}

getStatusLabel(): string {
return OrderStatusUtils.getOrderStatusLabel(this.order.status);
}

isStatusValidated(): boolean {
return (OrderStatus.PAYED === this.order.status) || (OrderStatus.DELIVERED === this.order.status);
}

isStatusCancelled(): boolean {
return OrderStatus.CANCELLED === this.order.status;
}

isStatusBooked(): boolean {
return OrderStatus.BOOKED === this.order.status;
}

getTotalPrice(): number {
return this.orderService.getTotalPrice(this.order);
}

getDeliveryAddressElements(): string[] {
return [
this.order.delivery.deliveryAddress.name,
this.order.delivery.deliveryAddress.addressLine1,
this.order.delivery.deliveryAddress.addressLine2,
this.order.delivery.deliveryAddress.addressLine3,
this.order.delivery.deliveryAddress.addressLine4,
this.order.delivery.deliveryAddress.zipCode,
this.order.delivery.deliveryAddress.city
].filter(addressElement => addressElement && (addressElement.length > 0));
}

goHome(): void {
window.location.replace('./customer-area');
}

print(): void {
window.print();
}
}

0 comments on commit 5b33139

Please sign in to comment.