mirror of
https://github.com/valitydev/hooker.git
synced 2024-11-06 08:15:17 +00:00
HOOK-78: Error mapping (#52)
* HOOK-78: Error mapping * Added test ErrorUtils
This commit is contained in:
parent
0c5db49ce6
commit
7c487a3f8f
6
pom.xml
6
pom.xml
@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>hooker</artifactId>
|
||||
<version>2.0.7-SNAPSHOT</version>
|
||||
<version>2.0.8-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>hooker</name>
|
||||
@ -22,7 +22,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<postgresql.jdbc.version>9.4.1212</postgresql.jdbc.version>
|
||||
<dockerfile.base.service.tag>22c57470c4fc47161894f036b7cf9d70f42b75f5</dockerfile.base.service.tag>
|
||||
<damsel.version>1.222-17857b0</damsel.version>
|
||||
<damsel.version>1.228-b0806eb</damsel.version>
|
||||
<shared.resources.version>0.2.1</shared.resources.version>
|
||||
|
||||
<db.host.name>db-pg-shared</db.host.name>
|
||||
@ -142,7 +142,7 @@
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>swag-webhook-events</artifactId>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
<version>1.0.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney.logback</groupId>
|
||||
|
@ -10,7 +10,6 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcDaoSupport;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -7,6 +7,7 @@ import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.Invoice;
|
||||
import com.rbkmoney.hooker.model.Payment;
|
||||
import com.rbkmoney.hooker.model.PaymentContactInfo;
|
||||
import com.rbkmoney.hooker.utils.ErrorUtils;
|
||||
import com.rbkmoney.hooker.utils.PaymentToolUtils;
|
||||
import com.rbkmoney.swag_webhook_events.*;
|
||||
import org.slf4j.Logger;
|
||||
@ -23,9 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.sql.DataSource;
|
||||
import java.util.*;
|
||||
|
||||
import static com.rbkmoney.hooker.handler.poller.impl.invoicing.AbstractInvoiceEventHandler.INVOICE;
|
||||
import static com.rbkmoney.hooker.handler.poller.impl.invoicing.AbstractInvoiceEventHandler.PAYMENT;
|
||||
import static com.rbkmoney.hooker.handler.poller.impl.invoicing.AbstractInvoiceEventHandler.REFUND;
|
||||
import static com.rbkmoney.hooker.handler.poller.impl.invoicing.AbstractInvoiceEventHandler.*;
|
||||
import static com.rbkmoney.hooker.utils.PaymentToolUtils.getPaymentToolDetails;
|
||||
|
||||
public class InvoicingMessageDaoImpl extends NamedParameterJdbcDaoSupport implements InvoicingMessageDao {
|
||||
@ -61,8 +60,8 @@ public class InvoicingMessageDaoImpl extends NamedParameterJdbcDaoSupport implem
|
||||
public static final String PAYMENT_ID = "payment_id";
|
||||
public static final String PAYMENT_CREATED_AT = "payment_created_at";
|
||||
public static final String PAYMENT_STATUS = "payment_status";
|
||||
public static final String PAYMENT_ERROR_CODE = "payment_error_code";
|
||||
public static final String PAYMENT_ERROR_MESSAGE = "payment_error_message";
|
||||
public static final String PAYMENT_FAILURE = "payment_failure";
|
||||
public static final String PAYMENT_FAILURE_REASON = "payment_failure_reason";
|
||||
public static final String PAYMENT_AMOUNT = "payment_amount";
|
||||
public static final String PAYMENT_CURRENCY = "payment_currency";
|
||||
public static final String PAYMENT_TOOL_TOKEN = "payment_tool_token";
|
||||
@ -82,8 +81,8 @@ public class InvoicingMessageDaoImpl extends NamedParameterJdbcDaoSupport implem
|
||||
public static final String REFUND_ID = "refund_id";
|
||||
public static final String REFUND_CREATED_AT = "refund_created_at";
|
||||
public static final String REFUND_STATUS = "refund_status";
|
||||
public static final String REFUND_ERROR_CODE = "refund_error_code";
|
||||
public static final String REFUND_ERROR_MESSAGE = "refund_error_message";
|
||||
public static final String REFUND_FAILURE = "refund_failure";
|
||||
public static final String REFUND_FAILURE_REASON = "refund_failure_reason";
|
||||
public static final String REFUND_AMOUNT = "refund_amount";
|
||||
public static final String REFUND_CURRENCY = "refund_currency";
|
||||
public static final String REFUND_REASON = "refund_reason";
|
||||
@ -93,8 +92,8 @@ public class InvoicingMessageDaoImpl extends NamedParameterJdbcDaoSupport implem
|
||||
params.addValue(PAYMENT_ID, null)
|
||||
.addValue(PAYMENT_CREATED_AT, null)
|
||||
.addValue(PAYMENT_STATUS, null)
|
||||
.addValue(PAYMENT_ERROR_CODE, null)
|
||||
.addValue(PAYMENT_ERROR_MESSAGE, null)
|
||||
.addValue(PAYMENT_FAILURE, null)
|
||||
.addValue(PAYMENT_FAILURE_REASON, null)
|
||||
.addValue(PAYMENT_AMOUNT, null)
|
||||
.addValue(PAYMENT_CURRENCY, null)
|
||||
.addValue(PAYMENT_TOOL_TOKEN, null)
|
||||
@ -114,8 +113,8 @@ public class InvoicingMessageDaoImpl extends NamedParameterJdbcDaoSupport implem
|
||||
.addValue(REFUND_ID, null)
|
||||
.addValue(REFUND_CREATED_AT, null)
|
||||
.addValue(REFUND_STATUS, null)
|
||||
.addValue(REFUND_ERROR_CODE, null)
|
||||
.addValue(REFUND_ERROR_MESSAGE, null)
|
||||
.addValue(REFUND_FAILURE, null)
|
||||
.addValue(REFUND_FAILURE_REASON, null)
|
||||
.addValue(REFUND_AMOUNT, null)
|
||||
.addValue(REFUND_CURRENCY, null)
|
||||
.addValue(REFUND_REASON, null);
|
||||
@ -164,8 +163,8 @@ public class InvoicingMessageDaoImpl extends NamedParameterJdbcDaoSupport implem
|
||||
payment.setId(rs.getString(PAYMENT_ID));
|
||||
payment.setCreatedAt(rs.getString(PAYMENT_CREATED_AT));
|
||||
payment.setStatus(rs.getString(PAYMENT_STATUS));
|
||||
if (rs.getString(PAYMENT_ERROR_CODE) != null && "failed".equals(rs.getString(PAYMENT_STATUS))) {
|
||||
payment.setError(new StatusError(rs.getString(PAYMENT_ERROR_CODE), rs.getString(PAYMENT_ERROR_MESSAGE)));
|
||||
if (rs.getString(PAYMENT_FAILURE) != null && "failed".equals(rs.getString(PAYMENT_STATUS))) {
|
||||
payment.setError(ErrorUtils.toPaymentError(rs.getString(PAYMENT_FAILURE), rs.getString(PAYMENT_FAILURE_REASON)));
|
||||
}
|
||||
payment.setAmount(rs.getLong(PAYMENT_AMOUNT));
|
||||
payment.setCurrency(rs.getString(PAYMENT_CURRENCY));
|
||||
@ -206,8 +205,8 @@ public class InvoicingMessageDaoImpl extends NamedParameterJdbcDaoSupport implem
|
||||
refund.setId(rs.getString(REFUND_ID));
|
||||
refund.setCreatedAt(rs.getString(REFUND_CREATED_AT));
|
||||
refund.setStatus(rs.getString(REFUND_STATUS));
|
||||
if (rs.getString(REFUND_ERROR_CODE) != null && "failed".equals(rs.getString(REFUND_STATUS))) {
|
||||
refund.setError(new StatusError(rs.getString(REFUND_ERROR_CODE), rs.getString(REFUND_ERROR_MESSAGE)));
|
||||
if (rs.getString(REFUND_FAILURE) != null && "failed".equals(rs.getString(REFUND_STATUS))) {
|
||||
refund.setError(ErrorUtils.toPaymentError(rs.getString(REFUND_FAILURE), rs.getString(REFUND_FAILURE_REASON)));
|
||||
}
|
||||
refund.setAmount(rs.getLong(REFUND_AMOUNT));
|
||||
refund.setCurrency(rs.getString(REFUND_CURRENCY));
|
||||
@ -281,20 +280,20 @@ public class InvoicingMessageDaoImpl extends NamedParameterJdbcDaoSupport implem
|
||||
"(event_id, event_time, type, party_id, event_type, " +
|
||||
"invoice_id, shop_id, invoice_created_at, invoice_status, invoice_reason, invoice_due_date, invoice_amount, " +
|
||||
"invoice_currency, invoice_content_type, invoice_content_data, invoice_product, invoice_description, " +
|
||||
"payment_id, payment_created_at, payment_status, payment_error_code, payment_error_message, payment_amount, " +
|
||||
"payment_id, payment_created_at, payment_status, payment_failure, payment_failure_reason, payment_amount, " +
|
||||
"payment_currency, payment_tool_token, payment_session, payment_email, payment_phone, payment_ip, payment_fingerprint, " +
|
||||
"payment_customer_id, payment_payer_type, payment_tool_details_type, payment_card_number_mask, payment_system, payment_terminal_provider, " +
|
||||
"payment_digital_wallet_provider, payment_digital_wallet_id, " +
|
||||
"refund_id, refund_created_at, refund_status, refund_error_code, refund_error_message, refund_amount, refund_currency, refund_reason) " +
|
||||
"refund_id, refund_created_at, refund_status, refund_failure, refund_failure_reason, refund_amount, refund_currency, refund_reason) " +
|
||||
"VALUES " +
|
||||
"(:event_id, :event_time, :type, :party_id, CAST(:event_type as hook.eventtype), " +
|
||||
":invoice_id, :shop_id, :invoice_created_at, :invoice_status, :invoice_reason, :invoice_due_date, :invoice_amount, " +
|
||||
":invoice_currency, :invoice_content_type, :invoice_content_data, :invoice_product, :invoice_description, " +
|
||||
":payment_id, :payment_created_at, :payment_status, :payment_error_code, :payment_error_message, :payment_amount, " +
|
||||
":payment_id, :payment_created_at, :payment_status, :payment_failure, :payment_failure_reason, :payment_amount, " +
|
||||
":payment_currency, :payment_tool_token, :payment_session, :payment_email, :payment_phone, :payment_ip, :payment_fingerprint, " +
|
||||
":payment_customer_id, CAST(:payment_payer_type as hook.payment_payer_type), CAST(:payment_tool_details_type as hook.payment_tool_details_type), " +
|
||||
":payment_card_number_mask, :payment_system, :payment_terminal_provider, :payment_digital_wallet_provider, :payment_digital_wallet_id, " +
|
||||
":refund_id, :refund_created_at, :refund_status, :refund_error_code, :refund_error_message, :refund_amount, :refund_currency, :refund_reason) " +
|
||||
":refund_id, :refund_created_at, :refund_status, :refund_failure, :refund_failure_reason, :refund_amount, :refund_currency, :refund_reason) " +
|
||||
"RETURNING id";
|
||||
MapSqlParameterSource params = new MapSqlParameterSource()
|
||||
.addValue(EVENT_ID, message.getEventId())
|
||||
@ -321,8 +320,8 @@ public class InvoicingMessageDaoImpl extends NamedParameterJdbcDaoSupport implem
|
||||
params.addValue(PAYMENT_ID, payment.getId())
|
||||
.addValue(PAYMENT_CREATED_AT, payment.getCreatedAt())
|
||||
.addValue(PAYMENT_STATUS, payment.getStatus())
|
||||
.addValue(PAYMENT_ERROR_CODE, payment.getError() != null ? payment.getError().getCode() : null)
|
||||
.addValue(PAYMENT_ERROR_MESSAGE, payment.getError() != null ? payment.getError().getMessage() : null)
|
||||
.addValue(PAYMENT_FAILURE, payment.getError() != null ? ErrorUtils.toStringFailure(payment.getError()) : null)
|
||||
.addValue(PAYMENT_FAILURE_REASON, payment.getError() != null ? payment.getError().getMessage() : null)
|
||||
.addValue(PAYMENT_AMOUNT, payment.getAmount())
|
||||
.addValue(PAYMENT_CURRENCY, payment.getCurrency())
|
||||
.addValue(PAYMENT_TOOL_TOKEN, payment.getPaymentToolToken())
|
||||
@ -360,8 +359,8 @@ public class InvoicingMessageDaoImpl extends NamedParameterJdbcDaoSupport implem
|
||||
params.addValue(REFUND_ID, refund.getId())
|
||||
.addValue(REFUND_CREATED_AT, refund.getCreatedAt())
|
||||
.addValue(REFUND_STATUS, refund.getStatus())
|
||||
.addValue(PAYMENT_ERROR_CODE, refund.getError() != null ? refund.getError().getCode() : null)
|
||||
.addValue(PAYMENT_ERROR_MESSAGE, refund.getError() != null ? refund.getError().getMessage() : null)
|
||||
.addValue(PAYMENT_FAILURE, refund.getError() != null ? refund.getError().getCode() : null)
|
||||
.addValue(PAYMENT_FAILURE_REASON, refund.getError() != null ? refund.getError().getMessage() : null)
|
||||
.addValue(REFUND_AMOUNT, refund.getAmount())
|
||||
.addValue(REFUND_CURRENCY, refund.getCurrency())
|
||||
.addValue(REFUND_REASON, refund.getReason());
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.rbkmoney.hooker.handler.poller.impl.customer;
|
||||
|
||||
import com.rbkmoney.damsel.domain.PaymentTool;
|
||||
import com.rbkmoney.damsel.payment_processing.CustomerChange;
|
||||
import com.rbkmoney.damsel.payment_processing.Event;
|
||||
import com.rbkmoney.geck.filter.Filter;
|
||||
@ -12,7 +11,6 @@ import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.swag_webhook_events.ClientInfo;
|
||||
import com.rbkmoney.swag_webhook_events.CustomerBinding;
|
||||
import com.rbkmoney.swag_webhook_events.PaymentResource;
|
||||
import com.rbkmoney.swag_webhook_events.PaymentToolDetails;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.rbkmoney.hooker.utils.PaymentToolUtils.getPaymentToolDetails;
|
||||
|
@ -1,8 +1,6 @@
|
||||
package com.rbkmoney.hooker.handler.poller.impl.invoicing;
|
||||
|
||||
import com.rbkmoney.damsel.domain.Failure;
|
||||
import com.rbkmoney.damsel.domain.InvoicePaymentRefundStatus;
|
||||
import com.rbkmoney.damsel.domain.InvoicePaymentStatus;
|
||||
import com.rbkmoney.damsel.domain.OperationFailure;
|
||||
import com.rbkmoney.damsel.payment_processing.Event;
|
||||
import com.rbkmoney.damsel.payment_processing.InvoiceChange;
|
||||
@ -10,7 +8,10 @@ import com.rbkmoney.geck.filter.Filter;
|
||||
import com.rbkmoney.geck.filter.PathConditionFilter;
|
||||
import com.rbkmoney.geck.filter.condition.IsNullCondition;
|
||||
import com.rbkmoney.geck.filter.rule.PathConditionRule;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.Refund;
|
||||
import com.rbkmoney.hooker.utils.ErrorUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ -52,7 +53,7 @@ public class InvoicePaymentRefundStatusChangedHandler extends NeedReadInvoiceEve
|
||||
refund.setStatus(refundStatus.getSetField().getFieldName());
|
||||
if (refundStatus.isSetFailed()) {
|
||||
OperationFailure failure = refundStatus.getFailed().getFailure();
|
||||
refund.setError(getStatusError(failure));
|
||||
refund.setError(ErrorUtils.getPaymentError(failure));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,16 @@
|
||||
package com.rbkmoney.hooker.handler.poller.impl.invoicing;
|
||||
|
||||
import com.rbkmoney.damsel.domain.*;
|
||||
import com.rbkmoney.damsel.domain.DisposablePaymentResource;
|
||||
import com.rbkmoney.damsel.domain.InvoicePayment;
|
||||
import com.rbkmoney.damsel.domain.PaymentTool;
|
||||
import com.rbkmoney.damsel.payment_processing.Event;
|
||||
import com.rbkmoney.damsel.payment_processing.InvoiceChange;
|
||||
import com.rbkmoney.geck.filter.Filter;
|
||||
import com.rbkmoney.geck.filter.PathConditionFilter;
|
||||
import com.rbkmoney.geck.filter.condition.IsNullCondition;
|
||||
import com.rbkmoney.geck.filter.rule.PathConditionRule;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.Payment;
|
||||
import com.rbkmoney.hooker.model.PaymentContactInfo;
|
||||
import com.rbkmoney.hooker.utils.PaymentToolUtils;
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.rbkmoney.hooker.handler.poller.impl.invoicing;
|
||||
|
||||
import com.rbkmoney.damsel.domain.Failure;
|
||||
import com.rbkmoney.damsel.domain.InvoicePaymentRefundStatus;
|
||||
import com.rbkmoney.damsel.domain.InvoicePaymentStatus;
|
||||
import com.rbkmoney.damsel.domain.OperationFailure;
|
||||
import com.rbkmoney.damsel.payment_processing.Event;
|
||||
@ -10,7 +8,10 @@ import com.rbkmoney.geck.filter.Filter;
|
||||
import com.rbkmoney.geck.filter.PathConditionFilter;
|
||||
import com.rbkmoney.geck.filter.condition.IsNullCondition;
|
||||
import com.rbkmoney.geck.filter.rule.PathConditionRule;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.Payment;
|
||||
import com.rbkmoney.hooker.utils.ErrorUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ -50,7 +51,7 @@ public class InvoicePaymentStatusChangedHandler extends NeedReadInvoiceEventHand
|
||||
payment.setStatus(paymentOriginStatus.getSetField().getFieldName());
|
||||
if (paymentOriginStatus.isSetFailed()) {
|
||||
OperationFailure failure = paymentOriginStatus.getFailed().getFailure();
|
||||
payment.setError(getStatusError(failure));
|
||||
payment.setError(ErrorUtils.getPaymentError(failure));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,11 @@
|
||||
package com.rbkmoney.hooker.handler.poller.impl.invoicing;
|
||||
|
||||
import com.rbkmoney.damsel.domain.Failure;
|
||||
import com.rbkmoney.damsel.domain.OperationFailure;
|
||||
import com.rbkmoney.damsel.payment_processing.Event;
|
||||
import com.rbkmoney.damsel.payment_processing.InvoiceChange;
|
||||
import com.rbkmoney.hooker.dao.DaoException;
|
||||
import com.rbkmoney.hooker.dao.InvoicingMessageDao;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.StatusError;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
@ -43,13 +40,5 @@ public abstract class NeedReadInvoiceEventHandler extends AbstractInvoiceEventHa
|
||||
|
||||
protected abstract void modifyMessage(InvoiceChange ic, Event event, InvoicingMessage message);
|
||||
|
||||
protected StatusError getStatusError(OperationFailure failure) {
|
||||
if (failure.isSetFailure()) {
|
||||
Failure external = failure.getFailure();
|
||||
return new StatusError(external.getCode(), external.getReason());
|
||||
} else if (failure.isSetOperationTimeout()) {
|
||||
return new StatusError("408", "Operation timeout");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public class Payment {
|
||||
private String id;
|
||||
private String createdAt;
|
||||
private String status;
|
||||
private StatusError error;
|
||||
private PaymentError error;
|
||||
private long amount;
|
||||
private String currency;
|
||||
private String paymentToolToken;
|
||||
@ -26,7 +26,10 @@ public class Payment {
|
||||
this.createdAt = other.createdAt;
|
||||
this.status = other.status;
|
||||
if (other.error != null) {
|
||||
this.error = new StatusError(other.error);
|
||||
this.error = new PaymentError();
|
||||
this.error.setCode(other.error.getCode());
|
||||
this.error.setMessage(other.error.getMessage());
|
||||
this.error.setSubError(other.error.getSubError());
|
||||
}
|
||||
this.amount = other.amount;
|
||||
this.currency = other.currency;
|
||||
@ -108,11 +111,11 @@ public class Payment {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public StatusError getError() {
|
||||
public PaymentError getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public void setError(StatusError error) {
|
||||
public void setError(PaymentError error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
package com.rbkmoney.hooker.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.rbkmoney.swag_webhook_events.PaymentError;
|
||||
|
||||
public class Refund {
|
||||
private String id;
|
||||
private String createdAt;
|
||||
private String status;
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private StatusError error;
|
||||
private PaymentError error;
|
||||
private Long amount;
|
||||
private String currency;
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@ -18,7 +19,10 @@ public class Refund {
|
||||
this.createdAt = other.createdAt;
|
||||
this.status = other.status;
|
||||
if (other.error != null) {
|
||||
this.error = new StatusError(other.error);
|
||||
this.error = new PaymentError();
|
||||
this.error.setCode(other.error.getCode());
|
||||
this.error.setMessage(other.error.getMessage());
|
||||
this.error.setSubError(other.error.getSubError());
|
||||
}
|
||||
this.amount = other.amount;
|
||||
this.currency = other.currency;
|
||||
@ -53,11 +57,11 @@ public class Refund {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public StatusError getError() {
|
||||
public PaymentError getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public void setError(StatusError error) {
|
||||
public void setError(PaymentError error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
|
74
src/main/java/com/rbkmoney/hooker/utils/ErrorUtils.java
Normal file
74
src/main/java/com/rbkmoney/hooker/utils/ErrorUtils.java
Normal file
@ -0,0 +1,74 @@
|
||||
package com.rbkmoney.hooker.utils;
|
||||
|
||||
import com.rbkmoney.damsel.domain.Failure;
|
||||
import com.rbkmoney.damsel.domain.OperationFailure;
|
||||
import com.rbkmoney.damsel.domain.SubFailure;
|
||||
import com.rbkmoney.swag_webhook_events.PaymentError;
|
||||
import com.rbkmoney.swag_webhook_events.PaymentErrorSubError;
|
||||
|
||||
public class ErrorUtils {
|
||||
|
||||
public static PaymentError getPaymentError(OperationFailure operationFailure) {
|
||||
if (operationFailure.isSetFailure()) {
|
||||
Failure failure = operationFailure.getFailure();
|
||||
PaymentError paymentError = new PaymentError();
|
||||
paymentError.setCode(failure.getCode());
|
||||
if (failure.isSetReason()) {
|
||||
paymentError.setMessage(failure.getReason());
|
||||
} else {
|
||||
paymentError.setMessage("Unknown error");
|
||||
}
|
||||
if (failure.isSetSub()) {
|
||||
SubFailure sub = failure.getSub();
|
||||
paymentError.setSubError(getSubError(sub));
|
||||
}
|
||||
return paymentError;
|
||||
} else if (operationFailure.isSetOperationTimeout()) {
|
||||
PaymentError paymentError = new PaymentError();
|
||||
paymentError.setCode("408");
|
||||
paymentError.setMessage("Operation timeout");
|
||||
return paymentError;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static PaymentErrorSubError getSubError(SubFailure sub) {
|
||||
PaymentErrorSubError paymentErrorSubError = new PaymentErrorSubError();
|
||||
paymentErrorSubError.setCode(sub.getCode());
|
||||
if (sub.isSetSub()) {
|
||||
paymentErrorSubError.setSubError(getSubError(sub.getSub()));
|
||||
}
|
||||
return paymentErrorSubError;
|
||||
}
|
||||
|
||||
public static String toStringFailure(PaymentError paymentError) {
|
||||
StringBuilder sb = new StringBuilder(paymentError.getCode());
|
||||
PaymentErrorSubError subError = paymentError.getSubError();
|
||||
while (subError != null) {
|
||||
sb.append(":").append(subError.getCode());
|
||||
subError = subError.getSubError();
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static PaymentError toPaymentError(String failure, String failureReason) {
|
||||
String[] codes = failure.split(":");
|
||||
PaymentError paymentError = new PaymentError();
|
||||
paymentError.setCode(codes[0]);
|
||||
paymentError.setMessage(failureReason);
|
||||
if (codes.length > 1) {
|
||||
PaymentErrorSubError previousSubError = null;
|
||||
for (int i = 1; i < codes.length; ++i){
|
||||
PaymentErrorSubError subError = new PaymentErrorSubError();
|
||||
subError.setCode(codes[i]);
|
||||
if (i == 1) {
|
||||
paymentError.setSubError(subError);
|
||||
} else {
|
||||
previousSubError.setSubError(subError);
|
||||
}
|
||||
previousSubError = subError;
|
||||
}
|
||||
}
|
||||
return paymentError;
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.rbkmoney.damsel.domain.BankCard;
|
||||
import com.rbkmoney.damsel.domain.DigitalWallet;
|
||||
import com.rbkmoney.damsel.domain.DigitalWalletProvider;
|
||||
import com.rbkmoney.damsel.domain.PaymentTool;
|
||||
import com.rbkmoney.hooker.model.PaymentToolDetailsDigitalWalletWrapper;
|
||||
@ -15,7 +14,6 @@ import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
7
src/main/resources/db/migration/V5__error_mapping.sql
Normal file
7
src/main/resources/db/migration/V5__error_mapping.sql
Normal file
@ -0,0 +1,7 @@
|
||||
UPDATE hook.message SET payment_error_code = replace(payment_error_code, ':', '');
|
||||
ALTER TABLE hook.message RENAME payment_error_code TO payment_failure;
|
||||
ALTER TABLE hook.message RENAME payment_error_message TO payment_failure_reason;
|
||||
|
||||
UPDATE hook.message SET refund_error_code = replace(refund_error_code, ':', '');
|
||||
ALTER TABLE hook.message RENAME refund_error_code TO refund_failure;
|
||||
ALTER TABLE hook.message RENAME refund_error_message TO refund_failure_reason;
|
@ -31,9 +31,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.rbkmoney.hooker.utils.BuildUtils.buildMessage;
|
||||
import static com.rbkmoney.hooker.utils.BuildUtils.cart;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by jeckep on 20.04.17.
|
||||
|
@ -50,7 +50,13 @@ public class BuildUtils {
|
||||
payment.setId("123");
|
||||
payment.setCreatedAt("13.12.20017");
|
||||
payment.setStatus(status);
|
||||
payment.setError(new StatusError("1", "shit"));
|
||||
PaymentError paymentError = new PaymentError();
|
||||
paymentError.setCode("code");
|
||||
paymentError.setMessage("mess");
|
||||
PaymentErrorSubError subError = new PaymentErrorSubError();
|
||||
subError.setCode("sub_code");
|
||||
paymentError.setSubError(subError);
|
||||
payment.setError(paymentError);
|
||||
payment.setAmount(1);
|
||||
payment.setCurrency("RUB");
|
||||
payment.setPaymentToolToken("payment tool token");
|
||||
|
47
src/test/java/com/rbkmoney/hooker/utils/ErrorUtilsTest.java
Normal file
47
src/test/java/com/rbkmoney/hooker/utils/ErrorUtilsTest.java
Normal file
@ -0,0 +1,47 @@
|
||||
package com.rbkmoney.hooker.utils;
|
||||
|
||||
import com.rbkmoney.damsel.domain.Failure;
|
||||
import com.rbkmoney.damsel.domain.OperationFailure;
|
||||
import com.rbkmoney.damsel.domain.OperationTimeout;
|
||||
import com.rbkmoney.damsel.domain.SubFailure;
|
||||
import com.rbkmoney.swag_webhook_events.PaymentError;
|
||||
import com.rbkmoney.swag_webhook_events.PaymentErrorSubError;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ErrorUtilsTest {
|
||||
|
||||
@Test
|
||||
public void getPaymentError() {
|
||||
OperationFailure operationFailure = new OperationFailure();
|
||||
operationFailure.setOperationTimeout(new OperationTimeout());
|
||||
assertEquals("408", ErrorUtils.getPaymentError(operationFailure).getCode());
|
||||
|
||||
OperationFailure operationFailure1 = new OperationFailure();
|
||||
Failure value = new Failure();
|
||||
operationFailure1.setFailure(value);
|
||||
value.setCode("code");
|
||||
value.setReason("reason");
|
||||
SubFailure sub = new SubFailure();
|
||||
value.setSub(sub);
|
||||
sub.setCode("sub_code");
|
||||
assertEquals("sub_code", ErrorUtils.getPaymentError(operationFailure1).getSubError().getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringFailure() {
|
||||
PaymentError paymentError = new PaymentError();
|
||||
paymentError.setCode("code");
|
||||
paymentError.setMessage("mess");
|
||||
PaymentErrorSubError subError = new PaymentErrorSubError();
|
||||
subError.setCode("sub_error");
|
||||
paymentError.setSubError(subError);
|
||||
assertEquals("code:sub_error", ErrorUtils.toStringFailure(paymentError));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toPaymentError() {
|
||||
assertEquals("sub_code", ErrorUtils.toPaymentError("code:sub_code", "message").getSubError().getCode());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user