Skip to content

Commit

Permalink
feat: add token tds_finish.
Browse files Browse the repository at this point in the history
  • Loading branch information
nonz250 committed Nov 14, 2024
1 parent a4189be commit 4d17f4a
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/jp/pay/model/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> 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);
}
}
7 changes: 7 additions & 0 deletions src/test/java/jp/pay/PayjpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> listParams = new HashMap<String, Object>();
Expand Down
59 changes: 59 additions & 0 deletions src/test/java/jp/pay/model/TokenTest.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
32 changes: 32 additions & 0 deletions src/test/resources/jp/pay/model/token.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"phone": "+81301234567"
},
"created": 1442290383,
"id": "tok_5ca06b51685e001723a2c3b4aeb4",
"livemode": false,
"object": "token",
"used": false
}

0 comments on commit 4d17f4a

Please sign in to comment.