From 4d17f4a043be504fa79dfe2727cd05df0bbe5e8e Mon Sep 17 00:00:00 2001 From: nonz250 Date: Thu, 14 Nov 2024 18:15:12 +0900 Subject: [PATCH] feat: add token tds_finish. --- src/main/java/jp/pay/model/Token.java | 6 +++ src/test/java/jp/pay/PayjpTest.java | 7 +++ src/test/java/jp/pay/model/TokenTest.java | 59 ++++++++++++++++++++++ src/test/resources/jp/pay/model/token.json | 32 ++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 src/test/java/jp/pay/model/TokenTest.java create mode 100755 src/test/resources/jp/pay/model/token.json diff --git a/src/main/java/jp/pay/model/Token.java b/src/main/java/jp/pay/model/Token.java index 2edd79b..9d87615 100644 --- a/src/main/java/jp/pay/model/Token.java +++ b/src/main/java/jp/pay/model/Token.java @@ -112,4 +112,10 @@ public static Token retrieve(String id, RequestOptions options) APIConnectionException, CardException, APIException { return request(RequestMethod.GET, instanceURL(Token.class, id), null, Token.class, options); } + + public static Token tdsFinish(String id, Map params, RequestOptions options) + throws AuthenticationException, InvalidRequestException, + APIConnectionException, CardException, APIException { + return request(RequestMethod.POST, String.format("%s/tds_finish", instanceURL(Token.class, id)), params, Token.class, options); + } } diff --git a/src/test/java/jp/pay/PayjpTest.java b/src/test/java/jp/pay/PayjpTest.java index ff2b66c..bbda384 100644 --- a/src/test/java/jp/pay/PayjpTest.java +++ b/src/test/java/jp/pay/PayjpTest.java @@ -937,6 +937,13 @@ public void testTokenUse() throws PayjpException { assertTrue(retrievedToken.getUsed()); } + @Test + public void testTokenTdsFinish() throws PayjpException { + stubNetwork(Token.class, "{\"id\":\"tok_xxxxxxxxxxxxxxxxxxxxxxxx\"}"); + Token token = Token.tdsFinish("tok_xxxxxxxxxxxxxxxxxxxxxxxx", null, null); + assertEquals("tok_xxxxxxxxxxxxxxxxxxxxxxxx", token.getId()); + } + @Test public void testEventRetrieve() throws PayjpException { Map listParams = new HashMap(); diff --git a/src/test/java/jp/pay/model/TokenTest.java b/src/test/java/jp/pay/model/TokenTest.java new file mode 100644 index 0000000..f34fa18 --- /dev/null +++ b/src/test/java/jp/pay/model/TokenTest.java @@ -0,0 +1,59 @@ +/* + * 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; + +public class TokenTest extends BasePayjpTest { + @Test + public void testDeserialize() throws PayjpException, IOException { + String json = resource("token.json"); + Token token = APIResource.GSON.fromJson(json, Token.class); + assertEquals(Long.valueOf("1442290383"), token.getCreated()); + assertEquals("tok_5ca06b51685e001723a2c3b4aeb4", token.getId()); + assertEquals(Boolean.FALSE, token.getLivemode()); + assertEquals(Boolean.FALSE, token.getUsed()); + assertEquals("card", token.getCard().getObject()); + } + + @Test + public void testRetrieve() throws PayjpException { + stubNetwork(Token.class, "{\"id\":\"token1\"}"); + Token token = Token.retrieve("token1"); + verifyGet(Token.class, "https://api.pay.jp/v1/tokens/token1"); + assertEquals(token.getId(), "token1"); + } +} diff --git a/src/test/resources/jp/pay/model/token.json b/src/test/resources/jp/pay/model/token.json new file mode 100755 index 0000000..da53f87 --- /dev/null +++ b/src/test/resources/jp/pay/model/token.json @@ -0,0 +1,32 @@ +{ + "card": { + "address_city": null, + "address_line1": null, + "address_line2": null, + "address_state": null, + "address_zip": null, + "address_zip_check": "unchecked", + "brand": "Visa", + "country": null, + "created": 1442290383, + "customer": null, + "cvc_check": "passed", + "exp_month": 2, + "exp_year": 2024, + "fingerprint": "e1d8225886e3a7211127df751c86787f", + "id": "car_e3ccd4e0959f45e7c75bacc4be90", + "livemode": false, + "metadata": {}, + "last4": "4242", + "name": "PAY TARO", + "object": "card", + "three_d_secure_status": "verified", + "email": "liveaccount@example.com", + "phone": "+81301234567" + }, + "created": 1442290383, + "id": "tok_5ca06b51685e001723a2c3b4aeb4", + "livemode": false, + "object": "token", + "used": false +} \ No newline at end of file