Skip to content

Commit fee4810

Browse files
authored
Merge pull request #43 from Riskified/psd2
Psd2
2 parents 7f74ee0 + 51f577e commit fee4810

18 files changed

Lines changed: 528 additions & 50 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ lib/*
1313
*/bin/
1414
*/target/
1515
/target/
16+
/.metadata/

riskified-sample/11313414.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"id":"11313414","email":"test@gmail.com","created_at":"2014-12-15T00:20-05:00","currency":"EUR","gateway":"mypaymentprocessor","total_price":950.0,"browser_ip":"124.185.86.55","customer":{"email":"great.customer@example.com","first_name":"john","last_name":"smith","created_at":"2014-01-01T00:20-05:00","id":"999","orders_count":10,"verified_email":true,"social":[]},"line_items":[{"price":200.0,"quantity":4,"title":"Cool shirt","product_id":"AAA2","properties":[],"tax_lines":[],"category":"Shirts - Men"}],"cart_token":"1sdaf23j212","shipping_address":{"first_name":"John","last_name":"Doe","city":"NYC","phone":"1234567","country":"United States","country_code":"US","company":"Kansas Computers","address1":"108 Main Street","province_code":"NY","zip":"64155"},"billing_address":{"first_name":"John","last_name":"Doe","city":"NYC","phone":"1234567","country":"United States","country_code":"US","company":"Kansas Computers","address1":"108 Main Street","province_code":"NY","zip":"64155"},"payment_details":[{}],"shipping_lines":[{"price":25.0,"title":"express"}]}

riskified-sample/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<dependency>
1010
<groupId>com.riskified</groupId>
1111
<artifactId>riskified-sdk</artifactId>
12-
<version>1.2.3</version>
12+
<version>1.2.4</version>
1313
</dependency>
1414

1515
<dependency>

riskified-sample/src/main/java/com/riskified/samples/orderClient/AccommodationClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private static Order generateOrder() {
7474

7575
order.setDiscountCodes(Arrays.asList(new DiscountCode(20, "10")));
7676

77-
order.setPaymentDetails(new CreditCardPaymentDetails("370002", "y", "n", "xxxx-xxxx-xxxx-1234", "VISA"));
77+
order.setPaymentDetails(Arrays.asList(new CreditCardPaymentDetails("370002", "y", "n", "xxxx-xxxx-xxxx-1234", "VISA")));
7878

7979
Address address = new Address("John", "Doe", "108 Main Street", "NYC", "1234567", "United States");
8080
address.setCompany("Kansas Computers");

riskified-sample/src/main/java/com/riskified/samples/orderClient/Client.java

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
public class Client {
1616
public static void main(String[] arg) throws FieldBadFormatException, ParseException {
1717

18-
CheckoutOrder checkoutOrder = generateCheckoutOrder();
18+
CheckoutOrder adviseOrder = generateAdviseOrder();
19+
20+
CheckoutOrder checkoutOrder = generateCheckoutOrder();
1921

2022
CheckoutDeniedOrder checkoutDeniedOrder = generateCheckoutDeniedOrder();
2123

@@ -39,12 +41,25 @@ public static void main(String[] arg) throws FieldBadFormatException, ParseExcep
3941
// Or according 'riskified_sdk.properties' configuration file, like this:
4042
RiskifiedClient client = new RiskifiedClient();
4143

44+
Response resAdviseOrder = client.adviseOrder(adviseOrder);
45+
46+
System.out.println("Advise order response:");
47+
System.out.println("id: " + resAdviseOrder.getOrder().getId());
48+
System.out.println("status: " + resAdviseOrder.getOrder().getStatus());
49+
System.out.println("score: " + resAdviseOrder.getOrder().getScore());
50+
System.out.println("auth_type: " + resAdviseOrder.getOrder().getAuthenticationType().getAuthType());
51+
52+
System.out.println("-----------------------------------------");
53+
54+
4255
Response resCheckoutOrder = client.checkoutOrder(checkoutOrder);
4356

44-
System.out.println("Checkout order response:");
57+
System.out.println("Checkout create order response:");
4558
System.out.println("id: " + resCheckoutOrder.getOrder().getId());
4659
System.out.println("status: " + resCheckoutOrder.getOrder().getStatus());
4760
System.out.println("description: " + resCheckoutOrder.getOrder().getDescription());
61+
62+
4863

4964
Response resCheckoutDeniedOrder = client.checkoutDeniedOrder(checkoutDeniedOrder);
5065

@@ -196,7 +211,7 @@ private static FulfillmentOrder generateFulfillmentOrder(Order order) throws Par
196211
private static CheckoutOrder generateCheckoutOrder() throws ParseException {
197212
CheckoutOrder order = new CheckoutOrder();
198213

199-
order.setId("221212");
214+
order.setId("221211112");
200215
order.setName("#1234");
201216
order.setEmail("great.customer@example.com");
202217
order.setCreatedAt(parseDate("15-12-2016 00:00:00.0"));
@@ -218,9 +233,69 @@ private static CheckoutOrder generateCheckoutOrder() throws ParseException {
218233

219234
order.setDiscountCodes(Arrays.asList(new DiscountCode(19.95, "12")));
220235

236+
order.setShippingLines(Arrays.asList(new ShippingLine(123, "free")));
237+
order.setPaymentDetails(Arrays.asList(new CreditCardPaymentDetails("370002", "y", "n", "xxxx-xxxx-xxxx-1234", "VISA")));
238+
239+
240+
Address address = new Address("John", "Doe", "108 Main Street", "NYC", "1234567", "United States");
241+
address.setCompany("Kansas Computers");
242+
address.setCountryCode("US");
243+
address.setName("John Doe");
244+
address.setAddress2("Apartment 12");
245+
address.setProvince("New York");
246+
address.setProvinceCode("NY");
247+
address.setZip("64155");
248+
order.setBillingAddress(address);
249+
250+
address = new Address("John", "Doe", "108 Main Street", "NYC", "1234567", "United States");
251+
address.setCompany("Kansas Computers");
252+
address.setCountryCode("US");
253+
address.setName("John Doe");
254+
address.setAddress2("Apartment 12");
255+
address.setProvince("New York");
256+
address.setProvinceCode("NY");
257+
address.setZip("64155");
258+
order.setShippingAddress(address);
259+
260+
261+
return order;
262+
}
263+
264+
private static CheckoutOrder generateAdviseOrder() throws ParseException {
265+
CheckoutOrder order = new CheckoutOrder();
266+
267+
order.setId("99992328882");
268+
order.setName("#123422111");
269+
order.setEmail("great.customer_2@example.com");
270+
order.setCreatedAt(parseDate("04-04-2018 00:00:00.0"));
271+
order.setClosedAt(null);
272+
order.setCurrency("CAD");
273+
order.setUpdatedAt(parseDate("04-05-2018 00:00:00.0"));
274+
order.setBrowserIp("125.185.86.55");
275+
order.setTotalPrice(123.23);
276+
order.setTotalDiscounts(4);
277+
order.setCartToken("1sdaf23j212oodee");
278+
order.setAdditionalEmails(Arrays.asList("my@email.com", "second@email.co.uk"));
279+
order.setNote("Shipped to my hotel.");
280+
order.setReferringSite("google.com");
281+
282+
order.setLineItems(Arrays.asList(
283+
new LineItem(100, 1, "ACME Widget", "101"),
284+
new LineItem(200, 4, "ACME Spring", "202")));
285+
286+
order.setDiscountCodes(Arrays.asList(new DiscountCode(19.95, "12")));
287+
221288
order.setShippingLines(Arrays.asList(new ShippingLine(123, "free")));
222289

223-
order.setPaymentDetails(new CreditCardPaymentDetails("370002", "y", "n", "xxxx-xxxx-xxxx-1234", "VISA"));
290+
CreditCardPaymentDetails creditCardPaymentDetails = new CreditCardPaymentDetails("370002", "y", "n", "xxxx-xxxx-xxxx-1234", "VISA");
291+
creditCardPaymentDetails.setType("CreditCard");
292+
creditCardPaymentDetails.setAcquirerBin("232323");
293+
creditCardPaymentDetails.setGateway("goGateway");
294+
creditCardPaymentDetails.setMid("212212121");
295+
creditCardPaymentDetails.setId("1");
296+
297+
order.setPaymentDetails(Arrays.asList(creditCardPaymentDetails));
298+
224299

225300
Address address = new Address("John", "Doe", "108 Main Street", "NYC", "1234567", "United States");
226301
address.setCompany("Kansas Computers");
@@ -246,6 +321,7 @@ private static CheckoutOrder generateCheckoutOrder() throws ParseException {
246321
return order;
247322
}
248323

324+
249325
private static Order generateOrder() throws ParseException {
250326
Order order = new Order();
251327
order.setId("#12345");
@@ -310,7 +386,7 @@ private static Order generateOrder() throws ParseException {
310386

311387
order.setShippingLines(Arrays.asList(new ShippingLine(123, "free")));
312388

313-
order.setPaymentDetails(new CreditCardPaymentDetails("370002", "y", "n", "xxxx-xxxx-xxxx-1234", "VISA"));
389+
order.setPaymentDetails(Arrays.asList(new CreditCardPaymentDetails("370002", "y", "n", "xxxx-xxxx-xxxx-1234", "VISA")));
314390

315391
Address address = new Address("John", "Doe", "108 Main Street", "NYC", "1234567", "United States");
316392
address.setCompany("Kansas Computers");
@@ -344,7 +420,7 @@ private static CheckoutDeniedOrder generateCheckoutDeniedOrder() throws ParseExc
344420
creditCardPaymentDetails.setAuthorizationError(authorizationError);
345421

346422
CheckoutDeniedOrder checkoutDeniedOrder = new CheckoutDeniedOrder("cd12345");
347-
checkoutDeniedOrder.setPaymentDetails(creditCardPaymentDetails);
423+
checkoutDeniedOrder.setPaymentDetails(Arrays.asList(creditCardPaymentDetails));
348424

349425
return checkoutDeniedOrder;
350426
}

riskified-sample/src/main/java/com/riskified/samples/orderClient/JsonClient.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import java.io.*;
44
import java.text.*;
55
import java.util.*;
6-
import com.riskified.JSONFormmater;
6+
7+
import com.riskified.JSONFormater;
78
import com.riskified.models.*;
89

910
public class JsonClient {
@@ -33,7 +34,7 @@ public static void main(String[] args) throws ParseException, FileNotFoundExcept
3334
order.setLineItems(lineItems);
3435

3536
order.setShippingLines(Arrays.asList(new ShippingLine(25, "express")));
36-
order.setPaymentDetails(new CreditCardPaymentDetails("370002", "y", "n", "xxxx-xxxx-xxxx-1234", "VISA"));
37+
order.setPaymentDetails(Arrays.asList(new CreditCardPaymentDetails("370002", "y", "n", "xxxx-xxxx-xxxx-1234", "VISA")));
3738

3839
Address billingAddress = new Address("John", "Doe", "108 Main Street", "NYC", "1234567", "United States");
3940
billingAddress.setCompany("Kansas Computers");
@@ -49,7 +50,7 @@ public static void main(String[] args) throws ParseException, FileNotFoundExcept
4950
shippingAddress.setZip("64155");
5051
order.setShippingAddress(shippingAddress);
5152

52-
String orderJson = JSONFormmater.toJson(order);
53+
String orderJson = JSONFormater.toJson(order);
5354

5455
// Save the order json to a file
5556
PrintWriter fileWriter = new PrintWriter(orderId + ".json");

riskified-sample/src/main/java/com/riskified/samples/orderClient/SimpleClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private static Order generateOrder() {
113113

114114
order.setShippingLines(Arrays.asList(new ShippingLine(123, "free")));
115115

116-
order.setPaymentDetails(new CreditCardPaymentDetails("370002", "y", "n", "xxxx-xxxx-xxxx-1234", "VISA"));
116+
order.setPaymentDetails(Arrays.asList(new CreditCardPaymentDetails("370002", "y", "n", "xxxx-xxxx-xxxx-1234", "VISA")));
117117

118118

119119
Address address = new Address("John", "Doe", "108 Main Street", "NYC", "1234567", "United States");

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>1.2.3</version>
7+
<version>1.2.4</version>
88
<name>Riskified SDK</name>
99
<description>Riskified rest api SDK for java</description>
1010
<url>https://www.riskified.com</url>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.riskified;
2+
3+
import java.lang.reflect.Type;
4+
import java.text.DateFormat;
5+
import java.text.SimpleDateFormat;
6+
import java.util.Date;
7+
8+
import com.google.gson.*;
9+
import com.riskified.models.BankWirePaymentDetails;
10+
import com.riskified.models.CreditCardPaymentDetails;
11+
import com.riskified.models.IPaymentDetails;
12+
import com.riskified.models.PaypalPaymentDetails;
13+
import sun.security.x509.IPAddressName;
14+
15+
public class JSONFormater {
16+
17+
public static String toJson(Object obj) {
18+
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
19+
.registerTypeAdapter(Date.class, new DateTimeSerializer())
20+
.registerTypeAdapterFactory(paymentDetailsSerializer())
21+
.create();
22+
return gson.toJson(obj);
23+
}
24+
25+
public static class DateTimeSerializer implements JsonSerializer<Date> {
26+
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
27+
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmXXX");
28+
return new JsonPrimitive(df.format(src));
29+
}
30+
}
31+
public static RuntimeTypeAdapterFactory paymentDetailsSerializer() {
32+
return RuntimeTypeAdapterFactory
33+
.of(IPaymentDetails.class, "method")
34+
.registerSubtype(PaypalPaymentDetails.class, "paypal")
35+
.registerSubtype(CreditCardPaymentDetails.class, "credit_card")
36+
.registerSubtype(BankWirePaymentDetails.class, "bank_wire");
37+
}
38+
39+
40+
}

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

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

0 commit comments

Comments
 (0)