Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add endpoints about ThreeDSecureRequest object. #45

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Add this dependency to your project's POM:
<dependency>
<groupId>jp.pay</groupId>
<artifactId>payjp-java</artifactId>
<version>0.7.3</version>
<version>0.8.0</version>
</dependency>
```

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.3
0.8.0
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>jp.pay</groupId>
<artifactId>payjp-java</artifactId>
<packaging>jar</packaging>
<version>0.7.3</version>
<version>0.8.0</version>
<name>pay-java</name>
<url>https://github.com/payjp/payjp-java</url>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jp/pay/Payjp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
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
91 changes: 91 additions & 0 deletions src/test/java/jp/pay/model/ThreeDSecureRequestTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここら辺に verifyPost(ThreeDSecureRequest.class, "https://api.pay.jp/v1/three_d_secure_requests", createThreeDSecureRequestParams); とか追加したい

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました✍
イメージあってますかね?
8c52bf7

assertEquals(threeDSecureRequest.getResourceId(), "car_xxxxx");
verifyPost(ThreeDSecureRequest.class, "https://api.pay.jp/v1/three_d_secure_requests", createThreeDSecureRequestParams);
}
}
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"
}