From 003f1836631f40e522663eb9debae438203bcd66 Mon Sep 17 00:00:00 2001 From: Inal Arsanukaev Date: Thu, 6 Sep 2018 15:52:54 +0300 Subject: [PATCH] NEW-11: Recurrents --- pom.xml | 4 +- .../domain/enums/RecurrentTokenSource.java | 68 +++++ .../newway/domain/tables/Payment.java | 28 +- .../newway/domain/tables/pojos/Payment.java | 275 ++++++++++++------ .../domain/tables/records/PaymentRecord.java | 80 ++++- .../payment/InvoicePaymentCreatedHandler.java | 20 +- ...InvoicePaymentRecTokenAcquiredHandler.java | 82 ++++++ ...InvoicePaymentRiskScoreChangedHandler.java | 86 ++++++ .../contract/ContractCreatedHandler.java | 4 +- .../resources/db/migration/V5__recurrents.sql | 7 + 10 files changed, 557 insertions(+), 97 deletions(-) create mode 100644 src/main/java/com/rbkmoney/newway/domain/enums/RecurrentTokenSource.java create mode 100644 src/main/java/com/rbkmoney/newway/poller/handler/impl/invoicing/payment/InvoicePaymentRecTokenAcquiredHandler.java create mode 100644 src/main/java/com/rbkmoney/newway/poller/handler/impl/invoicing/payment/InvoicePaymentRiskScoreChangedHandler.java create mode 100644 src/main/resources/db/migration/V5__recurrents.sql diff --git a/pom.xml b/pom.xml index 17543fd..f57b0a5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 newway - 1.0.5-SNAPSHOT + 1.0.7-SNAPSHOT jar newway @@ -29,7 +29,7 @@ postgres nw 4.2.0 - 1.246-abda90b + 1.251-15f037a-epic diff --git a/src/main/java/com/rbkmoney/newway/domain/enums/RecurrentTokenSource.java b/src/main/java/com/rbkmoney/newway/domain/enums/RecurrentTokenSource.java new file mode 100644 index 0000000..2b3357e --- /dev/null +++ b/src/main/java/com/rbkmoney/newway/domain/enums/RecurrentTokenSource.java @@ -0,0 +1,68 @@ +/* + * This file is generated by jOOQ. +*/ +package com.rbkmoney.newway.domain.enums; + + +import com.rbkmoney.newway.domain.Nw; + +import javax.annotation.Generated; + +import org.jooq.Catalog; +import org.jooq.EnumType; +import org.jooq.Schema; + + +/** + * This class is generated by jOOQ. + */ +@Generated( + value = { + "http://www.jooq.org", + "jOOQ version:3.9.6" + }, + comments = "This class is generated by jOOQ" +) +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public enum RecurrentTokenSource implements EnumType { + + payment("payment"); + + private final String literal; + + private RecurrentTokenSource(String literal) { + this.literal = literal; + } + + /** + * {@inheritDoc} + */ + @Override + public Catalog getCatalog() { + return getSchema() == null ? null : getSchema().getCatalog(); + } + + /** + * {@inheritDoc} + */ + @Override + public Schema getSchema() { + return Nw.NW; + } + + /** + * {@inheritDoc} + */ + @Override + public String getName() { + return "recurrent_token_source"; + } + + /** + * {@inheritDoc} + */ + @Override + public String getLiteral() { + return literal; + } +} diff --git a/src/main/java/com/rbkmoney/newway/domain/tables/Payment.java b/src/main/java/com/rbkmoney/newway/domain/tables/Payment.java index 11d5e73..7f0095f 100644 --- a/src/main/java/com/rbkmoney/newway/domain/tables/Payment.java +++ b/src/main/java/com/rbkmoney/newway/domain/tables/Payment.java @@ -10,6 +10,7 @@ import com.rbkmoney.newway.domain.enums.PayerType; import com.rbkmoney.newway.domain.enums.PaymentFlowType; import com.rbkmoney.newway.domain.enums.PaymentStatus; import com.rbkmoney.newway.domain.enums.PaymentToolType; +import com.rbkmoney.newway.domain.enums.RecurrentTokenSource; import com.rbkmoney.newway.domain.enums.RiskScore; import com.rbkmoney.newway.domain.tables.records.PaymentRecord; @@ -41,7 +42,7 @@ import org.jooq.impl.TableImpl; @SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class Payment extends TableImpl { - private static final long serialVersionUID = -1550487756; + private static final long serialVersionUID = -1409619571; /** * The reference instance of nw.payment @@ -271,6 +272,31 @@ public class Payment extends TableImpl { */ public final TableField CURRENT = createField("current", org.jooq.impl.SQLDataType.BOOLEAN.nullable(false).defaultValue(org.jooq.impl.DSL.field("true", org.jooq.impl.SQLDataType.BOOLEAN)), this, ""); + /** + * The column nw.payment.is_recurring. + */ + public final TableField IS_RECURRING = createField("is_recurring", org.jooq.impl.SQLDataType.BOOLEAN, this, ""); + + /** + * The column nw.payment.recurrent_intention_token_source. + */ + public final TableField RECURRENT_INTENTION_TOKEN_SOURCE = createField("recurrent_intention_token_source", org.jooq.util.postgres.PostgresDataType.VARCHAR.asEnumDataType(com.rbkmoney.newway.domain.enums.RecurrentTokenSource.class), this, ""); + + /** + * The column nw.payment.recurrent_intention_token_source_invoice_id. + */ + public final TableField RECURRENT_INTENTION_TOKEN_SOURCE_INVOICE_ID = createField("recurrent_intention_token_source_invoice_id", org.jooq.impl.SQLDataType.VARCHAR, this, ""); + + /** + * The column nw.payment.recurrent_intention_token_source_payment_id. + */ + public final TableField RECURRENT_INTENTION_TOKEN_SOURCE_PAYMENT_ID = createField("recurrent_intention_token_source_payment_id", org.jooq.impl.SQLDataType.VARCHAR, this, ""); + + /** + * The column nw.payment.recurrent_intention_token. + */ + public final TableField RECURRENT_INTENTION_TOKEN = createField("recurrent_intention_token", org.jooq.impl.SQLDataType.VARCHAR, this, ""); + /** * Create a nw.payment table reference */ diff --git a/src/main/java/com/rbkmoney/newway/domain/tables/pojos/Payment.java b/src/main/java/com/rbkmoney/newway/domain/tables/pojos/Payment.java index eedbd50..84d278e 100644 --- a/src/main/java/com/rbkmoney/newway/domain/tables/pojos/Payment.java +++ b/src/main/java/com/rbkmoney/newway/domain/tables/pojos/Payment.java @@ -8,6 +8,7 @@ import com.rbkmoney.newway.domain.enums.PayerType; import com.rbkmoney.newway.domain.enums.PaymentFlowType; import com.rbkmoney.newway.domain.enums.PaymentStatus; import com.rbkmoney.newway.domain.enums.PaymentToolType; +import com.rbkmoney.newway.domain.enums.RecurrentTokenSource; import com.rbkmoney.newway.domain.enums.RiskScore; import java.io.Serializable; @@ -30,51 +31,56 @@ import javax.annotation.Generated; @SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class Payment implements Serializable { - private static final long serialVersionUID = -1965756637; + private static final long serialVersionUID = 1906566481; - private Long id; - private Long eventId; - private LocalDateTime eventCreatedAt; - private String paymentId; - private LocalDateTime createdAt; - private String invoiceId; - private String partyId; - private String shopId; - private Long domainRevision; - private Long partyRevision; - private PaymentStatus status; - private String statusCancelledReason; - private String statusCapturedReason; - private String statusFailedFailure; - private Long amount; - private String currencyCode; - private PayerType payerType; - private PaymentToolType payerPaymentToolType; - private String payerBankCardToken; - private String payerBankCardPaymentSystem; - private String payerBankCardBin; - private String payerBankCardMaskedPan; - private String payerBankCardTokenProvider; - private String payerPaymentTerminalType; - private String payerDigitalWalletProvider; - private String payerDigitalWalletId; - private String payerPaymentSessionId; - private String payerIpAddress; - private String payerFingerprint; - private String payerPhoneNumber; - private String payerEmail; - private String payerCustomerId; - private String payerCustomerBindingId; - private String payerCustomerRecPaymentToolId; - private byte[] context; - private PaymentFlowType paymentFlowType; - private String paymentFlowOnHoldExpiration; - private LocalDateTime paymentFlowHeldUntil; - private RiskScore riskScore; - private Integer routeProviderId; - private Integer routeTerminalId; - private LocalDateTime wtime; - private Boolean current; + private Long id; + private Long eventId; + private LocalDateTime eventCreatedAt; + private String paymentId; + private LocalDateTime createdAt; + private String invoiceId; + private String partyId; + private String shopId; + private Long domainRevision; + private Long partyRevision; + private PaymentStatus status; + private String statusCancelledReason; + private String statusCapturedReason; + private String statusFailedFailure; + private Long amount; + private String currencyCode; + private PayerType payerType; + private PaymentToolType payerPaymentToolType; + private String payerBankCardToken; + private String payerBankCardPaymentSystem; + private String payerBankCardBin; + private String payerBankCardMaskedPan; + private String payerBankCardTokenProvider; + private String payerPaymentTerminalType; + private String payerDigitalWalletProvider; + private String payerDigitalWalletId; + private String payerPaymentSessionId; + private String payerIpAddress; + private String payerFingerprint; + private String payerPhoneNumber; + private String payerEmail; + private String payerCustomerId; + private String payerCustomerBindingId; + private String payerCustomerRecPaymentToolId; + private byte[] context; + private PaymentFlowType paymentFlowType; + private String paymentFlowOnHoldExpiration; + private LocalDateTime paymentFlowHeldUntil; + private RiskScore riskScore; + private Integer routeProviderId; + private Integer routeTerminalId; + private LocalDateTime wtime; + private Boolean current; + private Boolean isRecurring; + private RecurrentTokenSource recurrentIntentionTokenSource; + private String recurrentIntentionTokenSourceInvoiceId; + private String recurrentIntentionTokenSourcePaymentId; + private String recurrentIntentionToken; public Payment() {} @@ -122,52 +128,62 @@ public class Payment implements Serializable { this.routeTerminalId = value.routeTerminalId; this.wtime = value.wtime; this.current = value.current; + this.isRecurring = value.isRecurring; + this.recurrentIntentionTokenSource = value.recurrentIntentionTokenSource; + this.recurrentIntentionTokenSourceInvoiceId = value.recurrentIntentionTokenSourceInvoiceId; + this.recurrentIntentionTokenSourcePaymentId = value.recurrentIntentionTokenSourcePaymentId; + this.recurrentIntentionToken = value.recurrentIntentionToken; } public Payment( - Long id, - Long eventId, - LocalDateTime eventCreatedAt, - String paymentId, - LocalDateTime createdAt, - String invoiceId, - String partyId, - String shopId, - Long domainRevision, - Long partyRevision, - PaymentStatus status, - String statusCancelledReason, - String statusCapturedReason, - String statusFailedFailure, - Long amount, - String currencyCode, - PayerType payerType, - PaymentToolType payerPaymentToolType, - String payerBankCardToken, - String payerBankCardPaymentSystem, - String payerBankCardBin, - String payerBankCardMaskedPan, - String payerBankCardTokenProvider, - String payerPaymentTerminalType, - String payerDigitalWalletProvider, - String payerDigitalWalletId, - String payerPaymentSessionId, - String payerIpAddress, - String payerFingerprint, - String payerPhoneNumber, - String payerEmail, - String payerCustomerId, - String payerCustomerBindingId, - String payerCustomerRecPaymentToolId, - byte[] context, - PaymentFlowType paymentFlowType, - String paymentFlowOnHoldExpiration, - LocalDateTime paymentFlowHeldUntil, - RiskScore riskScore, - Integer routeProviderId, - Integer routeTerminalId, - LocalDateTime wtime, - Boolean current + Long id, + Long eventId, + LocalDateTime eventCreatedAt, + String paymentId, + LocalDateTime createdAt, + String invoiceId, + String partyId, + String shopId, + Long domainRevision, + Long partyRevision, + PaymentStatus status, + String statusCancelledReason, + String statusCapturedReason, + String statusFailedFailure, + Long amount, + String currencyCode, + PayerType payerType, + PaymentToolType payerPaymentToolType, + String payerBankCardToken, + String payerBankCardPaymentSystem, + String payerBankCardBin, + String payerBankCardMaskedPan, + String payerBankCardTokenProvider, + String payerPaymentTerminalType, + String payerDigitalWalletProvider, + String payerDigitalWalletId, + String payerPaymentSessionId, + String payerIpAddress, + String payerFingerprint, + String payerPhoneNumber, + String payerEmail, + String payerCustomerId, + String payerCustomerBindingId, + String payerCustomerRecPaymentToolId, + byte[] context, + PaymentFlowType paymentFlowType, + String paymentFlowOnHoldExpiration, + LocalDateTime paymentFlowHeldUntil, + RiskScore riskScore, + Integer routeProviderId, + Integer routeTerminalId, + LocalDateTime wtime, + Boolean current, + Boolean isRecurring, + RecurrentTokenSource recurrentIntentionTokenSource, + String recurrentIntentionTokenSourceInvoiceId, + String recurrentIntentionTokenSourcePaymentId, + String recurrentIntentionToken ) { this.id = id; this.eventId = eventId; @@ -212,6 +228,11 @@ public class Payment implements Serializable { this.routeTerminalId = routeTerminalId; this.wtime = wtime; this.current = current; + this.isRecurring = isRecurring; + this.recurrentIntentionTokenSource = recurrentIntentionTokenSource; + this.recurrentIntentionTokenSourceInvoiceId = recurrentIntentionTokenSourceInvoiceId; + this.recurrentIntentionTokenSourcePaymentId = recurrentIntentionTokenSourcePaymentId; + this.recurrentIntentionToken = recurrentIntentionToken; } public Long getId() { @@ -558,6 +579,46 @@ public class Payment implements Serializable { this.current = current; } + public Boolean getIsRecurring() { + return this.isRecurring; + } + + public void setIsRecurring(Boolean isRecurring) { + this.isRecurring = isRecurring; + } + + public RecurrentTokenSource getRecurrentIntentionTokenSource() { + return this.recurrentIntentionTokenSource; + } + + public void setRecurrentIntentionTokenSource(RecurrentTokenSource recurrentIntentionTokenSource) { + this.recurrentIntentionTokenSource = recurrentIntentionTokenSource; + } + + public String getRecurrentIntentionTokenSourceInvoiceId() { + return this.recurrentIntentionTokenSourceInvoiceId; + } + + public void setRecurrentIntentionTokenSourceInvoiceId(String recurrentIntentionTokenSourceInvoiceId) { + this.recurrentIntentionTokenSourceInvoiceId = recurrentIntentionTokenSourceInvoiceId; + } + + public String getRecurrentIntentionTokenSourcePaymentId() { + return this.recurrentIntentionTokenSourcePaymentId; + } + + public void setRecurrentIntentionTokenSourcePaymentId(String recurrentIntentionTokenSourcePaymentId) { + this.recurrentIntentionTokenSourcePaymentId = recurrentIntentionTokenSourcePaymentId; + } + + public String getRecurrentIntentionToken() { + return this.recurrentIntentionToken; + } + + public void setRecurrentIntentionToken(String recurrentIntentionToken) { + this.recurrentIntentionToken = recurrentIntentionToken; + } + @Override public boolean equals(Object obj) { if (this == obj) @@ -825,6 +886,36 @@ public class Payment implements Serializable { } else if (!current.equals(other.current)) return false; + if (isRecurring == null) { + if (other.isRecurring != null) + return false; + } + else if (!isRecurring.equals(other.isRecurring)) + return false; + if (recurrentIntentionTokenSource == null) { + if (other.recurrentIntentionTokenSource != null) + return false; + } + else if (!recurrentIntentionTokenSource.equals(other.recurrentIntentionTokenSource)) + return false; + if (recurrentIntentionTokenSourceInvoiceId == null) { + if (other.recurrentIntentionTokenSourceInvoiceId != null) + return false; + } + else if (!recurrentIntentionTokenSourceInvoiceId.equals(other.recurrentIntentionTokenSourceInvoiceId)) + return false; + if (recurrentIntentionTokenSourcePaymentId == null) { + if (other.recurrentIntentionTokenSourcePaymentId != null) + return false; + } + else if (!recurrentIntentionTokenSourcePaymentId.equals(other.recurrentIntentionTokenSourcePaymentId)) + return false; + if (recurrentIntentionToken == null) { + if (other.recurrentIntentionToken != null) + return false; + } + else if (!recurrentIntentionToken.equals(other.recurrentIntentionToken)) + return false; return true; } @@ -875,6 +966,11 @@ public class Payment implements Serializable { result = prime * result + ((this.routeTerminalId == null) ? 0 : this.routeTerminalId.hashCode()); result = prime * result + ((this.wtime == null) ? 0 : this.wtime.hashCode()); result = prime * result + ((this.current == null) ? 0 : this.current.hashCode()); + result = prime * result + ((this.isRecurring == null) ? 0 : this.isRecurring.hashCode()); + result = prime * result + ((this.recurrentIntentionTokenSource == null) ? 0 : this.recurrentIntentionTokenSource.hashCode()); + result = prime * result + ((this.recurrentIntentionTokenSourceInvoiceId == null) ? 0 : this.recurrentIntentionTokenSourceInvoiceId.hashCode()); + result = prime * result + ((this.recurrentIntentionTokenSourcePaymentId == null) ? 0 : this.recurrentIntentionTokenSourcePaymentId.hashCode()); + result = prime * result + ((this.recurrentIntentionToken == null) ? 0 : this.recurrentIntentionToken.hashCode()); return result; } @@ -925,6 +1021,11 @@ public class Payment implements Serializable { sb.append(", ").append(routeTerminalId); sb.append(", ").append(wtime); sb.append(", ").append(current); + sb.append(", ").append(isRecurring); + sb.append(", ").append(recurrentIntentionTokenSource); + sb.append(", ").append(recurrentIntentionTokenSourceInvoiceId); + sb.append(", ").append(recurrentIntentionTokenSourcePaymentId); + sb.append(", ").append(recurrentIntentionToken); sb.append(")"); return sb.toString(); diff --git a/src/main/java/com/rbkmoney/newway/domain/tables/records/PaymentRecord.java b/src/main/java/com/rbkmoney/newway/domain/tables/records/PaymentRecord.java index 4c9cdd3..8800a43 100644 --- a/src/main/java/com/rbkmoney/newway/domain/tables/records/PaymentRecord.java +++ b/src/main/java/com/rbkmoney/newway/domain/tables/records/PaymentRecord.java @@ -8,6 +8,7 @@ import com.rbkmoney.newway.domain.enums.PayerType; import com.rbkmoney.newway.domain.enums.PaymentFlowType; import com.rbkmoney.newway.domain.enums.PaymentStatus; import com.rbkmoney.newway.domain.enums.PaymentToolType; +import com.rbkmoney.newway.domain.enums.RecurrentTokenSource; import com.rbkmoney.newway.domain.enums.RiskScore; import com.rbkmoney.newway.domain.tables.Payment; @@ -32,7 +33,7 @@ import org.jooq.impl.UpdatableRecordImpl; @SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class PaymentRecord extends UpdatableRecordImpl { - private static final long serialVersionUID = 345543654; + private static final long serialVersionUID = 1043313227; /** * Setter for nw.payment.id. @@ -636,6 +637,76 @@ public class PaymentRecord extends UpdatableRecordImpl { return (Boolean) get(42); } + /** + * Setter for nw.payment.is_recurring. + */ + public void setIsRecurring(Boolean value) { + set(43, value); + } + + /** + * Getter for nw.payment.is_recurring. + */ + public Boolean getIsRecurring() { + return (Boolean) get(43); + } + + /** + * Setter for nw.payment.recurrent_intention_token_source. + */ + public void setRecurrentIntentionTokenSource(RecurrentTokenSource value) { + set(44, value); + } + + /** + * Getter for nw.payment.recurrent_intention_token_source. + */ + public RecurrentTokenSource getRecurrentIntentionTokenSource() { + return (RecurrentTokenSource) get(44); + } + + /** + * Setter for nw.payment.recurrent_intention_token_source_invoice_id. + */ + public void setRecurrentIntentionTokenSourceInvoiceId(String value) { + set(45, value); + } + + /** + * Getter for nw.payment.recurrent_intention_token_source_invoice_id. + */ + public String getRecurrentIntentionTokenSourceInvoiceId() { + return (String) get(45); + } + + /** + * Setter for nw.payment.recurrent_intention_token_source_payment_id. + */ + public void setRecurrentIntentionTokenSourcePaymentId(String value) { + set(46, value); + } + + /** + * Getter for nw.payment.recurrent_intention_token_source_payment_id. + */ + public String getRecurrentIntentionTokenSourcePaymentId() { + return (String) get(46); + } + + /** + * Setter for nw.payment.recurrent_intention_token. + */ + public void setRecurrentIntentionToken(String value) { + set(47, value); + } + + /** + * Getter for nw.payment.recurrent_intention_token. + */ + public String getRecurrentIntentionToken() { + return (String) get(47); + } + // ------------------------------------------------------------------------- // Primary key information // ------------------------------------------------------------------------- @@ -662,7 +733,7 @@ public class PaymentRecord extends UpdatableRecordImpl { /** * Create a detached, initialised PaymentRecord */ - public PaymentRecord(Long id, Long eventId, LocalDateTime eventCreatedAt, String paymentId, LocalDateTime createdAt, String invoiceId, String partyId, String shopId, Long domainRevision, Long partyRevision, PaymentStatus status, String statusCancelledReason, String statusCapturedReason, String statusFailedFailure, Long amount, String currencyCode, PayerType payerType, PaymentToolType payerPaymentToolType, String payerBankCardToken, String payerBankCardPaymentSystem, String payerBankCardBin, String payerBankCardMaskedPan, String payerBankCardTokenProvider, String payerPaymentTerminalType, String payerDigitalWalletProvider, String payerDigitalWalletId, String payerPaymentSessionId, String payerIpAddress, String payerFingerprint, String payerPhoneNumber, String payerEmail, String payerCustomerId, String payerCustomerBindingId, String payerCustomerRecPaymentToolId, byte[] context, PaymentFlowType paymentFlowType, String paymentFlowOnHoldExpiration, LocalDateTime paymentFlowHeldUntil, RiskScore riskScore, Integer routeProviderId, Integer routeTerminalId, LocalDateTime wtime, Boolean current) { + public PaymentRecord(Long id, Long eventId, LocalDateTime eventCreatedAt, String paymentId, LocalDateTime createdAt, String invoiceId, String partyId, String shopId, Long domainRevision, Long partyRevision, PaymentStatus status, String statusCancelledReason, String statusCapturedReason, String statusFailedFailure, Long amount, String currencyCode, PayerType payerType, PaymentToolType payerPaymentToolType, String payerBankCardToken, String payerBankCardPaymentSystem, String payerBankCardBin, String payerBankCardMaskedPan, String payerBankCardTokenProvider, String payerPaymentTerminalType, String payerDigitalWalletProvider, String payerDigitalWalletId, String payerPaymentSessionId, String payerIpAddress, String payerFingerprint, String payerPhoneNumber, String payerEmail, String payerCustomerId, String payerCustomerBindingId, String payerCustomerRecPaymentToolId, byte[] context, PaymentFlowType paymentFlowType, String paymentFlowOnHoldExpiration, LocalDateTime paymentFlowHeldUntil, RiskScore riskScore, Integer routeProviderId, Integer routeTerminalId, LocalDateTime wtime, Boolean current, Boolean isRecurring, RecurrentTokenSource recurrentIntentionTokenSource, String recurrentIntentionTokenSourceInvoiceId, String recurrentIntentionTokenSourcePaymentId, String recurrentIntentionToken) { super(Payment.PAYMENT); set(0, id); @@ -708,5 +779,10 @@ public class PaymentRecord extends UpdatableRecordImpl { set(40, routeTerminalId); set(41, wtime); set(42, current); + set(43, isRecurring); + set(44, recurrentIntentionTokenSource); + set(45, recurrentIntentionTokenSourceInvoiceId); + set(46, recurrentIntentionTokenSourcePaymentId); + set(47, recurrentIntentionToken); } } diff --git a/src/main/java/com/rbkmoney/newway/poller/handler/impl/invoicing/payment/InvoicePaymentCreatedHandler.java b/src/main/java/com/rbkmoney/newway/poller/handler/impl/invoicing/payment/InvoicePaymentCreatedHandler.java index cd1d48b..f7e55f3 100644 --- a/src/main/java/com/rbkmoney/newway/poller/handler/impl/invoicing/payment/InvoicePaymentCreatedHandler.java +++ b/src/main/java/com/rbkmoney/newway/poller/handler/impl/invoicing/payment/InvoicePaymentCreatedHandler.java @@ -1,10 +1,10 @@ package com.rbkmoney.newway.poller.handler.impl.invoicing.payment; -import com.fasterxml.jackson.databind.ObjectMapper; import com.rbkmoney.damsel.domain.ContactInfo; import com.rbkmoney.damsel.domain.CustomerPayer; import com.rbkmoney.damsel.domain.InvoicePayment; import com.rbkmoney.damsel.domain.PaymentTool; +import com.rbkmoney.damsel.domain.RecurrentTokenSource; import com.rbkmoney.damsel.payment_processing.Event; import com.rbkmoney.damsel.payment_processing.InvoiceChange; import com.rbkmoney.damsel.payment_processing.InvoicePaymentStarted; @@ -44,8 +44,6 @@ public class InvoicePaymentCreatedHandler extends AbstractInvoicingHandler { private final CashFlowDao cashFlowDao; - private final ObjectMapper objectMapper = new ObjectMapper(); - private final Filter filter; @Autowired @@ -136,6 +134,22 @@ public class InvoicePaymentCreatedHandler extends AbstractInvoicingHandler { payment.setRouteProviderId(invoicePaymentStarted.getRoute().getProvider().getId()); payment.setRouteTerminalId(invoicePaymentStarted.getRoute().getTerminal().getId()); } + if (invoicePayment.isSetIsRecurring()) { + payment.setIsRecurring(invoicePayment.isIsRecurring()); + } + if (invoicePayment.isSetRecurrentIntention()) { + RecurrentTokenSource recurrentTokenSource = invoicePayment.getRecurrentIntention().getTokenSource(); + com.rbkmoney.newway.domain.enums.RecurrentTokenSource recurrentIntentionTokenSource = TypeUtil.toEnumField(recurrentTokenSource.getSetField().getFieldName(), com.rbkmoney.newway.domain.enums.RecurrentTokenSource.class); + if (recurrentIntentionTokenSource == null) { + throw new IllegalArgumentException("Illegal recurrent intention token source: " + recurrentTokenSource); + } + payment.setRecurrentIntentionTokenSource(recurrentIntentionTokenSource); + if (recurrentTokenSource.isSetPayment()) { + payment.setRecurrentIntentionTokenSourceInvoiceId(recurrentTokenSource.getPayment().getInvoiceId()); + payment.setRecurrentIntentionTokenSourcePaymentId(recurrentTokenSource.getPayment().getPaymentId()); + } + } + long pmntId = paymentDao.save(payment); if (invoicePaymentStarted.isSetCashFlow()) { diff --git a/src/main/java/com/rbkmoney/newway/poller/handler/impl/invoicing/payment/InvoicePaymentRecTokenAcquiredHandler.java b/src/main/java/com/rbkmoney/newway/poller/handler/impl/invoicing/payment/InvoicePaymentRecTokenAcquiredHandler.java new file mode 100644 index 0000000..47b94de --- /dev/null +++ b/src/main/java/com/rbkmoney/newway/poller/handler/impl/invoicing/payment/InvoicePaymentRecTokenAcquiredHandler.java @@ -0,0 +1,82 @@ +package com.rbkmoney.newway.poller.handler.impl.invoicing.payment; + +import com.rbkmoney.damsel.domain.RiskScore; +import com.rbkmoney.damsel.payment_processing.Event; +import com.rbkmoney.damsel.payment_processing.InvoiceChange; +import com.rbkmoney.damsel.payment_processing.InvoicePaymentChange; +import com.rbkmoney.geck.common.util.TypeUtil; +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.newway.dao.invoicing.iface.CashFlowDao; +import com.rbkmoney.newway.dao.invoicing.iface.PaymentDao; +import com.rbkmoney.newway.domain.enums.PaymentChangeType; +import com.rbkmoney.newway.domain.tables.pojos.CashFlow; +import com.rbkmoney.newway.domain.tables.pojos.Payment; +import com.rbkmoney.newway.exception.NotFoundException; +import com.rbkmoney.newway.poller.handler.impl.invoicing.AbstractInvoicingHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Component +public class InvoicePaymentRecTokenAcquiredHandler extends AbstractInvoicingHandler { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + private final PaymentDao paymentDao; + + private final CashFlowDao cashFlowDao; + + private final Filter filter; + + @Autowired + public InvoicePaymentRecTokenAcquiredHandler(PaymentDao paymentDao, CashFlowDao cashFlowDao) { + this.paymentDao = paymentDao; + this.cashFlowDao = cashFlowDao; + this.filter = new PathConditionFilter(new PathConditionRule( + "invoice_payment_change.payload.invoice_payment_rec_token_acquired", + new IsNullCondition().not())); + } + + @Override + @Transactional(propagation = Propagation.REQUIRED) + public void handle(InvoiceChange change, Event event) { + InvoicePaymentChange invoicePaymentChange = change.getInvoicePaymentChange(); + String invoiceId = event.getSource().getInvoiceId(); + String paymentId = invoicePaymentChange.getId(); + String token = invoicePaymentChange.getPayload().getInvoicePaymentRecTokenAcquired().getToken(); + log.info("Start handling payment recurrent token acquired, eventId='{}', invoiceId='{}', paymentId='{}'", event.getId(), invoiceId, paymentId); + Payment paymentSource = paymentDao.get(invoiceId, paymentId); + if (paymentSource == null) { + throw new NotFoundException(String.format("Invoice payment not found, invoiceId='%s', paymentId='%s'", + invoiceId, paymentId)); + } + Long paymentSourceId = paymentSource.getId(); + paymentSource.setId(null); + paymentSource.setWtime(null); + paymentSource.setEventId(event.getId()); + paymentSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt())); + paymentSource.setRecurrentIntentionToken(token); + paymentDao.updateNotCurrent(invoiceId, paymentId); + long pmntId = paymentDao.save(paymentSource); + List cashFlows = cashFlowDao.getByObjId(paymentSourceId, PaymentChangeType.payment); + cashFlows.forEach(pcf -> { + pcf.setId(null); + pcf.setObjId(pmntId); + }); + cashFlowDao.save(cashFlows); + log.info("Payment recurrent token have been saved, eventId='{}', invoiceId='{}', paymentId='{}'", event.getId(), invoiceId, paymentId); + } + + @Override + public Filter getFilter() { + return filter; + } +} diff --git a/src/main/java/com/rbkmoney/newway/poller/handler/impl/invoicing/payment/InvoicePaymentRiskScoreChangedHandler.java b/src/main/java/com/rbkmoney/newway/poller/handler/impl/invoicing/payment/InvoicePaymentRiskScoreChangedHandler.java new file mode 100644 index 0000000..027f2d1 --- /dev/null +++ b/src/main/java/com/rbkmoney/newway/poller/handler/impl/invoicing/payment/InvoicePaymentRiskScoreChangedHandler.java @@ -0,0 +1,86 @@ +package com.rbkmoney.newway.poller.handler.impl.invoicing.payment; + +import com.rbkmoney.damsel.domain.RiskScore; +import com.rbkmoney.damsel.payment_processing.Event; +import com.rbkmoney.damsel.payment_processing.InvoiceChange; +import com.rbkmoney.damsel.payment_processing.InvoicePaymentChange; +import com.rbkmoney.geck.common.util.TypeUtil; +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.newway.dao.invoicing.iface.CashFlowDao; +import com.rbkmoney.newway.dao.invoicing.iface.PaymentDao; +import com.rbkmoney.newway.domain.enums.PaymentChangeType; +import com.rbkmoney.newway.domain.tables.pojos.CashFlow; +import com.rbkmoney.newway.domain.tables.pojos.Payment; +import com.rbkmoney.newway.exception.NotFoundException; +import com.rbkmoney.newway.poller.handler.impl.invoicing.AbstractInvoicingHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Component +public class InvoicePaymentRiskScoreChangedHandler extends AbstractInvoicingHandler { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + private final PaymentDao paymentDao; + + private final CashFlowDao cashFlowDao; + + private final Filter filter; + + @Autowired + public InvoicePaymentRiskScoreChangedHandler(PaymentDao paymentDao, CashFlowDao cashFlowDao) { + this.paymentDao = paymentDao; + this.cashFlowDao = cashFlowDao; + this.filter = new PathConditionFilter(new PathConditionRule( + "invoice_payment_change.payload.invoice_payment_risk_score_changed", + new IsNullCondition().not())); + } + + @Override + @Transactional(propagation = Propagation.REQUIRED) + public void handle(InvoiceChange change, Event event) { + InvoicePaymentChange invoicePaymentChange = change.getInvoicePaymentChange(); + String invoiceId = event.getSource().getInvoiceId(); + String paymentId = invoicePaymentChange.getId(); + RiskScore riskScore = invoicePaymentChange.getPayload().getInvoicePaymentRiskScoreChanged().getRiskScore(); + log.info("Start handling payment risk score change, eventId='{}', invoiceId='{}', paymentId='{}'", event.getId(), invoiceId, paymentId); + Payment paymentSource = paymentDao.get(invoiceId, paymentId); + if (paymentSource == null) { + throw new NotFoundException(String.format("Invoice payment not found, invoiceId='%s', paymentId='%s'", + invoiceId, paymentId)); + } + Long paymentSourceId = paymentSource.getId(); + paymentSource.setId(null); + paymentSource.setWtime(null); + paymentSource.setEventId(event.getId()); + paymentSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt())); + com.rbkmoney.newway.domain.enums.RiskScore score = TypeUtil.toEnumField(riskScore.name(), com.rbkmoney.newway.domain.enums.RiskScore.class); + if (score == null) { + throw new IllegalArgumentException("Illegal risk score: " + riskScore); + } + paymentSource.setRiskScore(score); + paymentDao.updateNotCurrent(invoiceId, paymentId); + long pmntId = paymentDao.save(paymentSource); + List cashFlows = cashFlowDao.getByObjId(paymentSourceId, PaymentChangeType.payment); + cashFlows.forEach(pcf -> { + pcf.setId(null); + pcf.setObjId(pmntId); + }); + cashFlowDao.save(cashFlows); + log.info("Payment risk score have been saved, eventId='{}', invoiceId='{}', paymentId='{}'", event.getId(), invoiceId, paymentId); + } + + @Override + public Filter getFilter() { + return filter; + } +} diff --git a/src/main/java/com/rbkmoney/newway/poller/handler/impl/party_mngmnt/contract/ContractCreatedHandler.java b/src/main/java/com/rbkmoney/newway/poller/handler/impl/party_mngmnt/contract/ContractCreatedHandler.java index bb1e388..3594da6 100644 --- a/src/main/java/com/rbkmoney/newway/poller/handler/impl/party_mngmnt/contract/ContractCreatedHandler.java +++ b/src/main/java/com/rbkmoney/newway/poller/handler/impl/party_mngmnt/contract/ContractCreatedHandler.java @@ -49,7 +49,7 @@ public class ContractCreatedHandler extends AbstractClaimChangedHandler { com.rbkmoney.damsel.domain.Contract contractCreated = contractEffectUnit.getEffect().getCreated(); String contractId = contractEffectUnit.getContractId(); String partyId = event.getSource().getPartyId(); - log.info("Start contract created handling, eventId={}, partyId={}, contractId={}", eventId, contractId); + log.info("Start contract created handling, eventId={}, partyId={}, contractId={}", eventId, partyId, contractId); Contract contract = new Contract(); contract.setEventId(eventId); contract.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt())); @@ -94,7 +94,7 @@ public class ContractCreatedHandler extends AbstractClaimChangedHandler { List payoutTools = ContractUtil.convertPayoutTools(contractCreated, cntrctId); payoutToolDao.save(payoutTools); - log.info("Contract has been saved, eventId={}, contractId={}", eventId, contractId); + log.info("Contract has been saved, eventId={}, partyId={}, contractId={}", eventId, partyId, contractId); }); } } diff --git a/src/main/resources/db/migration/V5__recurrents.sql b/src/main/resources/db/migration/V5__recurrents.sql new file mode 100644 index 0000000..0b3baa1 --- /dev/null +++ b/src/main/resources/db/migration/V5__recurrents.sql @@ -0,0 +1,7 @@ +CREATE TYPE nw.recurrent_token_source AS ENUM ('payment'); + +ALTER TABLE nw.payment ADD COLUMN is_recurring BOOL; +ALTER TABLE nw.payment ADD COLUMN recurrent_intention_token_source nw.recurrent_token_source; +ALTER TABLE nw.payment ADD COLUMN recurrent_intention_token_source_invoice_id CHARACTER VARYING; +ALTER TABLE nw.payment ADD COLUMN recurrent_intention_token_source_payment_id CHARACTER VARYING; +ALTER TABLE nw.payment ADD COLUMN recurrent_intention_token CHARACTER VARYING; \ No newline at end of file