Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void callCreateDisputeRemotely(Dispute dispute) {
// validate
var invoicePayment = invoicingService.getInvoicePayment(dispute.getInvoiceId(), dispute.getPaymentId());
// validate
PaymentStatusValidator.checkStatus(invoicePayment);
PaymentStatusValidator.checkStatus(invoicePayment, true);
enrichPaymentRiskData(dispute, invoicePayment);
var providerData = providerDataService.getProviderData(dispute.getProviderId(), dispute.getTerminalId());
var providerStatus =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void process(Dispute dispute) {
// validate
var invoicePayment = invoicingService.getInvoicePayment(dispute.getInvoiceId(), dispute.getPaymentId());
// validate
PaymentStatusValidator.checkStatus(invoicePayment);
PaymentStatusValidator.checkStatus(invoicePayment, true);
var providerData = providerDataService.getProviderData(dispute.getProviderId(), dispute.getTerminalId());
disputesService.updateNextPollingInterval(dispute, providerData);
} catch (NotFoundException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void callPendingDisputeRemotely(Dispute dispute) {
// validate
var invoicePayment = invoicingService.getInvoicePayment(dispute.getInvoiceId(), dispute.getPaymentId());
// validate
PaymentStatusValidator.checkStatus(invoicePayment);
PaymentStatusValidator.checkStatus(invoicePayment, true);
var providerData = getProviderData(dispute);
var finishCheckDisputeStatusResult = (Consumer<DisputeStatusResult>) result -> {
switch (result.getSetField()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@
public class PaymentStatusValidator {

public static void checkStatus(InvoicePayment invoicePayment) {
checkStatus(invoicePayment, false);
}

public static void checkStatus(InvoicePayment invoicePayment, boolean allowPending) {
var invoicePaymentStatus = invoicePayment.getPayment().getStatus();
switch (invoicePaymentStatus.getSetField()) {
case CAPTURED -> throw new CapturedPaymentException(invoicePayment);
case FAILED, CANCELLED -> {
}
case PENDING -> {
if (!allowPending) {
throw new InvoicingPaymentStatusRestrictionsException(invoicePaymentStatus);
}
}
default -> throw new InvoicingPaymentStatusRestrictionsException(invoicePaymentStatus);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.vality.disputes.schedule.service;

import dev.vality.damsel.domain.InvoicePaymentCaptured;
import dev.vality.damsel.domain.InvoicePaymentPending;
import dev.vality.damsel.domain.InvoicePaymentRefunded;
import dev.vality.damsel.domain.InvoicePaymentStatus;
import dev.vality.disputes.config.AbstractMockitoConfig;
Expand Down Expand Up @@ -232,6 +233,32 @@ public void testSuccessWhenInvoicePaymentStatusIsCaptured() {
assertEquals(DisputeStatus.succeeded, disputeDao.get(disputeId).getStatus());
}

@Test
@SneakyThrows
public void testCreatedWhenInvoicePaymentStatusIsPending() {
var paymentId = "1";
var invoicePayment = createInvoicePayment(paymentId);
invoicePayment.getPayment().setStatus(InvoicePaymentStatus.pending(new InvoicePaymentPending()));
when(invoicingClient.getPayment(any(), any())).thenReturn(invoicePayment);
when(fileStorageClient.generateDownloadUrl(any(), any())).thenReturn(wiremockAddressesHolder.getDownloadUrl());
var terminal = createTerminal().get();
terminal.getOptions().putAll(getOptions());
when(dominantService.getTerminal(any())).thenReturn(terminal);
when(dominantService.getProvider(any())).thenReturn(createProvider().get());
when(dominantService.getProxy(any())).thenReturn(createProxy().get());
var providerMock = mock(ProviderDisputesServiceSrv.Client.class);
var providerDisputeId = UUID.randomUUID().toString();
when(providerMock.createDispute(any())).thenReturn(createDisputeCreatedSuccessResult(providerDisputeId));
when(providerDisputesThriftInterfaceBuilder.buildWoodyClient(any())).thenReturn(providerMock);
createdFlowHandler.mockFailStatusProviderPayment();
var invoiceId = "20McecNnWoy";
var disputeId = UUID.fromString(merchantApiMvcPerformer.createDispute(invoiceId, paymentId).getDisputeId());
var dispute = disputeDao.get(disputeId);
createdDisputesService.callCreateDisputeRemotely(dispute);
assertEquals(DisputeStatus.pending, disputeDao.get(disputeId).getStatus());
disputeDao.finishFailed(disputeId, null);
}

@Test
@SneakyThrows
public void createAdjustmentWhenSuccessStatusProviderPayment() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.vality.disputes.schedule.service;

import dev.vality.damsel.domain.InvoicePaymentCaptured;
import dev.vality.damsel.domain.InvoicePaymentPending;
import dev.vality.damsel.domain.InvoicePaymentRefunded;
import dev.vality.damsel.domain.InvoicePaymentStatus;
import dev.vality.disputes.config.AbstractMockitoConfig;
Expand Down Expand Up @@ -142,4 +143,20 @@ public void testSuccessWhenInvoicePaymentStatusIsCaptured() {
pendingDisputesService.callPendingDisputeRemotely(dispute);
assertEquals(DisputeStatus.succeeded, disputeDao.get(disputeId).getStatus());
}

@Test
@SneakyThrows
public void testPendingWhenInvoicePaymentStatusIsPending() {
var disputeId = createdFlowHandler.handleCreate();
var providerMock = mock(ProviderDisputesServiceSrv.Client.class);
when(providerMock.checkDisputeStatus(any())).thenReturn(createDisputeStatusPendingResult());
when(providerDisputesThriftInterfaceBuilder.buildWoodyClient(any())).thenReturn(providerMock);
var dispute = disputeDao.get(disputeId);
var invoicePayment = createInvoicePayment(dispute.getPaymentId());
invoicePayment.getPayment().setStatus(InvoicePaymentStatus.pending(new InvoicePaymentPending()));
when(invoicingClient.getPayment(any(), any())).thenReturn(invoicePayment);
pendingDisputesService.callPendingDisputeRemotely(dispute);
assertEquals(DisputeStatus.pending, disputeDao.get(disputeId).getStatus());
disputeDao.finishFailed(disputeId, null);
}
}
Loading