Skip to content

Commit

Permalink
Merge pull request #51 from pagopa/fix-grand-total-amount-format
Browse files Browse the repository at this point in the history
fix: grand total amount format
  • Loading branch information
pasqualespica authored Jan 9, 2024
2 parents 4e8dd2a + 6522688 commit 68c6409
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

import static it.gov.pagopa.receipt.pdf.helpdesk.utils.BizEventToReceiptUtils.formatAmount;
import static it.gov.pagopa.receipt.pdf.helpdesk.utils.BizEventToReceiptUtils.getItemSubject;

public class BizEventToReceiptServiceImpl implements BizEventToReceiptService {
Expand Down Expand Up @@ -261,7 +263,7 @@ public Receipt createCartReceipt(List<BizEvent> bizEventList) {
public static BigDecimal getAmount(BizEvent bizEvent) {
if (bizEvent.getTransactionDetails() != null && bizEvent.getTransactionDetails().getTransaction() != null
&& bizEvent.getTransactionDetails().getTransaction().getGrandTotal() != 0) {
return new BigDecimal(bizEvent.getTransactionDetails().getTransaction().getGrandTotal());
return formatAmount(bizEvent.getTransactionDetails().getTransaction().getGrandTotal());
}
if (bizEvent.getPaymentInfo() != null && bizEvent.getPaymentInfo().getAmount() != null) {
return new BigDecimal(bizEvent.getPaymentInfo().getAmount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.slf4j.Logger;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -410,5 +411,11 @@ public static MassiveRecoverCartResult massiveRecoverCartByStatus(
.build();
}

public static BigDecimal formatAmount(long grandTotal) {
BigDecimal amount = new BigDecimal(grandTotal);
BigDecimal divider = new BigDecimal(100);
return amount.divide(divider, 2, RoundingMode.UNNECESSARY);
}

private BizEventToReceiptUtils() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ void requestWithValidCartSaveReceiptErrorInReviewed() throws ReceiptNotFoundExce
.build();
when(receiptCosmosClient.getReceiptError(BIZ_EVENT_ID)).thenReturn(receiptError);

when(request.getQueryParameters()).thenReturn(Collections.singletonMap("isCart","true"));

when(receiptCosmosClient.getCartDocument(any())).thenReturn(generateCart());

function = spy(new ReceiptToReviewed(receiptCosmosClient));

// test execution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ void recoverNotNotifiedCartReceiptSuccess() throws ReceiptNotFoundException, Car
return new HttpResponseMessageMock.HttpResponseMessageBuilderMock().status(status);
}).when(requestMock).createResponseBuilder(any(HttpStatus.class));

when(requestMock.getQueryParameters()).thenReturn(Collections.singletonMap("isCart","true"));

when(receiptCosmosServiceMock.getCart(any())).thenReturn(generateCart());

// test execution
HttpResponseMessage response = sut.run(requestMock, EVENT_ID, documentReceipts, executionContextMock);

Expand Down

0 comments on commit 68c6409

Please sign in to comment.