generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create service to process payment callbacks
- Loading branch information
1 parent
9f9a95c
commit 02984fc
Showing
6 changed files
with
80 additions
and
121 deletions.
There are no files selected for viewing
89 changes: 0 additions & 89 deletions
89
src/main/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerGenerateNotifications.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../hmcts/divorce/controller/dto/FeeDto.java → ...mcts/divorce/payment/callback/FeeDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/uk/gov/hmcts/divorce/payment/callback/PaymentCallbackService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package uk.gov.hmcts.divorce.payment.callback; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import uk.gov.hmcts.divorce.common.service.task.UpdateSuccessfulPaymentStatus; | ||
import uk.gov.hmcts.divorce.divorcecase.model.PaymentStatus; | ||
import uk.gov.hmcts.divorce.divorcecase.model.State; | ||
import uk.gov.hmcts.divorce.idam.IdamService; | ||
import uk.gov.hmcts.divorce.idam.User; | ||
import uk.gov.hmcts.divorce.systemupdate.service.CcdUpdateService; | ||
import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator; | ||
import uk.gov.hmcts.reform.ccd.client.CoreCaseDataApi; | ||
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails; | ||
|
||
import static uk.gov.hmcts.divorce.citizen.event.CitizenPaymentMade.CITIZEN_PAYMENT_MADE; | ||
import static uk.gov.hmcts.divorce.citizen.event.RespondentFinalOrderPaymentMade.RESPONDENT_FINAL_ORDER_PAYMENT_MADE; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class PaymentCallbackService { | ||
|
||
private final CcdUpdateService ccdUpdateService; | ||
|
||
private final IdamService idamService; | ||
|
||
private final AuthTokenGenerator authTokenGenerator; | ||
|
||
private final CoreCaseDataApi coreCaseDataApi; | ||
|
||
private final UpdateSuccessfulPaymentStatus updateSuccessfulPaymentStatus; | ||
|
||
public void handleCallback(PaymentCallbackDto paymentCallback) { | ||
User systemUpdateUser = idamService.retrieveSystemUpdateUserDetails(); | ||
final String serviceAuthorization = authTokenGenerator.generate(); | ||
|
||
if (!PaymentStatus.SUCCESS.getLabel().equals(paymentCallback.getStatus())) { | ||
log.info("Payment unsuccessful for case: {}, not processing callback", paymentCallback.getCcdCaseNumber()); | ||
} | ||
|
||
String caseReference = paymentCallback.getCcdCaseNumber(); | ||
CaseDetails details = coreCaseDataApi.getCase(systemUpdateUser.getAuthToken(), serviceAuthorization, caseReference); | ||
State state = State.valueOf(details.getState()); | ||
|
||
String paymentMadeEvent = paymentMadeEvent(state); | ||
|
||
if (paymentMadeEvent != null) { | ||
ccdUpdateService.submitEventWithRetry( | ||
caseReference, | ||
paymentMadeEvent(state), | ||
updateSuccessfulPaymentStatus, | ||
systemUpdateUser, | ||
serviceAuthorization | ||
); | ||
} else { | ||
log.info("Case not in awaiting payment state: {}, not processing callback", paymentCallback.getCcdCaseNumber()); | ||
} | ||
} | ||
|
||
private String paymentMadeEvent(State state) { | ||
switch(state) { | ||
case AwaitingPayment: | ||
return CITIZEN_PAYMENT_MADE; | ||
case AwaitingFinalOrderPayment: | ||
return RESPONDENT_FINAL_ORDER_PAYMENT_MADE; | ||
default: | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters