Skip to content

Commit

Permalink
Merge pull request #44 from payjp/nonz250/feat-token-tds-finish
Browse files Browse the repository at this point in the history
feat: add token tds_finish.
  • Loading branch information
nonz250 authored Nov 15, 2024
2 parents e2941a2 + 036c147 commit 740bf10
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/main/java/jp/pay/model/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Card extends ExternalAccount implements MetadataStore<Card> {
Map<String, String> metadata = new HashMap<String, String>();
String email;
String phone;
String threeDSecureStatus;

public Card update(Map<String, Object> params)
throws AuthenticationException, InvalidRequestException,
Expand Down Expand Up @@ -201,4 +202,8 @@ public String getPhone() {
return phone;
}

public String getThreeDSecureStatus() {
return threeDSecureStatus;
}

}
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);
}
}
8 changes: 8 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,14 @@ 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());
verifyPost(Token.class, "https://api.pay.jp/v1/tokens/tok_xxxxxxxxxxxxxxxxxxxxxxxx/tds_finish", null);
}

@Test
public void testEventRetrieve() throws PayjpException {
Map<String, Object> listParams = new HashMap<String, Object>();
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/jp/pay/model/ChargeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void unmockPayjpResponseGetter() {
@Test
public void testDeserialize() throws PayjpException, IOException {
String json = resource("charge.json");

Charge ch = APIResource.GSON.fromJson(json, Charge.class);

assertEquals("ch_fa990a4c10672a93053a774730b0a", ch.getId());
Expand Down Expand Up @@ -106,7 +106,8 @@ public void testDeserialize() throws PayjpException, IOException {
assertEquals("e1d8225886e3a7211127df751c86787f", ca.getFingerprint());
assertEquals("[email protected]", ca.getEmail());
assertEquals("+81301234567", ca.getPhone());

assertNull(ca.getThreeDSecureStatus());

assertEquals("Visa", ca.getBrand());
}
}
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");
}
}
3 changes: 2 additions & 1 deletion src/test/resources/jp/pay/model/charge.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"name": "PAY TARO",
"object": "card",
"email": "[email protected]",
"phone": "+81301234567"
"phone": "+81301234567",
"three_d_secure_status": null
},
"created": 1578372537,
"currency": "jpy",
Expand Down
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 740bf10

Please sign in to comment.