Skip to content

Commit b168657

Browse files
authored
Added conditional validation for certain fields (#179)
1 parent 704e4ed commit b168657

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

riskified-sdk/src/main/java/com/riskified/models/BaseOrder.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,15 @@ public void validate(Validation validationType) throws FieldBadFormatException {
8383
Validate.notNull(this, this.createdAt, "Created At");
8484
Validate.notNull(this, this.updatedAt, "Updated At");
8585
Validate.notNullOrEmpty(this, this.gateway, "Gateway");
86-
Validate.notNullOrEmpty(this, this.browserIp, "Browser IP");
86+
if (this.source != null && !this.source.equalsIgnoreCase("phone")){
87+
Validate.notNullOrEmpty(this, this.browserIp, "Browser IP");
88+
}
89+
8790
Validate.notNull(this, this.totalPrice, "Total Price");
8891
Validate.notNull(this, this.lineItems, "Line Items");
89-
Validate.notNull(this, this.paymentDetails, "Payment Details");
92+
if (this.gateway != null && !this.gateway.equalsIgnoreCase("giftcard")){
93+
Validate.notNull(this, this.paymentDetails, "Payment Details");
94+
}
9095
Validate.notNull(this, this.customer, "Customer");
9196
Validate.notNull(this, this.billingAddress, "Billing Address");
9297
}

riskified-sdk/src/main/java/com/riskified/models/Customer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ public Customer(String email, String firstName, String lastName, String id, Date
6262
public void validate(Validation validationType) throws FieldBadFormatException {
6363

6464
if (validationType == Validation.ALL) {
65-
Validate.notNullOrEmpty(this, this.email, "Email");
6665
Validate.notNullOrEmpty(this, this.firstName, "First Name");
6766
Validate.notNullOrEmpty(this, this.lastName, "Last Name");
68-
Validate.notNullOrEmpty(this, this.id, "Id");
69-
Validate.notNull(this, this.createdAt, "Created At");
70-
Validate.notNull(this, this.verifiedEmail, "Verified Email");
67+
if (this.accountType != null && !this.accountType.equalsIgnoreCase("guest")){
68+
Validate.notNullOrEmpty(this, this.email, "Email");
69+
Validate.notNullOrEmpty(this, this.id, "Id");
70+
Validate.notNull(this, this.createdAt, "Created At");
71+
Validate.notNull(this, this.verifiedEmail, "Verified Email");
72+
}
7173
}
7274

7375
if (this.email != null) {

0 commit comments

Comments
 (0)