From 8e1d87164a077e7ada0b4906385bed3d9b3d2915 Mon Sep 17 00:00:00 2001 From: nonz250 Date: Fri, 15 Nov 2024 10:26:47 +0900 Subject: [PATCH 1/3] feat: add endpoints about ThreeDSecureRequest object. --- .../jp/pay/model/ThreeDSecureRequest.java | 106 ++++++++++++++++++ .../model/ThreeDSecureRequestCollection.java | 4 + src/main/java/jp/pay/net/APIResource.java | 3 + .../jp/pay/model/ThreeDSecureRequestTest.java | 89 +++++++++++++++ .../jp/pay/model/three_d_secure_request.json | 14 +++ 5 files changed, 216 insertions(+) create mode 100644 src/main/java/jp/pay/model/ThreeDSecureRequest.java create mode 100644 src/main/java/jp/pay/model/ThreeDSecureRequestCollection.java create mode 100644 src/test/java/jp/pay/model/ThreeDSecureRequestTest.java create mode 100755 src/test/resources/jp/pay/model/three_d_secure_request.json diff --git a/src/main/java/jp/pay/model/ThreeDSecureRequest.java b/src/main/java/jp/pay/model/ThreeDSecureRequest.java new file mode 100644 index 0000000..cc8711d --- /dev/null +++ b/src/main/java/jp/pay/model/ThreeDSecureRequest.java @@ -0,0 +1,106 @@ +package jp.pay.model; + +import jp.pay.exception.*; +import jp.pay.net.APIResource; +import jp.pay.net.APIResource.RequestMethod; +import jp.pay.net.RequestOptions; + +import java.util.Map; + +public class ThreeDSecureRequest extends APIResource { + String id; + String resourceId; + Boolean livemode; + Long created; + String state; + Long startedAt; + Long resultReceivedAt; + Long finishedAt; + Long expiredAt; + String tenantId; + String threeDSecureStatus; + + public String getId() { + return id; + } + + public String getResourceId() { + return resourceId; + } + + public Boolean getLivemode() { + return livemode; + } + + public Long getCreated() { + return created; + } + + public String getState() { + return state; + } + + public Long getStartedAt() { + return startedAt; + } + + public Long getResultReceivedAt() { + return resultReceivedAt; + } + + public Long getFinishedAt() { + return finishedAt; + } + + public Long getExpiredAt() { + return expiredAt; + } + + public String getTenantId() { + return tenantId; + } + + public String getThreeDSecureStatus() { + return threeDSecureStatus; + } + + public static ThreeDSecureRequest retrieve(String id) throws AuthenticationException, + InvalidRequestException, APIConnectionException, + CardException, APIException { + return retrieve(id, (RequestOptions) null); + } + + public static ThreeDSecureRequestCollection all(Map params) + throws AuthenticationException, InvalidRequestException, + APIConnectionException, CardException, APIException { + return all(params, (RequestOptions) null); + } + + public static ThreeDSecureRequest create(Map params) + throws AuthenticationException, InvalidRequestException, + APIConnectionException, CardException, APIException { + return create(params, (RequestOptions) null); + } + + public static ThreeDSecureRequest retrieve(String id, RequestOptions options) + throws AuthenticationException, InvalidRequestException, + APIConnectionException, CardException, APIException { + return request(RequestMethod.GET, instanceURL( + ThreeDSecureRequest.class, id), null, ThreeDSecureRequest.class, options); + } + + public static ThreeDSecureRequestCollection all(Map params, + RequestOptions options) throws AuthenticationException, + InvalidRequestException, APIConnectionException, + CardException, APIException { + return request(RequestMethod.GET, classURL( + ThreeDSecureRequest.class), params, ThreeDSecureRequestCollection.class, options); + } + + public static ThreeDSecureRequest create(Map params, RequestOptions options) + throws AuthenticationException, InvalidRequestException, + APIConnectionException, CardException, APIException { + return request(RequestMethod.POST, classURL(ThreeDSecureRequest.class), params, + ThreeDSecureRequest.class, options); + } +} diff --git a/src/main/java/jp/pay/model/ThreeDSecureRequestCollection.java b/src/main/java/jp/pay/model/ThreeDSecureRequestCollection.java new file mode 100644 index 0000000..77acbef --- /dev/null +++ b/src/main/java/jp/pay/model/ThreeDSecureRequestCollection.java @@ -0,0 +1,4 @@ +package jp.pay.model; + +public class ThreeDSecureRequestCollection extends PayjpCollection { +} diff --git a/src/main/java/jp/pay/net/APIResource.java b/src/main/java/jp/pay/net/APIResource.java index 4236bc5..d57ced2 100644 --- a/src/main/java/jp/pay/net/APIResource.java +++ b/src/main/java/jp/pay/net/APIResource.java @@ -42,6 +42,7 @@ import jp.pay.model.PayjpObjectDeserializer; import jp.pay.model.PayjpRawJsonObject; import jp.pay.model.PayjpRawJsonObjectDeserializer; +import jp.pay.model.ThreeDSecureRequest; public abstract class APIResource extends PayjpObject { private static PayjpResponseGetter payjpResponseGetter = new LivePayjpResponseGetter(); @@ -68,6 +69,8 @@ private static String className(Class clazz) { return "file"; } else if (className.equals("bitcoinreceiver")) { return "bitcoin_receiver"; + } else if (className.equals(ThreeDSecureRequest.class.getSimpleName().toLowerCase())) { + return "three_d_secure_request"; } else { return className; } diff --git a/src/test/java/jp/pay/model/ThreeDSecureRequestTest.java b/src/test/java/jp/pay/model/ThreeDSecureRequestTest.java new file mode 100644 index 0000000..f1e45f1 --- /dev/null +++ b/src/test/java/jp/pay/model/ThreeDSecureRequestTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2010-2011 Stripe (http://stripe.com) + * Copyright (c) 2024 PAY, Inc. (http://pay.co.jp/) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ +package jp.pay.model; + + +import jp.pay.net.APIResource; + +import org.junit.Test; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import jp.pay.exception.PayjpException; +import jp.pay.BasePayjpTest; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class ThreeDSecureRequestTest extends BasePayjpTest { + @Test + public void testDeserialize() throws PayjpException, IOException { + String json = resource("three_d_secure_request.json"); + ThreeDSecureRequest threeDSecureRequest = APIResource.GSON.fromJson(json, ThreeDSecureRequest.class); + assertEquals(threeDSecureRequest.getId(), "tdsr_125192559c91c4011c1ff56f50a"); + assertEquals(threeDSecureRequest.getResourceId(), "car_4ec110e0700daf893160424fe03c"); + assertEquals(threeDSecureRequest.getLivemode(), true); + assertEquals(threeDSecureRequest.getCreated().longValue(), 1730084767); + assertEquals(threeDSecureRequest.getState(), "created"); + assertEquals(threeDSecureRequest.getThreeDSecureStatus(), "unverified"); + assertEquals(threeDSecureRequest.getStartedAt(), null); + assertEquals(threeDSecureRequest.getResultReceivedAt(), null); + assertEquals(threeDSecureRequest.getFinishedAt(), null); + assertEquals(threeDSecureRequest.getExpiredAt(), null); + assertEquals(threeDSecureRequest.getTenantId(), null); + } + + @Test + public void testRetrieve() throws PayjpException { + stubNetwork(ThreeDSecureRequest.class, "{\"id\":\"tdsr_xxxxx\"}"); + ThreeDSecureRequest threeDSecureRequest = ThreeDSecureRequest.retrieve("tdsr_xxxxx"); + verifyGet(ThreeDSecureRequest.class, "https://api.pay.jp/v1/three_d_secure_requests/tdsr_xxxxx"); + assertEquals(threeDSecureRequest.getId(), "tdsr_xxxxx"); + } + + @Test + public void testList() throws PayjpException { + Map listParams = new HashMap(); + listParams.put("limit", 2); + stubNetwork(ThreeDSecureRequestCollection.class, "{\"count\":2,\"data\":[{\"id\":\"tdsr_xxxxx\"},{\"id\":\"tdsr_yyyyy\"}]}"); + List threeDSecureRequests = ThreeDSecureRequest.all(listParams).getData(); + verifyGet(ThreeDSecureRequestCollection.class, "https://api.pay.jp/v1/three_d_secure_requests", listParams); + assertEquals(threeDSecureRequests.size(), 2); + assertEquals(threeDSecureRequests.get(0).getId(), "tdsr_xxxxx"); + assertEquals(threeDSecureRequests.get(1).getId(), "tdsr_yyyyy"); + } + + @Test + public void testCreate() throws PayjpException { + stubNetwork(ThreeDSecureRequest.class, "{\"id\":tdsr_xxxxx,\"resource_id\":car_xxxxx}"); + Map createThreeDSecureRequestParams = new HashMap(); + createThreeDSecureRequestParams.put("resource_id", "car_xxxxx"); + ThreeDSecureRequest threeDSecureRequest = ThreeDSecureRequest.create(createThreeDSecureRequestParams); + assertEquals(threeDSecureRequest.getId(), "tdsr_xxxxx"); + assertEquals(threeDSecureRequest.getResourceId(), "car_xxxxx"); + } +} diff --git a/src/test/resources/jp/pay/model/three_d_secure_request.json b/src/test/resources/jp/pay/model/three_d_secure_request.json new file mode 100755 index 0000000..597f2ec --- /dev/null +++ b/src/test/resources/jp/pay/model/three_d_secure_request.json @@ -0,0 +1,14 @@ +{ + "created": 1730084767, + "expired_at": null, + "finished_at": null, + "id": "tdsr_125192559c91c4011c1ff56f50a", + "livemode": true, + "object": "three_d_secure_request", + "resource_id": "car_4ec110e0700daf893160424fe03c", + "result_received_at": null, + "started_at": null, + "state": "created", + "tenant_id": null, + "three_d_secure_status": "unverified" +} \ No newline at end of file From 2165b4edebeef9112a5670ecbfc12358fe4eb1d4 Mon Sep 17 00:00:00 2001 From: nonz250 Date: Fri, 15 Nov 2024 10:33:15 +0900 Subject: [PATCH 2/3] chore: update version. --- README.md | 4 ++-- VERSION | 2 +- pom.xml | 2 +- src/main/java/jp/pay/Payjp.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2301672..0e3f2fd 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Add this dependency to your project's POM: jp.pay payjp-java - 0.7.3 + 0.8.0 ``` @@ -27,7 +27,7 @@ Add this dependency to your project's POM: Add this dependency to your project's build file: ```groovy -compile "jp.pay:payjp-java:0.7.3" +compile "jp.pay:payjp-java:0.8.0" ``` ### Others diff --git a/VERSION b/VERSION index f38fc53..a3df0a6 100755 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.7.3 +0.8.0 diff --git a/pom.xml b/pom.xml index c58ca3d..85beaec 100755 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ jp.pay payjp-java jar - 0.7.3 + 0.8.0 pay-java https://github.com/payjp/payjp-java diff --git a/src/main/java/jp/pay/Payjp.java b/src/main/java/jp/pay/Payjp.java index 789d5c0..732d9bb 100644 --- a/src/main/java/jp/pay/Payjp.java +++ b/src/main/java/jp/pay/Payjp.java @@ -25,7 +25,7 @@ public abstract class Payjp { public static final String LIVE_API_BASE = "https://api.pay.jp"; - public static final String VERSION = "0.7.3"; + public static final String VERSION = "0.8.0"; public static volatile String apiKey; public static volatile String apiVersion; public static volatile Integer maxRetry = 0; From 8c52bf79416ffb0a7a414458bd1f54a31ac55ff5 Mon Sep 17 00:00:00 2001 From: nonz250 Date: Fri, 15 Nov 2024 11:38:30 +0900 Subject: [PATCH 3/3] test: add verifyPost --- src/test/java/jp/pay/model/ThreeDSecureRequestTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/java/jp/pay/model/ThreeDSecureRequestTest.java b/src/test/java/jp/pay/model/ThreeDSecureRequestTest.java index f1e45f1..a81262d 100644 --- a/src/test/java/jp/pay/model/ThreeDSecureRequestTest.java +++ b/src/test/java/jp/pay/model/ThreeDSecureRequestTest.java @@ -69,7 +69,8 @@ public void testRetrieve() throws PayjpException { public void testList() throws PayjpException { Map listParams = new HashMap(); listParams.put("limit", 2); - stubNetwork(ThreeDSecureRequestCollection.class, "{\"count\":2,\"data\":[{\"id\":\"tdsr_xxxxx\"},{\"id\":\"tdsr_yyyyy\"}]}"); + stubNetwork(ThreeDSecureRequestCollection.class, + "{\"count\":2,\"data\":[{\"id\":\"tdsr_xxxxx\"},{\"id\":\"tdsr_yyyyy\"}]}"); List threeDSecureRequests = ThreeDSecureRequest.all(listParams).getData(); verifyGet(ThreeDSecureRequestCollection.class, "https://api.pay.jp/v1/three_d_secure_requests", listParams); assertEquals(threeDSecureRequests.size(), 2); @@ -85,5 +86,6 @@ public void testCreate() throws PayjpException { ThreeDSecureRequest threeDSecureRequest = ThreeDSecureRequest.create(createThreeDSecureRequestParams); assertEquals(threeDSecureRequest.getId(), "tdsr_xxxxx"); assertEquals(threeDSecureRequest.getResourceId(), "car_xxxxx"); + verifyPost(ThreeDSecureRequest.class, "https://api.pay.jp/v1/three_d_secure_requests", createThreeDSecureRequestParams); } }