NEW-11: Recurrents

This commit is contained in:
Inal Arsanukaev 2018-09-06 15:52:54 +03:00
parent 7c006c57f4
commit 003f183663
10 changed files with 557 additions and 97 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>newway</artifactId>
<version>1.0.5-SNAPSHOT</version>
<version>1.0.7-SNAPSHOT</version>
<packaging>jar</packaging>
<name>newway</name>
@ -29,7 +29,7 @@
<db.password>postgres</db.password>
<db.schema>nw</db.schema>
<flyway.version>4.2.0</flyway.version>
<damsel.version>1.246-abda90b</damsel.version>
<damsel.version>1.251-15f037a-epic</damsel.version>
</properties>
<dependencies>

View File

@ -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;
}
}

View File

@ -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<PaymentRecord> {
private static final long serialVersionUID = -1550487756;
private static final long serialVersionUID = -1409619571;
/**
* The reference instance of <code>nw.payment</code>
@ -271,6 +272,31 @@ public class Payment extends TableImpl<PaymentRecord> {
*/
public final TableField<PaymentRecord, Boolean> 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 <code>nw.payment.is_recurring</code>.
*/
public final TableField<PaymentRecord, Boolean> IS_RECURRING = createField("is_recurring", org.jooq.impl.SQLDataType.BOOLEAN, this, "");
/**
* The column <code>nw.payment.recurrent_intention_token_source</code>.
*/
public final TableField<PaymentRecord, RecurrentTokenSource> 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 <code>nw.payment.recurrent_intention_token_source_invoice_id</code>.
*/
public final TableField<PaymentRecord, String> RECURRENT_INTENTION_TOKEN_SOURCE_INVOICE_ID = createField("recurrent_intention_token_source_invoice_id", org.jooq.impl.SQLDataType.VARCHAR, this, "");
/**
* The column <code>nw.payment.recurrent_intention_token_source_payment_id</code>.
*/
public final TableField<PaymentRecord, String> RECURRENT_INTENTION_TOKEN_SOURCE_PAYMENT_ID = createField("recurrent_intention_token_source_payment_id", org.jooq.impl.SQLDataType.VARCHAR, this, "");
/**
* The column <code>nw.payment.recurrent_intention_token</code>.
*/
public final TableField<PaymentRecord, String> RECURRENT_INTENTION_TOKEN = createField("recurrent_intention_token", org.jooq.impl.SQLDataType.VARCHAR, this, "");
/**
* Create a <code>nw.payment</code> table reference
*/

View File

@ -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();

View File

@ -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<PaymentRecord> {
private static final long serialVersionUID = 345543654;
private static final long serialVersionUID = 1043313227;
/**
* Setter for <code>nw.payment.id</code>.
@ -636,6 +637,76 @@ public class PaymentRecord extends UpdatableRecordImpl<PaymentRecord> {
return (Boolean) get(42);
}
/**
* Setter for <code>nw.payment.is_recurring</code>.
*/
public void setIsRecurring(Boolean value) {
set(43, value);
}
/**
* Getter for <code>nw.payment.is_recurring</code>.
*/
public Boolean getIsRecurring() {
return (Boolean) get(43);
}
/**
* Setter for <code>nw.payment.recurrent_intention_token_source</code>.
*/
public void setRecurrentIntentionTokenSource(RecurrentTokenSource value) {
set(44, value);
}
/**
* Getter for <code>nw.payment.recurrent_intention_token_source</code>.
*/
public RecurrentTokenSource getRecurrentIntentionTokenSource() {
return (RecurrentTokenSource) get(44);
}
/**
* Setter for <code>nw.payment.recurrent_intention_token_source_invoice_id</code>.
*/
public void setRecurrentIntentionTokenSourceInvoiceId(String value) {
set(45, value);
}
/**
* Getter for <code>nw.payment.recurrent_intention_token_source_invoice_id</code>.
*/
public String getRecurrentIntentionTokenSourceInvoiceId() {
return (String) get(45);
}
/**
* Setter for <code>nw.payment.recurrent_intention_token_source_payment_id</code>.
*/
public void setRecurrentIntentionTokenSourcePaymentId(String value) {
set(46, value);
}
/**
* Getter for <code>nw.payment.recurrent_intention_token_source_payment_id</code>.
*/
public String getRecurrentIntentionTokenSourcePaymentId() {
return (String) get(46);
}
/**
* Setter for <code>nw.payment.recurrent_intention_token</code>.
*/
public void setRecurrentIntentionToken(String value) {
set(47, value);
}
/**
* Getter for <code>nw.payment.recurrent_intention_token</code>.
*/
public String getRecurrentIntentionToken() {
return (String) get(47);
}
// -------------------------------------------------------------------------
// Primary key information
// -------------------------------------------------------------------------
@ -662,7 +733,7 @@ public class PaymentRecord extends UpdatableRecordImpl<PaymentRecord> {
/**
* 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<PaymentRecord> {
set(40, routeTerminalId);
set(41, wtime);
set(42, current);
set(43, isRecurring);
set(44, recurrentIntentionTokenSource);
set(45, recurrentIntentionTokenSourceInvoiceId);
set(46, recurrentIntentionTokenSourcePaymentId);
set(47, recurrentIntentionToken);
}
}

View File

@ -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()) {

View File

@ -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<CashFlow> 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<InvoiceChange> getFilter() {
return filter;
}
}

View File

@ -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<CashFlow> 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<InvoiceChange> getFilter() {
return filter;
}
}

View File

@ -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<com.rbkmoney.newway.domain.tables.pojos.PayoutTool> 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);
});
}
}

View File

@ -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;