Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [PagoPa-1763] - transaction response adjustment #61

Merged
merged 6 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,914 changes: 1,431 additions & 1,483 deletions openapi/openapi.json

Large diffs are not rendered by default.

1,067 changes: 502 additions & 565 deletions openapi/openapi_ec.json

Large diffs are not rendered by default.

1,436 changes: 697 additions & 739 deletions openapi/openapi_helpdesk.json

Large diffs are not rendered by default.

1,217 changes: 584 additions & 633 deletions openapi/openapi_io.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand All @@ -12,7 +11,8 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import it.gov.pagopa.bizeventsservice.model.ProblemJson;
import it.gov.pagopa.bizeventsservice.model.response.transaction.TransactionDetailResponse;
import it.gov.pagopa.bizeventsservice.model.response.transaction.TransactionListItem;
import it.gov.pagopa.bizeventsservice.model.response.transaction.TransactionListWrapResponse;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
Expand All @@ -25,7 +25,6 @@

import javax.validation.constraints.NotBlank;

import java.util.List;

@Tag(name = "IO Transactions REST APIs")
@RequestMapping("/transactions")
Expand All @@ -48,14 +47,14 @@ public interface ITransactionController {
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Obtained transaction list.",
headers = @Header(name = X_CONTINUATION_TOKEN, description = "continuation token for paginated query", schema = @Schema(type="string")),
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, array = @ArraySchema(schema = @Schema(name = "TransactionListItem", implementation = TransactionListItem.class)))),
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(name = "TransactionListWrapResponse", implementation = TransactionListWrapResponse.class))),
@ApiResponse(responseCode = "401", description = "Wrong or missing function key.", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "404", description = "Not found the transaction.", content = @Content(schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "429", description = "Too many requests.", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "500", description = "Service unavailable.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))})
@Operation(summary = "Retrieve the paged transaction list from biz events.", security = {
@SecurityRequirement(name = "ApiKey")}, operationId = "getTransactionList")
ResponseEntity<List<TransactionListItem>> getTransactionList(
ResponseEntity<TransactionListWrapResponse> getTransactionList(
@RequestHeader(name = X_FISCAL_CODE) String fiscalCode,
@RequestHeader(name = X_CONTINUATION_TOKEN, required = false) String continuationToken,
@RequestParam(name = PAGE_SIZE, required = false, defaultValue = "10") Integer size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import it.gov.pagopa.bizeventsservice.client.IReceiptPDFClient;
import it.gov.pagopa.bizeventsservice.controller.ITransactionController;
import it.gov.pagopa.bizeventsservice.exception.AppException;
import it.gov.pagopa.bizeventsservice.model.response.transaction.TransactionListItem;
import it.gov.pagopa.bizeventsservice.model.response.AttachmentsDetailsResponse;
import it.gov.pagopa.bizeventsservice.model.response.transaction.TransactionDetailResponse;
import it.gov.pagopa.bizeventsservice.model.response.transaction.TransactionListResponse;
import it.gov.pagopa.bizeventsservice.model.response.transaction.TransactionListWrapResponse;
import it.gov.pagopa.bizeventsservice.service.IBizEventsService;
import it.gov.pagopa.bizeventsservice.service.ITransactionService;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -17,8 +17,6 @@

import feign.FeignException;

import java.util.List;

import javax.validation.constraints.NotBlank;

/**
Expand All @@ -40,13 +38,13 @@ public TransactionController(ITransactionService transactionService, IBizEventsS
}

@Override
public ResponseEntity<List<TransactionListItem>> getTransactionList(
public ResponseEntity<TransactionListWrapResponse> getTransactionList(
String fiscalCode, String continuationToken, Integer size) {
TransactionListResponse transactionListResponse = transactionService.getTransactionList(fiscalCode, continuationToken, size);

return ResponseEntity.ok()
.header(X_CONTINUATION_TOKEN, transactionListResponse.getContinuationToken())
.body(transactionListResponse.getTransactionList());
.body(TransactionListWrapResponse.builder().transactions(transactionListResponse.getTransactionList()).build());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public class BizEventsViewUser {
private String transactionDate;
private Boolean hidden;
private Boolean isPayer;
private Boolean isDebtor;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(Include.NON_NULL)
public class WalletInfo implements Serializable {

private String accountHolder;
/**
*
*/
private static final long serialVersionUID = -6409303257722729484L;
private String accountHolder;
private String brand;
private String blurredNumber;
private String maskedEmail;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import it.gov.pagopa.bizeventsservice.entity.view.BizEventsViewGeneral;
import it.gov.pagopa.bizeventsservice.entity.view.BizEventsViewUser;
import it.gov.pagopa.bizeventsservice.model.response.transaction.CartItem;
import it.gov.pagopa.bizeventsservice.model.response.transaction.InfoTransaction;
import it.gov.pagopa.bizeventsservice.model.response.transaction.InfoTransactionView;
import it.gov.pagopa.bizeventsservice.util.DateValidator;
import it.gov.pagopa.bizeventsservice.model.response.transaction.*;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -36,10 +37,10 @@ public void setPayeeCartName(String payeeCartNameValue){
payeeCartName = payeeCartNameValue;
}

public static TransactionDetailResponse convertTransactionDetails(BizEventsViewGeneral bizEventsViewGeneral, List<BizEventsViewCart> listOfCartViews) {
public static TransactionDetailResponse convertTransactionDetails(String taxCode, BizEventsViewGeneral bizEventsViewGeneral, List<BizEventsViewCart> listOfCartViews) {
List<CartItem> listOfCartItems = new ArrayList<>();
AtomicReference<BigDecimal> totalAmount = new AtomicReference<>(BigDecimal.ZERO);

for (BizEventsViewCart bizEventsViewCart : listOfCartViews) {

listOfCartItems.add(
Expand All @@ -55,20 +56,22 @@ public static TransactionDetailResponse convertTransactionDetails(BizEventsViewG
BigDecimal amountExtracted = new BigDecimal(bizEventsViewCart.getAmount());
totalAmount.updateAndGet(v -> v.add(amountExtracted));
}


// PAGOPA-1763: if the tax code refers to a debtor, do not show the sections relating to the payer
boolean isDebtor = !bizEventsViewGeneral.getPayer().getTaxCode().equals(taxCode);
return TransactionDetailResponse.builder()
.infoTransaction(
InfoTransaction.builder()
InfoTransactionView.builder()
.transactionId(bizEventsViewGeneral.getTransactionId())
.authCode(bizEventsViewGeneral.getAuthCode())
.rrn(bizEventsViewGeneral.getRrn())
.transactionDate(dateFormatZoned(bizEventsViewGeneral.getTransactionDate()))
.pspName(bizEventsViewGeneral.getPspName())
.walletInfo(bizEventsViewGeneral.getWalletInfo())
.payer(bizEventsViewGeneral.getPayer())
.walletInfo(isDebtor ? null:bizEventsViewGeneral.getWalletInfo())
.payer(isDebtor ? null:bizEventsViewGeneral.getPayer())
.amount(currencyFormat(totalAmount.get().toString()))
.fee(bizEventsViewGeneral.getFee())
.paymentMethod(bizEventsViewGeneral.getPaymentMethod())
.paymentMethod(isDebtor ? null:bizEventsViewGeneral.getPaymentMethod())
.origin(bizEventsViewGeneral.getOrigin())
.build()
)
Expand All @@ -82,14 +85,17 @@ public static TransactionListItem convertTransactionListItem(BizEventsViewUser v
BigDecimal amountExtracted = new BigDecimal(bizEventsViewCart.getAmount());
totalAmount.updateAndGet(v -> v.add(amountExtracted));
}

return TransactionListItem.builder()
.transactionId(viewUser.getTransactionId())
.payeeName(listOfCartViews.size() > 1 ? payeeCartName : listOfCartViews.get(0).getPayee().getName())
.payeeTaxCode(listOfCartViews.size() > 1 ? "" : listOfCartViews.get(0).getPayee().getTaxCode())
.amount(currencyFormat(totalAmount.get().toString()))
// PAGOPA-1763: the amount value must be returned only if it is not a cart type transaction
.amount(listOfCartViews.size() > 1 ? null : currencyFormat(totalAmount.get().toString()))
.transactionDate(dateFormatZoned(viewUser.getTransactionDate()))
.isCart(listOfCartViews.size() > 1)
.isPayer(viewUser.getIsPayer())
.isPayer(BooleanUtils.isTrue(viewUser.getIsPayer()))
.isDebtor(BooleanUtils.isTrue(viewUser.getIsDebtor()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

/**
* Response model for transaction detail API
*/
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class InfoTransaction implements Serializable {
private String transactionId;
@JsonInclude(Include.NON_NULL)
public class InfoTransactionView implements Serializable {
/**
*
*/
private static final long serialVersionUID = -3548526079754223084L;
private String transactionId;
private String authCode;
private String rrn;
private String transactionDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
@AllArgsConstructor
public class TransactionDetailResponse implements Serializable {

private InfoTransaction infoTransaction;
/**
*
*/
private static final long serialVersionUID = 4998486115671575833L;
private InfoTransactionView infoTransaction;
private List<CartItem> carts;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

/**
* Response model for transaction list API
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@JsonInclude(Include.NON_NULL)
public class TransactionListItem implements Serializable {
/**
*
Expand All @@ -26,4 +30,6 @@ public class TransactionListItem implements Serializable {
private String transactionDate;
private Boolean isCart;
private Boolean isPayer;
@Builder.Default
private Boolean isDebtor = false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package it.gov.pagopa.bizeventsservice.model.response.transaction;

import lombok.Builder;
import lombok.Getter;

import java.util.List;

@Builder
@Getter
public class TransactionListWrapResponse {
private List<TransactionListItem> transactions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public TransactionListResponse getTransactionList(
TransactionListItem transactionListItem = ConvertViewsToTransactionDetailResponse.convertTransactionListItem(viewUser, listOfViewCart);
listOfTransactionListItem.add(transactionListItem);
}
//TODO handle error in case a transaction is invalid (empty)
}

CosmosPageRequest pageResponse = (CosmosPageRequest) page.getPageable().next();
Expand Down Expand Up @@ -93,7 +92,7 @@ public TransactionDetailResponse getTransactionDetails(String taxCode, String ev
throw new AppException(AppError.VIEW_CART_NOT_FOUND_WITH_TRANSACTION_ID_AND_TAX_CODE, eventReference);
}

return ConvertViewsToTransactionDetailResponse.convertTransactionDetails(bizEventsViewGeneral.get(0), listOfCartViews);
return ConvertViewsToTransactionDetailResponse.convertTransactionDetails(taxCode, bizEventsViewGeneral.get(0), listOfCartViews);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ void taxCodeWithEventsAndMultipleCartItemsShouldReturnTransactionList() {
Assertions.assertEquals(listOfViewUser.size(), transactionListItems.size());

for(TransactionListItem listItem : transactionListItems){
Assertions.assertEquals(ViewGenerator.FORMATTED_GRAND_TOTAL, listItem.getAmount());
// PAGOPA-1763: the amount value must be returned only if it is not a cart type transaction
Assertions.assertTrue(listItem.getIsCart() ? listItem.getAmount()==null:listItem.getAmount().equals(ViewGenerator.FORMATTED_GRAND_TOTAL));
Assertions.assertEquals(payeeCartName, listItem.getPayeeName());
Assertions.assertEquals("", listItem.getPayeeTaxCode());
}
Expand Down Expand Up @@ -140,7 +141,7 @@ void idAndTaxCodeWithOneEventShouldReturnTransactionDetails() {

BizEventsViewGeneral viewGeneral = generalViewList.get(0);
Assertions.assertNotNull(transactionDetailResponse);
InfoTransaction infoTransaction = transactionDetailResponse.getInfoTransaction();
InfoTransactionView infoTransaction = transactionDetailResponse.getInfoTransaction();
Assertions.assertEquals(viewGeneral.getTransactionId(), infoTransaction.getTransactionId());
Assertions.assertEquals(viewGeneral.getAuthCode(), infoTransaction.getAuthCode());
Assertions.assertEquals(viewGeneral.getRrn(), infoTransaction.getRrn());
Expand All @@ -149,6 +150,7 @@ void idAndTaxCodeWithOneEventShouldReturnTransactionDetails() {
Assertions.assertEquals(viewGeneral.getWalletInfo().getAccountHolder(), infoTransaction.getWalletInfo().getAccountHolder());
Assertions.assertEquals(viewGeneral.getWalletInfo().getBrand(), infoTransaction.getWalletInfo().getBrand());
Assertions.assertEquals(viewGeneral.getWalletInfo().getBlurredNumber(), infoTransaction.getWalletInfo().getBlurredNumber());
Assertions.assertEquals(viewGeneral.getWalletInfo().getMaskedEmail(), infoTransaction.getWalletInfo().getMaskedEmail());
Assertions.assertEquals(viewGeneral.getPayer().getName(), infoTransaction.getPayer().getName());
Assertions.assertEquals(viewGeneral.getPayer().getTaxCode(), infoTransaction.getPayer().getTaxCode());
Assertions.assertEquals(ViewGenerator.FORMATTED_AMOUNT, infoTransaction.getAmount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ViewGenerator {
public static final String BRAND = "brand";
public static final String ACCOUNT_HOLDER = "accountHolder";
public static final String BLURRED_NUMBER = "blurredNumber";
public static final String MASKED_EMAIL = "[email protected]";
public static final String PAYER_NAME = "payerName";
public static final String EVENT_ID = "eventId";
public static final String SUBJECT = "subject";
Expand All @@ -36,6 +37,7 @@ public static BizEventsViewUser generateBizEventsViewUser(){
.transactionId(TRANSACTION_ID)
.transactionDate(TRANSACTION_DATE)
.hidden(false)
.isPayer(Boolean.FALSE)
.build();
}

Expand All @@ -61,6 +63,7 @@ public static BizEventsViewGeneral generateBizEventsViewGeneral(){
.brand(BRAND)
.accountHolder(ACCOUNT_HOLDER)
.blurredNumber(BLURRED_NUMBER)
.maskedEmail(MASKED_EMAIL)
.build())
.payer(UserDetail.builder()
.name(PAYER_NAME)
Expand Down
Loading