Skip to content

Commit

Permalink
Merge pull request #86 from pagopa/PAGOPA-1476-unknown-payment-manage…
Browse files Browse the repository at this point in the history
…ment

bug: [PagoPA-1476] unknown payment management
  • Loading branch information
alessio-acitelli authored Jan 31, 2024
2 parents 338f0c8 + 1b0f728 commit 645c843
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 134 deletions.
4 changes: 2 additions & 2 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: pagopa-gpd-payments
description: Microservice that exposes API for payment receipts retrieving and other operations
type: application
version: 0.65.0
appVersion: 0.12.5
version: 0.66.0
appVersion: 0.12.5-1-PAGOPA-1476-unknown-payment-management
dependencies:
- name: microservice-chart
version: 2.4.0
Expand Down
2 changes: 1 addition & 1 deletion helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-gpd-payments
tag: "0.12.5"
tag: "0.12.5-1-PAGOPA-1476-unknown-payment-management"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-gpd-payments
tag: "0.12.5"
tag: "0.12.5-1-PAGOPA-1476-unknown-payment-management"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-gpd-payments
tag: "0.12.5"
tag: "0.12.5-1-PAGOPA-1476-unknown-payment-management"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "PagoPA API Payments",
"description": "Payments",
"termsOfService": "https://www.pagopa.gov.it/",
"version": "0.12.5"
"version": "0.12.5-1-PAGOPA-1476-unknown-payment-management"
},
"servers": [
{
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>it.gov.pagopa</groupId>
<artifactId>payments</artifactId>
<version>0.12.5</version>
<version>0.12.5-1-PAGOPA-1476-unknown-payment-management</version>
<name>Payments</name>
<description>Payments</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ReceiptEntity {
private String iuv;
private String debtor;
private String paymentDateTime;
private String status = Status.CREATED.name();
private String status = Status.PAID.name();
private String document;

public ReceiptEntity(String organizationFiscalCode, String iuv){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

import lombok.Data;
import lombok.NoArgsConstructor;

Expand All @@ -12,7 +13,7 @@ public class PaymentOptionModelResponse implements Serializable {

/** generated serialVersionUID */
private static final long serialVersionUID = -3105963604242460898L;

private String iuv;
private String organizationFiscalCode;
private long amount;
Expand Down
242 changes: 117 additions & 125 deletions src/main/java/it/gov/pagopa/payments/service/PartnerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import feign.RetryableException;
import it.gov.pagopa.payments.endpoints.validation.exceptions.PartnerValidationException;
import it.gov.pagopa.payments.entity.ReceiptEntity;
import it.gov.pagopa.payments.entity.Status;
import it.gov.pagopa.payments.exception.AppError;
import it.gov.pagopa.payments.exception.AppException;
import it.gov.pagopa.payments.mapper.ConvertTableEntityToReceiptEntity;
Expand Down Expand Up @@ -665,24 +664,7 @@ private ReceiptEntity getReceipt(String organizationFiscalCode, String iuv)
return ConvertTableEntityToReceiptEntity.mapTableEntityToReceiptEntity(tableEntity);
} catch (TableServiceException e) {
log.error(DBERROR, e);
throw new AppException(AppError.DB_ERROR);
}
}

private void updateReceipt(ReceiptEntity receiptEntity)
throws InvalidKeyException, URISyntaxException, StorageException {
try {
TableEntity tableEntity =
tableClient.getEntity(receiptEntity.getOrganizationFiscalCode(), receiptEntity.getIuv());
Map<String, Object> properties = new HashMap<>();
properties.put(DEBTOR_PROPERTY, receiptEntity.getDebtor());
properties.put(DOCUMENT_PROPERTY, receiptEntity.getDocument());
properties.put(STATUS_PROPERTY, receiptEntity.getStatus());
properties.put(PAYMENT_DATE_PROPERTY, receiptEntity.getPaymentDateTime());
tableClient.updateEntity(tableEntity);
} catch (TableServiceException e) {
log.error(DBERROR, e);
throw new AppException(AppError.DB_ERROR);
if (e.getValue().getErrorCode() == TableErrorCode.RESOURCE_NOT_FOUND) return null; else throw new AppException(AppError.DB_ERROR);
}
}

Expand Down Expand Up @@ -761,101 +743,102 @@ private PaymentsModelResponse manageGetPaymentRequest(String idPa, CtQrCode qrCo
}

private PaymentOptionModelResponse managePaSendRtRequest(PaSendRTReq request) {
log.debug(
"[managePaSendRtRequest] save receipt [noticeNumber={}]",
request.getReceipt().getNoticeNumber());

ReceiptEntity receiptEntity =
this.getReceiptEntity(
request.getIdPA(),
request.getReceipt().getCreditorReferenceId(),
request.getReceipt().getDebtor(),
request.getReceipt().getPaymentDateTime().toString());
// save the receipt info with status CREATED
try {
receiptEntity.setDocument(this.marshal(request));
this.saveReceipt(receiptEntity);
} catch (InvalidKeyException | URISyntaxException | StorageException | JAXBException e) {
log.error(
"[managePaSendRtRequest] Generic Error in receipt saving [noticeNumber={}]",
request.getReceipt().getNoticeNumber(),
e);
throw new PartnerValidationException(PaaErrorEnum.PAA_SYSTEM_ERROR);
}

// GPD service works on IUVs directly, so we use creditorReferenceId (=IUV)
LocalDateTime paymentDateTime =
request.getReceipt().getPaymentDateTime() != null
? request
.getReceipt()
.getPaymentDateTime()
.toGregorianCalendar()
.toZonedDateTime()
.toLocalDateTime()
: null;
PaymentOptionModel body =
PaymentOptionModel.builder()
.idReceipt(request.getReceipt().getReceiptId())
.paymentDate(paymentDateTime)
.pspCompany(request.getReceipt().getPSPCompanyName())
.paymentMethod(request.getReceipt().getPaymentMethod())
.fee(String.valueOf(this.getFeeInCent(request.getReceipt().getFee())))
.build();
return this.getReceiptPaymentOption(
request.getReceipt().getNoticeNumber(),
request.getIdPA(),
request.getReceipt().getCreditorReferenceId(),
body,
receiptEntity);
log.debug(
"[managePaSendRtRequest] save receipt [noticeNumber={}]",
request.getReceipt().getNoticeNumber());

ReceiptEntity receiptEntity =
this.getReceiptEntity(
request.getIdPA(),
request.getReceipt().getCreditorReferenceId(),
request.getReceipt().getDebtor(),
request.getReceipt().getPaymentDateTime().toString());

try {
receiptEntity.setDocument(this.marshal(request));
} catch (JAXBException e) {
log.error(
"[managePaSendRtRequest] Error in receipt marshalling [noticeNumber={}]",
request.getReceipt().getNoticeNumber(),
e);
throw new PartnerValidationException(PaaErrorEnum.PAA_SYSTEM_ERROR);
}

LocalDateTime paymentDateTime =
request.getReceipt().getPaymentDateTime() != null
? request
.getReceipt()
.getPaymentDateTime()
.toGregorianCalendar()
.toZonedDateTime()
.toLocalDateTime()
: null;
PaymentOptionModel body =
PaymentOptionModel.builder()
.idReceipt(request.getReceipt().getReceiptId())
.paymentDate(paymentDateTime)
.pspCompany(request.getReceipt().getPSPCompanyName())
.paymentMethod(request.getReceipt().getPaymentMethod())
.fee(String.valueOf(this.getFeeInCent(request.getReceipt().getFee())))
.build();

// call to gpd: GPD service works on IUVs directly, so we use creditorReferenceId (=IUV)
return this.getReceiptPaymentOption(
request.getReceipt().getNoticeNumber(),
request.getIdPA(),
request.getReceipt().getCreditorReferenceId(),
body,
receiptEntity);
}

private PaymentOptionModelResponse managePaSendRtRequest(PaSendRTV2Request request) {
log.debug(
"[managePaSendRtRequest] save V2 receipt [noticeNumber={}]",
request.getReceipt().getNoticeNumber());

ReceiptEntity receiptEntity =
this.getReceiptEntity(
request.getIdPA(),
request.getReceipt().getCreditorReferenceId(),
request.getReceipt().getDebtor(),
request.getReceipt().getPaymentDateTime().toString());
// save the receipt info with status CREATED
try {
receiptEntity.setDocument(this.marshalV2(request));
this.saveReceipt(receiptEntity);
} catch (InvalidKeyException | URISyntaxException | StorageException | JAXBException e) {
log.error(
"[managePaSendRtRequest] Generic Error in receipt saving [noticeNumber={}]",
request.getReceipt().getNoticeNumber(),
e);
throw new PartnerValidationException(PaaErrorEnum.PAA_SYSTEM_ERROR);
}

// GPD service works on IUVs directly, so we use creditorReferenceId (=IUV)
LocalDateTime paymentDateTime =
request.getReceipt().getPaymentDateTime() != null
? request
.getReceipt()
.getPaymentDateTime()
.toGregorianCalendar()
.toZonedDateTime()
.toLocalDateTime()
: null;
PaymentOptionModel body =
PaymentOptionModel.builder()
.idReceipt(request.getReceipt().getReceiptId())
.paymentDate(paymentDateTime)
.pspCompany(request.getReceipt().getPSPCompanyName())
.paymentMethod(request.getReceipt().getPaymentMethod())
.fee(String.valueOf(this.getFeeInCent(request.getReceipt().getFee())))
.build();
return this.getReceiptPaymentOption(
request.getReceipt().getNoticeNumber(),
request.getIdPA(),
request.getReceipt().getCreditorReferenceId(),
body,
receiptEntity);
log.debug(
"[managePaSendRtRequest] save V2 receipt [noticeNumber={}]",
request.getReceipt().getNoticeNumber());

ReceiptEntity receiptEntity =
this.getReceiptEntity(
request.getIdPA(),
request.getReceipt().getCreditorReferenceId(),
request.getReceipt().getDebtor(),
request.getReceipt().getPaymentDateTime().toString());
try {
receiptEntity.setDocument(this.marshalV2(request));
} catch (JAXBException e) {
log.error(
"[managePaSendRtRequest] Error in receipt marshalling [noticeNumber={}]",
request.getReceipt().getNoticeNumber(),
e);
throw new PartnerValidationException(PaaErrorEnum.PAA_SYSTEM_ERROR);
}

LocalDateTime paymentDateTime =
request.getReceipt().getPaymentDateTime() != null
? request
.getReceipt()
.getPaymentDateTime()
.toGregorianCalendar()
.toZonedDateTime()
.toLocalDateTime()
: null;

PaymentOptionModel body =
PaymentOptionModel.builder()
.idReceipt(request.getReceipt().getReceiptId())
.paymentDate(paymentDateTime)
.pspCompany(request.getReceipt().getPSPCompanyName())
.paymentMethod(request.getReceipt().getPaymentMethod())
.fee(String.valueOf(this.getFeeInCent(request.getReceipt().getFee())))
.build();


// call to gpd: GPD service works on IUVs directly, so we use creditorReferenceId (=IUV)
return this.getReceiptPaymentOption(
request.getReceipt().getNoticeNumber(),
request.getIdPA(),
request.getReceipt().getCreditorReferenceId(),
body,
receiptEntity);
}

private ReceiptEntity getReceiptEntity(
Expand All @@ -872,37 +855,46 @@ private ReceiptEntity getReceiptEntity(
return receiptEntity;
}

private PaymentOptionModelResponse getReceiptPaymentOption(
String noticeNumber,
String idPa,
String creditorReferenceId,
PaymentOptionModel body,
ReceiptEntity receiptEntity) {
private PaymentOptionModelResponse getReceiptPaymentOption(String noticeNumber,
String idPa,
String creditorReferenceId,
PaymentOptionModel body,
ReceiptEntity receiptEntity) {
PaymentOptionModelResponse paymentOption = new PaymentOptionModelResponse();
try {
paymentOption = gpdClient.receiptPaymentOption(idPa, creditorReferenceId, body);
// update receipt status to PAID
// creates the PAID receipt
if (PaymentOptionStatus.PO_PAID.equals(paymentOption.getStatus())) {
receiptEntity.setStatus(Status.PAID.name());
this.updateReceipt(receiptEntity);
this.saveReceipt(receiptEntity);
}
} catch (FeignException.Conflict e) {
// if PO is already paid on GPD --> checks and in case creates the receipt in PAID status
try {
log.error(
"[getReceiptPaymentOption] GPD Conflict Error Response [noticeNumber={}]",
noticeNumber,
e);
ReceiptEntity receiptEntityToUpdate = this.getReceipt(idPa, creditorReferenceId);
receiptEntityToUpdate.setStatus(Status.PAID.name());
this.updateReceipt(receiptEntityToUpdate);
ReceiptEntity receiptEntityToCreate = this.getReceipt(idPa, creditorReferenceId);
if (null == receiptEntityToCreate){
// if no receipt found --> save the with PAID receipt
this.saveReceipt(receiptEntity);
}
} catch (Exception ex) {
log.error(
"[getReceiptPaymentOption] GPD Generic Error [noticeNumber={}] during receipt status"
+ " update",
noticeNumber,
+ " save",
noticeNumber,
e);
}
throw new PartnerValidationException(PaaErrorEnum.PAA_RECEIPT_DUPLICATA);
} catch (FeignException.NotFound e) {
log.error(
"[getReceiptPaymentOption] GPD Not Found Error Response [noticeNumber={}]",
noticeNumber,
e);
throw new PartnerValidationException(PaaErrorEnum.PAA_PAGAMENTO_SCONOSCIUTO);
} catch (PartnerValidationException e) {
throw e;
} catch (RetryableException e) {
log.error("[getReceiptPaymentOption] GPD Not Reachable [noticeNumber={}]", noticeNumber, e);
throw new PartnerValidationException(PaaErrorEnum.PAA_SYSTEM_ERROR);
Expand Down
Loading

0 comments on commit 645c843

Please sign in to comment.