mirror of
https://github.com/valitydev/fraudo.git
synced 2024-11-06 01:45:16 +00:00
parent
7ba651d2ac
commit
ab6381786f
@ -1 +1 @@
|
||||
Subproject commit be44d69fc87b22a0bb82d98d6eae7658d1647f98
|
||||
Subproject commit a87ebf3ae5e56910dc6a0edcac7f90565368a3d1
|
@ -25,6 +25,8 @@ equalityExpression
|
||||
stringExpression
|
||||
: country_by
|
||||
| currency
|
||||
| payment_system
|
||||
| card_category
|
||||
| STRING
|
||||
;
|
||||
|
||||
|
@ -32,6 +32,14 @@ currency
|
||||
: 'currency' LPAREN RPAREN
|
||||
;
|
||||
|
||||
payment_system
|
||||
: 'paymentSystem' LPAREN RPAREN
|
||||
;
|
||||
|
||||
card_category
|
||||
: 'cardCategory' LPAREN RPAREN
|
||||
;
|
||||
|
||||
payer_type
|
||||
: 'payerType' LPAREN RPAREN
|
||||
;
|
||||
|
@ -7,8 +7,11 @@ public class BaseModel {
|
||||
|
||||
private String ip;
|
||||
private String email;
|
||||
private String phone;
|
||||
private String fingerprint;
|
||||
private Long amount;
|
||||
private String currency;
|
||||
private String paymentSystem;
|
||||
private String cardCategory;
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.rbkmoney.fraudo.payment.visitor.impl;
|
||||
|
||||
import com.rbkmoney.fraudo.FraudoPaymentBaseVisitor;
|
||||
import com.rbkmoney.fraudo.FraudoPaymentParser;
|
||||
import com.rbkmoney.fraudo.constant.ResultStatus;
|
||||
import com.rbkmoney.fraudo.converter.TrustConditionConverter;
|
||||
import com.rbkmoney.fraudo.exception.NotImplementedOperatorException;
|
||||
@ -11,11 +12,7 @@ import com.rbkmoney.fraudo.model.ResultModel;
|
||||
import com.rbkmoney.fraudo.model.RuleResult;
|
||||
import com.rbkmoney.fraudo.model.TrustCondition;
|
||||
import com.rbkmoney.fraudo.payment.generator.RuleKeyGenerator;
|
||||
import com.rbkmoney.fraudo.payment.visitor.CountVisitor;
|
||||
import com.rbkmoney.fraudo.payment.visitor.CustomFuncVisitor;
|
||||
import com.rbkmoney.fraudo.payment.visitor.IsTrustedFuncVisitor;
|
||||
import com.rbkmoney.fraudo.payment.visitor.ListVisitor;
|
||||
import com.rbkmoney.fraudo.payment.visitor.SumVisitor;
|
||||
import com.rbkmoney.fraudo.payment.visitor.*;
|
||||
import com.rbkmoney.fraudo.resolver.FieldResolver;
|
||||
import com.rbkmoney.fraudo.utils.TextUtil;
|
||||
import com.rbkmoney.fraudo.utils.key.generator.CountKeyGenerator;
|
||||
@ -36,7 +33,8 @@ import static com.rbkmoney.fraudo.FraudoPaymentParser.*;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class FirstFindVisitorImpl<T extends BaseModel, U> extends FraudoPaymentBaseVisitor<Object> implements TemplateVisitor<T, ResultModel> {
|
||||
public class FirstFindVisitorImpl<T extends BaseModel, U> extends FraudoPaymentBaseVisitor<Object>
|
||||
implements TemplateVisitor<T, ResultModel> {
|
||||
|
||||
private ThreadLocal<Map<String, Object>> localFuncCache = ThreadLocal.withInitial(HashMap::new);
|
||||
private ThreadLocal<T> threadLocalModel = new ThreadLocal<>();
|
||||
@ -418,4 +416,13 @@ public class FirstFindVisitorImpl<T extends BaseModel, U> extends FraudoPaymentB
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitCard_category(FraudoPaymentParser.Card_categoryContext ctx) {
|
||||
return threadLocalModel.get().getCardCategory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitPayment_system(Payment_systemContext ctx) {
|
||||
return threadLocalModel.get().getPaymentSystem();
|
||||
}
|
||||
}
|
||||
|
@ -100,4 +100,15 @@ public class CountTest extends AbstractPaymentTest {
|
||||
verify(countPaymentAggregator, times(1)).count(anyObject(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void countPhoneTest() throws Exception {
|
||||
InputStream resourceAsStream = CountTest.class.getResourceAsStream("/rules/count_phone.frd");
|
||||
when(countPaymentAggregator.count(anyObject(), any(), any(), any())).thenReturn(10);
|
||||
ParseContext parseContext = getParseContext(resourceAsStream);
|
||||
ResultModel result = invokeParse(parseContext);
|
||||
|
||||
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
|
||||
verify(countPaymentAggregator, times(1)).count(anyObject(), any(), any(), any());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -160,6 +160,34 @@ public class CustomTest extends AbstractPaymentTest {
|
||||
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void paymentSystemTest() throws Exception {
|
||||
InputStream resourceAsStream = CustomTest.class.getResourceAsStream("/rules/paymentSystem.frd");
|
||||
ParseContext parseContext = getParseContext(resourceAsStream);
|
||||
PaymentModel model = new PaymentModel();
|
||||
model.setPaymentSystem("VISA");
|
||||
ResultModel result = invoke(parseContext, model);
|
||||
assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
|
||||
|
||||
model.setPaymentSystem("MIR");
|
||||
result = invoke(parseContext, model);
|
||||
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cardCategoryTest() throws Exception {
|
||||
InputStream resourceAsStream = CustomTest.class.getResourceAsStream("/rules/cardCategory.frd");
|
||||
ParseContext parseContext = getParseContext(resourceAsStream);
|
||||
PaymentModel model = new PaymentModel();
|
||||
model.setCardCategory("credit");
|
||||
ResultModel result = invoke(parseContext, model);
|
||||
assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
|
||||
|
||||
model.setCardCategory("debit");
|
||||
result = invoke(parseContext, model);
|
||||
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void catchTest() throws Exception {
|
||||
InputStream resourceAsStream = CustomTest.class.getResourceAsStream("/rules/catch.frd");
|
||||
|
@ -6,6 +6,7 @@ import java.util.Map;
|
||||
public enum PaymentCheckedField {
|
||||
|
||||
EMAIL("email"),
|
||||
PHONE("phone"),
|
||||
IP("ip"),
|
||||
FINGERPRINT("fingerprint"),
|
||||
COUNTRY_BANK("country_bank"),
|
||||
|
@ -18,6 +18,8 @@ public class PaymentModelFieldResolver implements FieldResolver<PaymentModel, Pa
|
||||
return paymentModel.getFingerprint();
|
||||
case EMAIL:
|
||||
return paymentModel.getEmail();
|
||||
case PHONE:
|
||||
return paymentModel.getPhone();
|
||||
case COUNTRY_BANK:
|
||||
return paymentModel.getBinCountryCode();
|
||||
case CARD_TOKEN:
|
||||
|
2
src/test/resources/rules/cardCategory.frd
Normal file
2
src/test/resources/rules/cardCategory.frd
Normal file
@ -0,0 +1,2 @@
|
||||
rule: cardCategory() = "credit"
|
||||
-> accept;
|
2
src/test/resources/rules/count_phone.frd
Normal file
2
src/test/resources/rules/count_phone.frd
Normal file
@ -0,0 +1,2 @@
|
||||
rule: count("phone", 1444) >= 10 AND count("phone", 1444) >= 9
|
||||
-> decline;
|
2
src/test/resources/rules/paymentSystem.frd
Normal file
2
src/test/resources/rules/paymentSystem.frd
Normal file
@ -0,0 +1,2 @@
|
||||
rule: paymentSystem() = "VISA"
|
||||
-> accept;
|
Loading…
Reference in New Issue
Block a user