Skip to content

Commit d02605f

Browse files
authored
Merge pull request #216 from Riskified/DEV-135811
DEV-135811: Support digital wallets in the SDK
2 parents 7bbba42 + c540425 commit d02605f

7 files changed

Lines changed: 363 additions & 68 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ lib/*
1414
*/target/
1515
/target/
1616
/.metadata/
17-
.metals/*
17+
.metals/*
18+
.vscode/

.vscode/launch.json

Lines changed: 0 additions & 63 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Riskified JAVA SDK
22
=================
33

4-
version: 6.3.1
4+
version: 6.4.0
55
------------------
66

77
See https://developers.riskified.com/reference/api-overview for full API documentation
@@ -104,7 +104,7 @@ curl -H "Content-Type: application/json" -H "X-RISKIFIED-HMAC-SHA256: 071ef80d5
104104
<dependency>
105105
<groupId>com.riskified</groupId>
106106
<artifactId>riskified-sdk</artifactId>
107-
<version>6.3.1</version>
107+
<version>6.4.0</version>
108108
</dependency>
109109
```
110110

riskified-sdk/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.riskified</groupId>
66
<artifactId>riskified-sdk</artifactId>
7-
<version>6.3.1</version>
7+
<version>6.4.0</version>
88
<name>Riskified SDK</name>
99
<description>Riskified rest api SDK for java</description>
1010
<url>https://www.riskified.com</url>

riskified-sdk/src/main/java/com/riskified/JSONFormater.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.riskified.models.IPaymentDetails;
1212
import com.riskified.models.PaypalPaymentDetails;
1313
import com.riskified.models.StripePaymentDetails;
14+
import com.riskified.models.WalletPaymentDetails;
1415

1516
public class JSONFormater {
1617

@@ -34,7 +35,8 @@ public static RuntimeTypeAdapterFactory paymentDetailsSerializer() {
3435
.registerSubtype(PaypalPaymentDetails.class, "paypal")
3536
.registerSubtype(StripePaymentDetails.class, "stripe")
3637
.registerSubtype(CreditCardPaymentDetails.class, "credit_card")
37-
.registerSubtype(BankWirePaymentDetails.class, "bank_wire");
38+
.registerSubtype(BankWirePaymentDetails.class, "bank_wire")
39+
.registerSubtype(WalletPaymentDetails.class, "digital_wallet");
3840
}
3941

4042
}
Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
package com.riskified.models;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.Date;
6+
import java.util.List;
7+
import java.util.Locale;
8+
import java.util.function.Predicate;
9+
10+
import com.riskified.validations.*;
11+
12+
public class WalletPaymentDetails implements IPaymentDetails {
13+
14+
private static final List<PaymentType> WALLET_PAYMENT_TYPES = Arrays.asList(
15+
PaymentType.APPLE_PAY,
16+
PaymentType.GOOGLE_PAY,
17+
PaymentType.SAMSUNG_PAY,
18+
PaymentType.WECHAT_PAY,
19+
PaymentType.AMAZON_PAY,
20+
PaymentType.ALIPAY);
21+
22+
private static final List<String> VALID_ACQUIRER_REGIONS = Arrays.asList("EU", "NONEU");
23+
24+
// A rule = a check plus the message to raise if it fails.
25+
// Add new rules here instead of adding branches in validate().
26+
private static final List<Rule> RULES = Arrays.asList(
27+
new Rule(p -> p.paymentType != null, "Payment Type can't be null."),
28+
new Rule(p -> p.paymentType == null || WALLET_PAYMENT_TYPES.contains(p.paymentType),
29+
"Payment Type must be one of: " + supportedPaymentTypes()),
30+
new Rule(p -> p.authorizationId != null && !p.authorizationId.isEmpty(),
31+
"Authorization Id can't be null or empty."),
32+
new Rule(p -> p.avsResultCode != null && !p.avsResultCode.isEmpty(),
33+
"AVS Result Code can't be null or empty."),
34+
new Rule(p -> p.creditCardCountry == null || isValidCountryCode(p.creditCardCountry),
35+
"Credit Card Country is not a valid ISO country code."),
36+
new Rule(p -> p.acquirerRegion == null || VALID_ACQUIRER_REGIONS.contains(p.acquirerRegion),
37+
"Acquirer Region must be one of: " + VALID_ACQUIRER_REGIONS),
38+
new Rule(p -> p.expiryMonth == null || (p.expiryMonth >= 1 && p.expiryMonth <= 12),
39+
"Expiry Month must be between 01 and 12"),
40+
new Rule(p -> p.expiryYear == null || (p.expiryYear >= 1900 && p.expiryYear <= 9999),
41+
"Expiry Year must be a 4-digit integer formatted as YYYY"));
42+
43+
private PaymentType paymentType;
44+
private String avsResultCode;
45+
private String creditCardCompany;
46+
private String creditCardCountry;
47+
private String creditCardToken;
48+
private String cardholderName;
49+
private String authorizationId;
50+
private String mid;
51+
private String id;
52+
private Date storedPaymentCreatedAt;
53+
private Date storedPaymentUpdatedAt;
54+
private Integer installments;
55+
private String acquirerBin;
56+
private String acquirerRegion;
57+
private AuthorizationType authorizationType;
58+
private Integer expiryMonth;
59+
private Integer expiryYear;
60+
private Double initialPaymentAmount;
61+
private Integer paymentFrequency;
62+
private String billingAddressId;
63+
private AuthenticationResult authenticationResult;
64+
65+
public WalletPaymentDetails(PaymentType paymentType, String authorizationId, String avsResultCode) {
66+
this.paymentType = paymentType;
67+
this.authorizationId = authorizationId;
68+
this.avsResultCode = avsResultCode;
69+
}
70+
71+
public void validate(Validation validationType) throws FieldBadFormatException {
72+
if (validationType != Validation.ALL) {
73+
return;
74+
}
75+
for (Rule rule : RULES) {
76+
if (!rule.passes(this)) {
77+
throw new FieldBadFormatException(this, rule.message());
78+
}
79+
}
80+
}
81+
82+
private static String supportedPaymentTypes() {
83+
List<String> names = new ArrayList<String>(WALLET_PAYMENT_TYPES.size());
84+
for (PaymentType type : WALLET_PAYMENT_TYPES) {
85+
names.add(type.name().toLowerCase());
86+
}
87+
return names.toString();
88+
}
89+
90+
private static boolean isValidCountryCode(String countryCode) {
91+
return Arrays.asList(Locale.getISOCountries()).contains(countryCode);
92+
}
93+
94+
private static final class Rule {
95+
private final Predicate<WalletPaymentDetails> check;
96+
private final String message;
97+
98+
Rule(Predicate<WalletPaymentDetails> check, String message) {
99+
this.check = check;
100+
this.message = message;
101+
}
102+
103+
boolean passes(WalletPaymentDetails details) {
104+
return check.test(details);
105+
}
106+
107+
String message() {
108+
return message;
109+
}
110+
}
111+
112+
public PaymentType getPaymentType() {
113+
return paymentType;
114+
}
115+
116+
public void setPaymentType(PaymentType paymentType) {
117+
this.paymentType = paymentType;
118+
}
119+
120+
public String getAvsResultCode() {
121+
return avsResultCode;
122+
}
123+
124+
public void setAvsResultCode(String avsResultCode) {
125+
this.avsResultCode = avsResultCode;
126+
}
127+
128+
public String getCreditCardCompany() {
129+
return creditCardCompany;
130+
}
131+
132+
public void setCreditCardCompany(String creditCardCompany) {
133+
this.creditCardCompany = creditCardCompany;
134+
}
135+
136+
public String getCreditCardCountry() {
137+
return creditCardCountry;
138+
}
139+
140+
public void setCreditCardCountry(String creditCardCountry) {
141+
this.creditCardCountry = creditCardCountry;
142+
}
143+
144+
public String getCreditCardToken() {
145+
return creditCardToken;
146+
}
147+
148+
public void setCreditCardToken(String creditCardToken) {
149+
this.creditCardToken = creditCardToken;
150+
}
151+
152+
public String getCardholderName() {
153+
return cardholderName;
154+
}
155+
156+
public void setCardholderName(String cardholderName) {
157+
this.cardholderName = cardholderName;
158+
}
159+
160+
public String getAuthorizationId() {
161+
return authorizationId;
162+
}
163+
164+
public void setAuthorizationId(String authorizationId) {
165+
this.authorizationId = authorizationId;
166+
}
167+
168+
public String getMid() {
169+
return mid;
170+
}
171+
172+
public void setMid(String mid) {
173+
this.mid = mid;
174+
}
175+
176+
public String getId() {
177+
return id;
178+
}
179+
180+
public void setId(String id) {
181+
this.id = id;
182+
}
183+
184+
public Date getStoredPaymentCreatedAt() {
185+
return storedPaymentCreatedAt;
186+
}
187+
188+
public void setStoredPaymentCreatedAt(Date storedPaymentCreatedAt) {
189+
this.storedPaymentCreatedAt = storedPaymentCreatedAt;
190+
}
191+
192+
public Date getStoredPaymentUpdatedAt() {
193+
return storedPaymentUpdatedAt;
194+
}
195+
196+
public void setStoredPaymentUpdatedAt(Date storedPaymentUpdatedAt) {
197+
this.storedPaymentUpdatedAt = storedPaymentUpdatedAt;
198+
}
199+
200+
public Integer getInstallments() {
201+
return installments;
202+
}
203+
204+
public void setInstallments(Integer installments) {
205+
this.installments = installments;
206+
}
207+
208+
public String getAcquirerBin() {
209+
return acquirerBin;
210+
}
211+
212+
public void setAcquirerBin(String acquirerBin) {
213+
this.acquirerBin = acquirerBin;
214+
}
215+
216+
public String getAcquirerRegion() {
217+
return acquirerRegion;
218+
}
219+
220+
public void setAcquirerRegion(String acquirerRegion) {
221+
this.acquirerRegion = acquirerRegion;
222+
}
223+
224+
public AuthorizationType getAuthorizationType() {
225+
return authorizationType;
226+
}
227+
228+
public void setAuthorizationType(AuthorizationType authorizationType) {
229+
this.authorizationType = authorizationType;
230+
}
231+
232+
public Integer getExpiryMonth() {
233+
return expiryMonth;
234+
}
235+
236+
public void setExpiryMonth(Integer expiryMonth) {
237+
this.expiryMonth = expiryMonth;
238+
}
239+
240+
public Integer getExpiryYear() {
241+
return expiryYear;
242+
}
243+
244+
public void setExpiryYear(Integer expiryYear) {
245+
this.expiryYear = expiryYear;
246+
}
247+
248+
public Double getInitialPaymentAmount() {
249+
return initialPaymentAmount;
250+
}
251+
252+
public void setInitialPaymentAmount(Double initialPaymentAmount) {
253+
this.initialPaymentAmount = initialPaymentAmount;
254+
}
255+
256+
public Integer getPaymentFrequency() {
257+
return paymentFrequency;
258+
}
259+
260+
public void setPaymentFrequency(Integer paymentFrequency) {
261+
this.paymentFrequency = paymentFrequency;
262+
}
263+
264+
public String getBillingAddressId() {
265+
return billingAddressId;
266+
}
267+
268+
public void setBillingAddressId(String billingAddressId) {
269+
this.billingAddressId = billingAddressId;
270+
}
271+
272+
public AuthenticationResult getAuthenticationResult() {
273+
return authenticationResult;
274+
}
275+
276+
public void setAuthenticationResult(AuthenticationResult authenticationResult) {
277+
this.authenticationResult = authenticationResult;
278+
}
279+
280+
}

0 commit comments

Comments
 (0)