Skip to content

Commit

Permalink
feat: add endpoints about ThreeDSecureRequest object.
Browse files Browse the repository at this point in the history
  • Loading branch information
nonz250 committed Nov 15, 2024
1 parent e2941a2 commit 8e1d871
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 0 deletions.
106 changes: 106 additions & 0 deletions src/main/java/jp/pay/model/ThreeDSecureRequest.java
Original file line number Diff line number Diff line change
@@ -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<String, Object> params)
throws AuthenticationException, InvalidRequestException,
APIConnectionException, CardException, APIException {
return all(params, (RequestOptions) null);
}

public static ThreeDSecureRequest create(Map<String, Object> 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<String, Object> 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<String, Object> params, RequestOptions options)
throws AuthenticationException, InvalidRequestException,
APIConnectionException, CardException, APIException {
return request(RequestMethod.POST, classURL(ThreeDSecureRequest.class), params,
ThreeDSecureRequest.class, options);
}
}
4 changes: 4 additions & 0 deletions src/main/java/jp/pay/model/ThreeDSecureRequestCollection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package jp.pay.model;

public class ThreeDSecureRequestCollection extends PayjpCollection<ThreeDSecureRequest> {
}
3 changes: 3 additions & 0 deletions src/main/java/jp/pay/net/APIResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down
89 changes: 89 additions & 0 deletions src/test/java/jp/pay/model/ThreeDSecureRequestTest.java
Original file line number Diff line number Diff line change
@@ -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<String, Object> listParams = new HashMap<String, Object>();
listParams.put("limit", 2);
stubNetwork(ThreeDSecureRequestCollection.class, "{\"count\":2,\"data\":[{\"id\":\"tdsr_xxxxx\"},{\"id\":\"tdsr_yyyyy\"}]}");
List<ThreeDSecureRequest> 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<String, Object> createThreeDSecureRequestParams = new HashMap<String, Object>();
createThreeDSecureRequestParams.put("resource_id", "car_xxxxx");
ThreeDSecureRequest threeDSecureRequest = ThreeDSecureRequest.create(createThreeDSecureRequestParams);
assertEquals(threeDSecureRequest.getId(), "tdsr_xxxxx");
assertEquals(threeDSecureRequest.getResourceId(), "car_xxxxx");
}
}
14 changes: 14 additions & 0 deletions src/test/resources/jp/pay/model/three_d_secure_request.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 8e1d871

Please sign in to comment.