From 78ef72644456730c42967289d0ed7d1a925feaa2 Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Wed, 27 Mar 2024 13:16:25 +0900 Subject: [PATCH 01/18] refactor --- src/test/java/jp/pay/BasePayjpTest.java | 20 ++++++++++++++++++++ src/test/java/jp/pay/PayjpTest.java | 13 ------------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/test/java/jp/pay/BasePayjpTest.java b/src/test/java/jp/pay/BasePayjpTest.java index 8b21b98..813c04e 100644 --- a/src/test/java/jp/pay/BasePayjpTest.java +++ b/src/test/java/jp/pay/BasePayjpTest.java @@ -23,6 +23,7 @@ */ package jp.pay; +import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.mockito.ArgumentMatcher; @@ -45,6 +46,9 @@ import jp.pay.net.RequestOptions; import jp.pay.net.PayjpResponseGetter; import jp.pay.net.LivePayjpResponseGetter; + +import static org.mockito.Matchers.argThat; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.*; public class BasePayjpTest { @@ -203,4 +207,20 @@ protected String resource(String path) throws IOException { return os.toString("utf8"); } + + @Before + public void mockPayjpResponseGetter() { + APIResource.setPayjpResponseGetter(networkMock); + } + + @After + public void unmockPayjpResponseGetter() { + /* This needs to be done because tests aren't isolated in Java */ + APIResource.setPayjpResponseGetter(new LivePayjpResponseGetter()); + } + + @BeforeClass + public static void setApiKey() { + Payjp.apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // public api key for test + } } diff --git a/src/test/java/jp/pay/PayjpTest.java b/src/test/java/jp/pay/PayjpTest.java index f669257..ff2b66c 100644 --- a/src/test/java/jp/pay/PayjpTest.java +++ b/src/test/java/jp/pay/PayjpTest.java @@ -84,17 +84,6 @@ static Map getSubscriptionParams() throws PayjpException { return subscriptionParams; } - @Before - public void mockPayjpResponseGetter() { - APIResource.setPayjpResponseGetter(networkMock); - } - - @After - public void unmockPayjpResponseGetter() { - /* This needs to be done because tests aren't isolated in Java */ - APIResource.setPayjpResponseGetter(new LivePayjpResponseGetter()); - } - @Before public void before() { Payjp.apiVersion = null; @@ -102,8 +91,6 @@ public void before() { @BeforeClass public static void setUp() { - Payjp.apiKey = "sk_test_c62fade9d045b54cd76d7036"; // public api key for test - cardSupportedRequestOptions = RequestOptions.builder().setPayjpVersion("2015-06-23").build(); defaultCardParams.put("number", "4242424242424242"); From b37bb70ce0a0eeca2cfd8cfcc30f13afcffab49f Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Wed, 27 Mar 2024 13:16:52 +0900 Subject: [PATCH 02/18] add term and balance object --- src/main/java/jp/pay/model/Balance.java | 83 ++++++++++++++++ .../java/jp/pay/model/BalanceCollection.java | 4 + src/main/java/jp/pay/model/BankInfo.java | 35 +++++++ .../jp/pay/model/PayjpObjectDeserializer.java | 3 + src/main/java/jp/pay/model/Term.java | 77 +++++++++++++++ .../java/jp/pay/model/TermCollection.java | 4 + src/test/java/jp/pay/PayjpBalanceTest.java | 76 +++++++++++++++ src/test/java/jp/pay/PayjpTermTest.java | 72 ++++++++++++++ .../java/jp/pay/model/DeserializerTest.java | 33 +++++++ src/test/resources/jp/pay/model/balance.json | 88 +++++++++++++++++ .../resources/jp/pay/model/balance_event.json | 96 +++++++++++++++++++ .../jp/pay/model/statement_event.json | 54 +++++++++++ src/test/resources/jp/pay/model/term.json | 11 +++ .../resources/jp/pay/model/term_event.json | 19 ++++ 14 files changed, 655 insertions(+) create mode 100644 src/main/java/jp/pay/model/Balance.java create mode 100644 src/main/java/jp/pay/model/BalanceCollection.java create mode 100644 src/main/java/jp/pay/model/BankInfo.java create mode 100644 src/main/java/jp/pay/model/Term.java create mode 100644 src/main/java/jp/pay/model/TermCollection.java create mode 100644 src/test/java/jp/pay/PayjpBalanceTest.java create mode 100644 src/test/java/jp/pay/PayjpTermTest.java create mode 100755 src/test/resources/jp/pay/model/balance.json create mode 100755 src/test/resources/jp/pay/model/balance_event.json create mode 100755 src/test/resources/jp/pay/model/statement_event.json create mode 100755 src/test/resources/jp/pay/model/term.json create mode 100755 src/test/resources/jp/pay/model/term_event.json diff --git a/src/main/java/jp/pay/model/Balance.java b/src/main/java/jp/pay/model/Balance.java new file mode 100644 index 0000000..d8c467e --- /dev/null +++ b/src/main/java/jp/pay/model/Balance.java @@ -0,0 +1,83 @@ +package jp.pay.model; + +import jp.pay.exception.*; +import jp.pay.net.APIResource; +import jp.pay.net.RequestOptions; + +import java.math.BigInteger; +import java.util.List; +import java.util.Map; + + +public class Balance extends APIResource { + Long created; + String id; + Boolean livemode; + BigInteger net; + StatementCollection statements; + String type; + Boolean closed; + String dueDate; + BankInfo bankInfo; + + public Long getCreated() { + return created; + } + + public String getId() { + return id; + } + + public Boolean getLivemode() { + return livemode; + } + + public BigInteger getNet() { + return net; + } + + public StatementCollection getStatements() { + return statements; + } + + public String getType() { + return type; + } + + public Boolean getClosed() { + return closed; + } + + public String getDueDate() { + return dueDate; + } + + public BankInfo getBankInfo() { + return bankInfo; + } + + public static Balance retrieve(String id) throws AuthenticationException, + InvalidRequestException, APIConnectionException, + CardException, APIException { + return retrieve(id, (RequestOptions) null); + } + + public static BalanceCollection all(Map params) + throws AuthenticationException, InvalidRequestException, + APIConnectionException, CardException, APIException { + return all(params, (RequestOptions) null); + } + + public static Balance retrieve(String id, RequestOptions options) + throws AuthenticationException, InvalidRequestException, + APIConnectionException, CardException, APIException { + return request(RequestMethod.GET, instanceURL(Balance.class, id), null, Balance.class, options); + } + + public static BalanceCollection all(Map params, + RequestOptions options) throws AuthenticationException, + InvalidRequestException, APIConnectionException, + CardException, APIException { + return request(RequestMethod.GET, classURL(Statement.class), params, BalanceCollection.class, options); + } +} diff --git a/src/main/java/jp/pay/model/BalanceCollection.java b/src/main/java/jp/pay/model/BalanceCollection.java new file mode 100644 index 0000000..1b70ce5 --- /dev/null +++ b/src/main/java/jp/pay/model/BalanceCollection.java @@ -0,0 +1,4 @@ +package jp.pay.model; + +public class BalanceCollection extends PayjpCollection { +} diff --git a/src/main/java/jp/pay/model/BankInfo.java b/src/main/java/jp/pay/model/BankInfo.java new file mode 100644 index 0000000..8af82dc --- /dev/null +++ b/src/main/java/jp/pay/model/BankInfo.java @@ -0,0 +1,35 @@ +package jp.pay.model; + +public class BankInfo { + String bankCode; + String bankBranchCode; + String bankAccountType; + String bankAccountNumber; + String bankAccountHolderName; + String bankAccountStatus; + + public String getBankCode() { + return bankCode; + } + + public String getBankBranchCode() { + return bankBranchCode; + } + + public String getBankAccountType() { + return bankAccountType; + } + + public String getBankAccountNumber() { + return bankAccountNumber; + } + + public String getBankAccountHolderName() { + return bankAccountHolderName; + } + + public String getBankAccountStatus() { + return bankAccountStatus; + } + +} diff --git a/src/main/java/jp/pay/model/PayjpObjectDeserializer.java b/src/main/java/jp/pay/model/PayjpObjectDeserializer.java index 67e7dd2..279803c 100644 --- a/src/main/java/jp/pay/model/PayjpObjectDeserializer.java +++ b/src/main/java/jp/pay/model/PayjpObjectDeserializer.java @@ -52,6 +52,9 @@ public class PayjpObjectDeserializer implements JsonDeserializer { objectMap.put("transfer", Transfer.class); objectMap.put("summary", Summary.class); objectMap.put("card", Card.class); + objectMap.put("term", Term.class); + objectMap.put("statement", Statement.class); + objectMap.put("balance", Balance.class); } private Object deserializeJsonPrimitive(JsonPrimitive element) { diff --git a/src/main/java/jp/pay/model/Term.java b/src/main/java/jp/pay/model/Term.java new file mode 100644 index 0000000..ef15b47 --- /dev/null +++ b/src/main/java/jp/pay/model/Term.java @@ -0,0 +1,77 @@ +package jp.pay.model; + +import jp.pay.exception.*; +import jp.pay.net.APIResource; +import jp.pay.net.RequestOptions; + +import java.util.Map; + + +public class Term extends APIResource { + Long created; + String id; + Boolean livemode; + Long startAt; + Long endAt; + Integer chargeCount; + Integer refundCount; + Integer disputeCount; + + public Long getCreated() { + return created; + } + + public String getId() { + return id; + } + + public Boolean getLivemode() { + return livemode; + } + + public Long getStartAt() { + return startAt; + } + + public Long getEndAt() { + return endAt; + } + + public Integer getChargeCount() { + return chargeCount; + } + + public Integer getRefundCount() { + return refundCount; + } + + public Integer getDisputeCount() { + return disputeCount; + } + + + public static Term retrieve(String id) throws AuthenticationException, + InvalidRequestException, APIConnectionException, + CardException, APIException { + return retrieve(id, (RequestOptions) null); + } + + public static TermCollection all(Map params) + throws AuthenticationException, InvalidRequestException, + APIConnectionException, CardException, APIException { + return all(params, (RequestOptions) null); + } + + public static Term retrieve(String id, RequestOptions options) + throws AuthenticationException, InvalidRequestException, + APIConnectionException, CardException, APIException { + return request(RequestMethod.GET, instanceURL(Term.class, id), null, Term.class, options); + } + + public static TermCollection all(Map params, + RequestOptions options) throws AuthenticationException, + InvalidRequestException, APIConnectionException, + CardException, APIException { + return request(RequestMethod.GET, classURL(Statement.class), params, TermCollection.class, options); + } +} diff --git a/src/main/java/jp/pay/model/TermCollection.java b/src/main/java/jp/pay/model/TermCollection.java new file mode 100644 index 0000000..cea33b5 --- /dev/null +++ b/src/main/java/jp/pay/model/TermCollection.java @@ -0,0 +1,4 @@ +package jp.pay.model; + +public class TermCollection extends PayjpCollection { +} diff --git a/src/test/java/jp/pay/PayjpBalanceTest.java b/src/test/java/jp/pay/PayjpBalanceTest.java new file mode 100644 index 0000000..73560bd --- /dev/null +++ b/src/test/java/jp/pay/PayjpBalanceTest.java @@ -0,0 +1,76 @@ +/* + * 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; + + +import jp.pay.model.*; +import jp.pay.net.APIResource; + +import org.junit.Test; + +import java.io.IOException; +import java.math.BigInteger; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import jp.pay.exception.PayjpException; +import static org.junit.Assert.assertEquals; + +public class PayjpBalanceTest extends BasePayjpTest { + @Test + public void testDeserialize() throws PayjpException, IOException { + String json = resource("model/balance.json"); + Balance balance = APIResource.GSON.fromJson(json, Balance.class); + assertEquals("ba_b92b879e60f62b532d6756ae56af", balance.getId()); + assertEquals(Long.valueOf("1438354824"), balance.getCreated()); + assertEquals(BigInteger.valueOf(Long.valueOf("12300000000")), balance.getNet()); + StatementCollection statements = balance.getStatements(); + assertEquals("st_178fd25dc7ab7b75906f1c3c4b0e6", statements.getData().get(0).getId()); + assertEquals("st_b4a569b0122a7d08b358f198cf263", statements.getData().get(1).getId()); + } + + @Test + public void testRetrieve() throws PayjpException { + Map listParams = new HashMap(); + listParams.put("limit", 1); + stubNetwork(Balance.class, "{\"id\":\"balance1\"}"); + Balance balance = Balance.retrieve("balance1"); + verifyGet(Balance.class, "https://api.pay.jp/v1/balances/balance1"); + String id = balance.getId(); + assertEquals(id, "balance1"); + } + + @Test + public void testList() throws PayjpException { + Map listParams = new HashMap(); + listParams.put("limit", 1); + stubNetwork(BalanceCollection.class, "{\"count\":1,\"data\":[{\"id\":\"balance1\"}]}"); + List balances = Balance.all(listParams).getData(); + Balance balance = balances.get(0); + String id = balance.getId(); + assertEquals(id, "balance1"); + } + +} diff --git a/src/test/java/jp/pay/PayjpTermTest.java b/src/test/java/jp/pay/PayjpTermTest.java new file mode 100644 index 0000000..12ba7e3 --- /dev/null +++ b/src/test/java/jp/pay/PayjpTermTest.java @@ -0,0 +1,72 @@ +/* + * 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; + + +import 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 static org.junit.Assert.assertEquals; + +public class PayjpTermTest extends BasePayjpTest { + @Test + public void testDeserialize() throws PayjpException, IOException { + String json = resource("model/term.json"); + Term term = APIResource.GSON.fromJson(json, Term.class); + assertEquals("tm_b92b879e60f62b532d6756ae12aa", term.getId()); + assertEquals(Long.valueOf("1438354812"), term.getCreated()); + assertEquals((Integer)987, term.getChargeCount()); + } + + @Test + public void testRetrieve() throws PayjpException { + Map listParams = new HashMap(); + listParams.put("limit", 1); + stubNetwork(Term.class, "{\"id\":\"term1\"}"); + Term term = Term.retrieve("term1"); + verifyGet(Term.class, "https://api.pay.jp/v1/terms/term1"); + String id = term.getId(); + assertEquals(id, "term1"); + } + + @Test + public void testList() throws PayjpException { + Map listParams = new HashMap(); + listParams.put("limit", 1); + stubNetwork(TermCollection.class, "{\"count\":1,\"data\":[{\"id\":\"term1\"}]}"); + List terms = Term.all(listParams).getData(); + Term term = terms.get(0); + String id = term.getId(); + assertEquals(id, "term1"); + } + +} diff --git a/src/test/java/jp/pay/model/DeserializerTest.java b/src/test/java/jp/pay/model/DeserializerTest.java index 4c8a2fc..ceb4008 100644 --- a/src/test/java/jp/pay/model/DeserializerTest.java +++ b/src/test/java/jp/pay/model/DeserializerTest.java @@ -48,4 +48,37 @@ public void deserializeEventDataAccountEvent() throws IOException { Subscription sub = (Subscription)e.getData(); assertEquals("sub_dca9de79e5240009adb994d52974", sub.getId()); } + + @Test + public void deserializeTermEvent() throws IOException { + String json = resource("term_event.json"); + Event e = gson.fromJson(json, Event.class); + + assertEquals(Term.class, e.getData().getClass()); + + Term term = (Term)e.getData(); + assertEquals("tm_b92b879e60f62b532d6756ae12bb", term.getId()); + } + + @Test + public void deserializeStatementEvent() throws IOException { + String json = resource("statement_event.json"); + Event e = gson.fromJson(json, Event.class); + + assertEquals(Statement.class, e.getData().getClass()); + + Statement obj = (Statement)e.getData(); + assertEquals("st_178fd25dc7ab7b75906f5d4c4b0e6", obj.getId()); + } + + @Test + public void deserializeBalanceEvent() throws IOException { + String json = resource("balance_event.json"); + Event e = gson.fromJson(json, Event.class); + + assertEquals(Balance.class, e.getData().getClass()); + + Balance obj = (Balance)e.getData(); + assertEquals("ba_b92b879e60f62b532d6756ae78af", obj.getId()); + } } diff --git a/src/test/resources/jp/pay/model/balance.json b/src/test/resources/jp/pay/model/balance.json new file mode 100755 index 0000000..470b6f0 --- /dev/null +++ b/src/test/resources/jp/pay/model/balance.json @@ -0,0 +1,88 @@ +{ + "created": 1438354824, + "id": "ba_b92b879e60f62b532d6756ae56af", + "livemode": false, + "net": 12300000000, + "object": "balance", + "type": "collecting", + "statements": { + "count": 2, + "data": [ + { + "created": 1695892351, + "id": "st_178fd25dc7ab7b75906f1c3c4b0e6", + "items": [ + { + "amount": 25, + "name": "チャージバックによる手数料返還", + "subject": "chargeback_fee_offset", + "tax_rate": "0.00" + }, + { + "amount": -775, + "name": "チャージバック", + "subject": "chargeback", + "tax_rate": "0.00" + }, + { + "amount": 36, + "name": "返金による手数料返還", + "subject": "refund_fee_offset", + "tax_rate": "0.00" + }, + { + "amount": -1800, + "name": "返金", + "subject": "gross_refund", + "tax_rate": "0.00" + }, + { + "amount": -75, + "name": "決済手数料", + "subject": "fee", + "tax_rate": "0.00" + }, + { + "amount": 3125, + "name": "売上", + "subject": "gross_sales", + "tax_rate": "0.00" + } + ], + "object": "statement", + "livemode": true, + "title": null, + "updated": 1695892351 + }, + { + "created": 1695892350, + "id": "st_b4a569b0122a7d08b358f198cf263", + "items": [ + { + "amount": -10000, + "name": "プロプラン利用料", + "subject": "proplan", + "tax_rate": "10.00" + } + ], + "object": "statement", + "livemode": true, + "title": "プロプラン月額料金", + "updated": 1695892350 + } + ], + "has_more": false, + "object": "list", + "url": "/v1/statements" + }, + "closed": false, + "due_date": null, + "bank_info": { + "bank_code": "0000", + "bank_branch_code": "123", + "bank_account_type": "普通", + "bank_account_number": "1234567", + "bank_account_holder_name": "ペイ タロウ", + "bank_account_status": "pending" + } +} \ No newline at end of file diff --git a/src/test/resources/jp/pay/model/balance_event.json b/src/test/resources/jp/pay/model/balance_event.json new file mode 100755 index 0000000..31dbaaa --- /dev/null +++ b/src/test/resources/jp/pay/model/balance_event.json @@ -0,0 +1,96 @@ +{ + "created": 1432973142, + "data": { + "created": 1438354824, + "id": "ba_b92b879e60f62b532d6756ae78af", + "livemode": false, + "net": 12300000000, + "object": "balance", + "type": "collecting", + "statements": { + "count": 2, + "data": [ + { + "created": 1695892351, + "id": "st_178fd25dc7ab7b75906f1c3c4b0e5", + "items": [ + { + "amount": 25, + "name": "チャージバックによる手数料返還", + "subject": "chargeback_fee_offset", + "tax_rate": "0.00" + }, + { + "amount": -775, + "name": "チャージバック", + "subject": "chargeback", + "tax_rate": "0.00" + }, + { + "amount": 36, + "name": "返金による手数料返還", + "subject": "refund_fee_offset", + "tax_rate": "0.00" + }, + { + "amount": -1800, + "name": "返金", + "subject": "gross_refund", + "tax_rate": "0.00" + }, + { + "amount": -75, + "name": "決済手数料", + "subject": "fee", + "tax_rate": "0.00" + }, + { + "amount": 3125, + "name": "売上", + "subject": "gross_sales", + "tax_rate": "0.00" + } + ], + "object": "statement", + "livemode": true, + "title": null, + "updated": 1695892351 + }, + { + "created": 1695892350, + "id": "st_b4a569b0122a7d08b358f198cf263", + "items": [ + { + "amount": -10000, + "name": "プロプラン利用料", + "subject": "proplan", + "tax_rate": "10.00" + } + ], + "object": "statement", + "livemode": true, + "title": "プロプラン月額料金", + "updated": 1695892350 + } + ], + "has_more": false, + "object": "list", + "url": "/v1/statements" + }, + "closed": false, + "due_date": null, + "bank_info": { + "bank_code": "0000", + "bank_branch_code": "123", + "bank_account_type": "普通", + "bank_account_number": "1234567", + "bank_account_holder_name": "ペイ タロウ", + "bank_account_status": "pending" + } + }, + "id": "evnt_2f7436fe0017098bc8d22221d1e", + "livemode": false, + "object": "event", + "pending_webhooks": 0, + "type": "balance.created" +} \ No newline at end of file diff --git a/src/test/resources/jp/pay/model/statement_event.json b/src/test/resources/jp/pay/model/statement_event.json new file mode 100755 index 0000000..f6604ce --- /dev/null +++ b/src/test/resources/jp/pay/model/statement_event.json @@ -0,0 +1,54 @@ +{ + "created": 1432973142, + "data": { + "created": 1695892351, + "id": "st_178fd25dc7ab7b75906f5d4c4b0e6", + "items": [ + { + "amount": 3125, + "name": "売上", + "subject": "gross_sales", + "tax_rate": "0.00" + }, + { + "amount": -75, + "name": "決済手数料", + "subject": "fee", + "tax_rate": "0.00" + }, + { + "amount": -1800, + "name": "返金", + "subject": "gross_refund", + "tax_rate": "0.00" + }, + { + "amount": 36, + "name": "返金による手数料返還", + "subject": "refund_fee_offset", + "tax_rate": "0.00" + }, + { + "amount": -775, + "name": "チャージバック", + "subject": "chargeback", + "tax_rate": "0.00" + }, + { + "amount": 25, + "name": "チャージバックによる手数料返還", + "subject": "chargeback_fee_offset", + "tax_rate": "0.00" + } + ], + "livemode": true, + "object": "statement", + "title": null, + "updated": 1695892351 + }, + "id": "evnt_2f7436fe0017098bc8d22221d1e", + "livemode": false, + "object": "event", + "pending_webhooks": 0, + "type": "statement.resumed" +} \ No newline at end of file diff --git a/src/test/resources/jp/pay/model/term.json b/src/test/resources/jp/pay/model/term.json new file mode 100755 index 0000000..20dbf1b --- /dev/null +++ b/src/test/resources/jp/pay/model/term.json @@ -0,0 +1,11 @@ +{ + "created": 1438354812, + "id": "tm_b92b879e60f62b532d6756ae12aa", + "livemode": false, + "object": "term", + "charge_count": 987, + "refund_count": 57, + "dispute_count": 4, + "end_at": 1439650800, + "start_at": 1438354801 +} \ No newline at end of file diff --git a/src/test/resources/jp/pay/model/term_event.json b/src/test/resources/jp/pay/model/term_event.json new file mode 100755 index 0000000..0d54c71 --- /dev/null +++ b/src/test/resources/jp/pay/model/term_event.json @@ -0,0 +1,19 @@ +{ + "created": 1432973142, + "data": { + "created": 1438354800, + "id": "tm_b92b879e60f62b532d6756ae12bb", + "livemode": false, + "object": "term", + "charge_count": 158, + "refund_count": 25, + "dispute_count": 2, + "end_at": 1439650800, + "start_at": 1438354801 + }, + "id": "evnt_2f7436fe0017098bc8d222215bc", + "livemode": false, + "object": "event", + "pending_webhooks": 0, + "type": "term.created" +} \ No newline at end of file From fc0589181b4e0ae28afcc3f961b4d13d0cb72254 Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Wed, 27 Mar 2024 13:17:04 +0900 Subject: [PATCH 03/18] upgrade actions cause of below message: The following actions uses node12 which is deprecated and will be forced to run on node16: actions/checkout@v2, actions/setup-java@v2. For more info: https://github.blog/changelog/2023-06-13-github-actions-all-actions-will-run-on-node16-instead-of-node12-by-default/ --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bde0448..fe3e9cb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,9 +11,9 @@ jobs: java-version: [8, 11] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: java-version: ${{ matrix.java-version }} distribution: 'adopt' From 5a09e3086d221eeea09b5860d7d80e45f4b83dee Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Wed, 27 Mar 2024 17:50:20 +0900 Subject: [PATCH 04/18] rename test files --- .../pay/{PayjpBalanceTest.java => model/BalanceTest.java} | 6 +++--- .../java/jp/pay/{PayjpTermTest.java => model/TermTest.java} | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) rename src/test/java/jp/pay/{PayjpBalanceTest.java => model/BalanceTest.java} (96%) rename src/test/java/jp/pay/{PayjpTermTest.java => model/TermTest.java} (96%) diff --git a/src/test/java/jp/pay/PayjpBalanceTest.java b/src/test/java/jp/pay/model/BalanceTest.java similarity index 96% rename from src/test/java/jp/pay/PayjpBalanceTest.java rename to src/test/java/jp/pay/model/BalanceTest.java index 73560bd..bcaeb02 100644 --- a/src/test/java/jp/pay/PayjpBalanceTest.java +++ b/src/test/java/jp/pay/model/BalanceTest.java @@ -21,10 +21,9 @@ * THE SOFTWARE. * */ -package jp.pay; +package jp.pay.model; -import jp.pay.model.*; import jp.pay.net.APIResource; import org.junit.Test; @@ -36,9 +35,10 @@ import java.util.Map; import jp.pay.exception.PayjpException; +import jp.pay.BasePayjpTest; import static org.junit.Assert.assertEquals; -public class PayjpBalanceTest extends BasePayjpTest { +public class BalanceTest extends BasePayjpTest { @Test public void testDeserialize() throws PayjpException, IOException { String json = resource("model/balance.json"); diff --git a/src/test/java/jp/pay/PayjpTermTest.java b/src/test/java/jp/pay/model/TermTest.java similarity index 96% rename from src/test/java/jp/pay/PayjpTermTest.java rename to src/test/java/jp/pay/model/TermTest.java index 12ba7e3..4f45ee6 100644 --- a/src/test/java/jp/pay/PayjpTermTest.java +++ b/src/test/java/jp/pay/model/TermTest.java @@ -21,10 +21,9 @@ * THE SOFTWARE. * */ -package jp.pay; +package jp.pay.model; -import jp.pay.model.*; import jp.pay.net.APIResource; import org.junit.Test; @@ -35,9 +34,10 @@ import java.util.Map; import jp.pay.exception.PayjpException; +import jp.pay.BasePayjpTest; import static org.junit.Assert.assertEquals; -public class PayjpTermTest extends BasePayjpTest { +public class TermTest extends BasePayjpTest { @Test public void testDeserialize() throws PayjpException, IOException { String json = resource("model/term.json"); From ae6b9e64c5d8bb9e0ac8fa0b1bfbf76d14ef3f12 Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Wed, 27 Mar 2024 17:53:23 +0900 Subject: [PATCH 05/18] modify resource file path --- src/test/java/jp/pay/model/BalanceTest.java | 2 +- src/test/java/jp/pay/model/TermTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/jp/pay/model/BalanceTest.java b/src/test/java/jp/pay/model/BalanceTest.java index bcaeb02..9690e97 100644 --- a/src/test/java/jp/pay/model/BalanceTest.java +++ b/src/test/java/jp/pay/model/BalanceTest.java @@ -41,7 +41,7 @@ public class BalanceTest extends BasePayjpTest { @Test public void testDeserialize() throws PayjpException, IOException { - String json = resource("model/balance.json"); + String json = resource("balance.json"); Balance balance = APIResource.GSON.fromJson(json, Balance.class); assertEquals("ba_b92b879e60f62b532d6756ae56af", balance.getId()); assertEquals(Long.valueOf("1438354824"), balance.getCreated()); diff --git a/src/test/java/jp/pay/model/TermTest.java b/src/test/java/jp/pay/model/TermTest.java index 4f45ee6..3e9fd79 100644 --- a/src/test/java/jp/pay/model/TermTest.java +++ b/src/test/java/jp/pay/model/TermTest.java @@ -40,7 +40,7 @@ public class TermTest extends BasePayjpTest { @Test public void testDeserialize() throws PayjpException, IOException { - String json = resource("model/term.json"); + String json = resource("term.json"); Term term = APIResource.GSON.fromJson(json, Term.class); assertEquals("tm_b92b879e60f62b532d6756ae12aa", term.getId()); assertEquals(Long.valueOf("1438354812"), term.getCreated()); From e8ec2f8549d5096cd5102eaa6b0b73a2ec0d4471 Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Wed, 27 Mar 2024 18:00:46 +0900 Subject: [PATCH 06/18] add term_id to Charge object --- src/main/java/jp/pay/model/Charge.java | 5 +++++ src/test/java/jp/pay/model/ChargeTest.java | 1 + src/test/resources/jp/pay/model/charge.json | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/jp/pay/model/Charge.java b/src/main/java/jp/pay/model/Charge.java index 1233866..e1b6055 100644 --- a/src/main/java/jp/pay/model/Charge.java +++ b/src/main/java/jp/pay/model/Charge.java @@ -55,6 +55,7 @@ public class Charge extends APIResource implements MetadataStore { Map metadata = new HashMap(); String feeRate; String threeDSecureStatus; + String termId; public String getId() { return id; @@ -196,6 +197,10 @@ public Map getMetadata() { return metadata; } + public String getTermId() { + return termId; + } + /** * Assigning a whole collection from outside the object is not quite a right thing to do. * Be stick to use getMetadata(). diff --git a/src/test/java/jp/pay/model/ChargeTest.java b/src/test/java/jp/pay/model/ChargeTest.java index 236226a..425b143 100644 --- a/src/test/java/jp/pay/model/ChargeTest.java +++ b/src/test/java/jp/pay/model/ChargeTest.java @@ -84,6 +84,7 @@ public void testDeserialize() throws PayjpException, IOException { assertNull(ch.getMetadata()); assertEquals("3.00", ch.getFeeRate()); assertEquals("attempt", ch.getThreeDSecureStatus()); + assertEquals("tm_b92b879e60f62b532d6756ae12cc", ch.getTermId()); Card ca = ch.getCard(); assertEquals("car_d0e44730f83b0a19ba6caee04160", ca.getId()); diff --git a/src/test/resources/jp/pay/model/charge.json b/src/test/resources/jp/pay/model/charge.json index db37d9f..1b1027a 100755 --- a/src/test/resources/jp/pay/model/charge.json +++ b/src/test/resources/jp/pay/model/charge.json @@ -43,5 +43,6 @@ "subscription": null, "tenant": "ten_121673955bd7aa144de5a8f6c262", "total_platform_fee": 350, - "three_d_secure_status": "attempt" + "three_d_secure_status": "attempt", + "term_id": "tm_b92b879e60f62b532d6756ae12cc" } \ No newline at end of file From a01bfe5d162c977c5c31d3d42bd1c5357ca7bde5 Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Wed, 27 Mar 2024 18:01:09 +0900 Subject: [PATCH 07/18] add term, balance_id to statement object --- src/main/java/jp/pay/model/Statement.java | 11 +++++++++++ src/test/java/jp/pay/model/DeserializerTest.java | 4 ++++ .../resources/jp/pay/model/statement_event.json | 14 +++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/jp/pay/model/Statement.java b/src/main/java/jp/pay/model/Statement.java index def9eab..9918870 100644 --- a/src/main/java/jp/pay/model/Statement.java +++ b/src/main/java/jp/pay/model/Statement.java @@ -15,6 +15,8 @@ public class Statement extends APIResource { Boolean livemode; String title; Long updated; + Term term; + String balanceId; public class StatementItem { Integer amount; @@ -59,6 +61,15 @@ public void setLivemode(Boolean livemode) { this.livemode = livemode; } + public Term getTerm() { + return term; + } + + public String getBalanceId() { + return balanceId; + } + + public static Statement retrieve(String id) throws AuthenticationException, InvalidRequestException, APIConnectionException, diff --git a/src/test/java/jp/pay/model/DeserializerTest.java b/src/test/java/jp/pay/model/DeserializerTest.java index ceb4008..6ccf8fd 100644 --- a/src/test/java/jp/pay/model/DeserializerTest.java +++ b/src/test/java/jp/pay/model/DeserializerTest.java @@ -69,6 +69,10 @@ public void deserializeStatementEvent() throws IOException { Statement obj = (Statement)e.getData(); assertEquals("st_178fd25dc7ab7b75906f5d4c4b0e6", obj.getId()); + assertEquals("ba_b92b879e60f62b532d6756ae90af", obj.getBalanceId()); + + Term term = obj.getTerm(); + assertEquals("tm_b92b879e60f62b532d6756ae12dd", term.getId()); } @Test diff --git a/src/test/resources/jp/pay/model/statement_event.json b/src/test/resources/jp/pay/model/statement_event.json index f6604ce..ab0b65c 100755 --- a/src/test/resources/jp/pay/model/statement_event.json +++ b/src/test/resources/jp/pay/model/statement_event.json @@ -44,7 +44,19 @@ "livemode": true, "object": "statement", "title": null, - "updated": 1695892351 + "updated": 1695892351, + "term": { + "created": 1438354812, + "id": "tm_b92b879e60f62b532d6756ae12dd", + "livemode": false, + "object": "term", + "charge_count": 987, + "refund_count": 57, + "dispute_count": 4, + "end_at": 1439650800, + "start_at": 1438354801 + }, + "balance_id": "ba_b92b879e60f62b532d6756ae90af" }, "id": "evnt_2f7436fe0017098bc8d22221d1e", "livemode": false, From 7adad900670df282750c087b179e791c279af173 Mon Sep 17 00:00:00 2001 From: natsuki-yamanaka Date: Thu, 28 Mar 2024 17:00:21 +0900 Subject: [PATCH 08/18] Update src/main/java/jp/pay/model/Balance.java Co-authored-by: Nozomi Hosaka --- src/main/java/jp/pay/model/Balance.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/jp/pay/model/Balance.java b/src/main/java/jp/pay/model/Balance.java index d8c467e..8300649 100644 --- a/src/main/java/jp/pay/model/Balance.java +++ b/src/main/java/jp/pay/model/Balance.java @@ -5,7 +5,6 @@ import jp.pay.net.RequestOptions; import java.math.BigInteger; -import java.util.List; import java.util.Map; From dd73be4e43e03f676745f493b5e4e4c04f2d7b69 Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Thu, 28 Mar 2024 17:26:26 +0900 Subject: [PATCH 09/18] remove unused import --- src/test/java/jp/pay/model/DeserializerTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/jp/pay/model/DeserializerTest.java b/src/test/java/jp/pay/model/DeserializerTest.java index 6ccf8fd..97402ab 100644 --- a/src/test/java/jp/pay/model/DeserializerTest.java +++ b/src/test/java/jp/pay/model/DeserializerTest.java @@ -30,7 +30,6 @@ import java.io.IOException; import jp.pay.BasePayjpTest; -import jp.pay.model.Event; import jp.pay.net.APIResource; import static org.junit.Assert.assertEquals; From 9e1875a5b58ec210e76ab80a1ba815c0fcb3ac03 Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Thu, 28 Mar 2024 17:51:01 +0900 Subject: [PATCH 10/18] add test, fix list url --- src/main/java/jp/pay/model/Balance.java | 2 +- src/main/java/jp/pay/model/Term.java | 2 +- src/test/java/jp/pay/model/TermTest.java | 18 +++++++++++------- src/test/resources/jp/pay/model/term.json | 8 ++++---- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/jp/pay/model/Balance.java b/src/main/java/jp/pay/model/Balance.java index 8300649..9616ba9 100644 --- a/src/main/java/jp/pay/model/Balance.java +++ b/src/main/java/jp/pay/model/Balance.java @@ -77,6 +77,6 @@ public static BalanceCollection all(Map params, RequestOptions options) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException { - return request(RequestMethod.GET, classURL(Statement.class), params, BalanceCollection.class, options); + return request(RequestMethod.GET, classURL(Balance.class), params, BalanceCollection.class, options); } } diff --git a/src/main/java/jp/pay/model/Term.java b/src/main/java/jp/pay/model/Term.java index ef15b47..be3659a 100644 --- a/src/main/java/jp/pay/model/Term.java +++ b/src/main/java/jp/pay/model/Term.java @@ -72,6 +72,6 @@ public static TermCollection all(Map params, RequestOptions options) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException { - return request(RequestMethod.GET, classURL(Statement.class), params, TermCollection.class, options); + return request(RequestMethod.GET, classURL(Term.class), params, TermCollection.class, options); } } diff --git a/src/test/java/jp/pay/model/TermTest.java b/src/test/java/jp/pay/model/TermTest.java index 3e9fd79..8a2d3ce 100644 --- a/src/test/java/jp/pay/model/TermTest.java +++ b/src/test/java/jp/pay/model/TermTest.java @@ -42,9 +42,13 @@ public class TermTest extends BasePayjpTest { public void testDeserialize() throws PayjpException, IOException { String json = resource("term.json"); Term term = APIResource.GSON.fromJson(json, Term.class); - assertEquals("tm_b92b879e60f62b532d6756ae12aa", term.getId()); assertEquals(Long.valueOf("1438354812"), term.getCreated()); + assertEquals("tm_b92b879e60f62b532d6756ae12aa", term.getId()); + assertEquals(Long.valueOf("1438354802"), term.getStartAt()); + assertEquals(Long.valueOf("1439650803"), term.getEndAt()); assertEquals((Integer)987, term.getChargeCount()); + assertEquals((Integer)58, term.getRefundCount()); + assertEquals((Integer)5, term.getDisputeCount()); } @Test @@ -54,19 +58,19 @@ public void testRetrieve() throws PayjpException { stubNetwork(Term.class, "{\"id\":\"term1\"}"); Term term = Term.retrieve("term1"); verifyGet(Term.class, "https://api.pay.jp/v1/terms/term1"); - String id = term.getId(); - assertEquals(id, "term1"); + assertEquals(term.getId(), "term1"); } @Test public void testList() throws PayjpException { Map listParams = new HashMap(); listParams.put("limit", 1); - stubNetwork(TermCollection.class, "{\"count\":1,\"data\":[{\"id\":\"term1\"}]}"); + stubNetwork(TermCollection.class, "{\"count\":1,\"data\":[{\"id\":\"term1\"},{\"id\":\"term2\"}]}"); List terms = Term.all(listParams).getData(); - Term term = terms.get(0); - String id = term.getId(); - assertEquals(id, "term1"); + verifyGet(TermCollection.class, "https://api.pay.jp/v1/terms", listParams); + assertEquals(terms.size(), 2); + assertEquals(terms.get(0).getId(), "term1"); + assertEquals(terms.get(1).getId(), "term2"); } } diff --git a/src/test/resources/jp/pay/model/term.json b/src/test/resources/jp/pay/model/term.json index 20dbf1b..9bb76df 100755 --- a/src/test/resources/jp/pay/model/term.json +++ b/src/test/resources/jp/pay/model/term.json @@ -4,8 +4,8 @@ "livemode": false, "object": "term", "charge_count": 987, - "refund_count": 57, - "dispute_count": 4, - "end_at": 1439650800, - "start_at": 1438354801 + "refund_count": 58, + "dispute_count": 5, + "end_at": 1439650803, + "start_at": 1438354802 } \ No newline at end of file From a208830b5fc13e1e8ad65cdc4801f473c6024a29 Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Thu, 28 Mar 2024 17:59:47 +0900 Subject: [PATCH 11/18] add assertion for Balance object each property, refactor --- src/test/java/jp/pay/model/BalanceTest.java | 30 ++++++++++++++------- src/test/java/jp/pay/model/TermTest.java | 5 ++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/test/java/jp/pay/model/BalanceTest.java b/src/test/java/jp/pay/model/BalanceTest.java index 9690e97..c034108 100644 --- a/src/test/java/jp/pay/model/BalanceTest.java +++ b/src/test/java/jp/pay/model/BalanceTest.java @@ -43,9 +43,23 @@ public class BalanceTest extends BasePayjpTest { public void testDeserialize() throws PayjpException, IOException { String json = resource("balance.json"); Balance balance = APIResource.GSON.fromJson(json, Balance.class); + assertEquals("ba_b92b879e60f62b532d6756ae56af", balance.getId()); assertEquals(Long.valueOf("1438354824"), balance.getCreated()); + assertEquals(Boolean.FALSE, balance.getLivemode()); assertEquals(BigInteger.valueOf(Long.valueOf("12300000000")), balance.getNet()); + assertEquals("collecting", balance.getType()); + assertEquals(Boolean.FALSE, balance.getClosed()); + assertEquals(null, balance.getDueDate()); + + BankInfo bankInfo = balance.getBankInfo(); + assertEquals("0000", bankInfo.getBankCode()); + assertEquals("123", bankInfo.getBankBranchCode()); + assertEquals("普通", bankInfo.getBankAccountType()); + assertEquals("1234567", bankInfo.getBankAccountNumber()); + assertEquals("ペイ タロウ", bankInfo.getBankAccountHolderName()); + assertEquals("pending", bankInfo.getBankAccountStatus()); + StatementCollection statements = balance.getStatements(); assertEquals("st_178fd25dc7ab7b75906f1c3c4b0e6", statements.getData().get(0).getId()); assertEquals("st_b4a569b0122a7d08b358f198cf263", statements.getData().get(1).getId()); @@ -53,24 +67,22 @@ public void testDeserialize() throws PayjpException, IOException { @Test public void testRetrieve() throws PayjpException { - Map listParams = new HashMap(); - listParams.put("limit", 1); stubNetwork(Balance.class, "{\"id\":\"balance1\"}"); Balance balance = Balance.retrieve("balance1"); verifyGet(Balance.class, "https://api.pay.jp/v1/balances/balance1"); - String id = balance.getId(); - assertEquals(id, "balance1"); + assertEquals(balance.getId(), "balance1"); } @Test public void testList() throws PayjpException { Map listParams = new HashMap(); - listParams.put("limit", 1); - stubNetwork(BalanceCollection.class, "{\"count\":1,\"data\":[{\"id\":\"balance1\"}]}"); + listParams.put("limit", 2); + stubNetwork(BalanceCollection.class, "{\"count\":1,\"data\":[{\"id\":\"balance1\"},{\"id\":\"balance2\"}]}"); List balances = Balance.all(listParams).getData(); - Balance balance = balances.get(0); - String id = balance.getId(); - assertEquals(id, "balance1"); + verifyGet(BalanceCollection.class, "https://api.pay.jp/v1/balances", listParams); + assertEquals(balances.size(), 2); + assertEquals(balances.get(0).getId(), "balance1"); + assertEquals(balances.get(1).getId(), "balance2"); } } diff --git a/src/test/java/jp/pay/model/TermTest.java b/src/test/java/jp/pay/model/TermTest.java index 8a2d3ce..c4ce21a 100644 --- a/src/test/java/jp/pay/model/TermTest.java +++ b/src/test/java/jp/pay/model/TermTest.java @@ -43,6 +43,7 @@ public void testDeserialize() throws PayjpException, IOException { String json = resource("term.json"); Term term = APIResource.GSON.fromJson(json, Term.class); assertEquals(Long.valueOf("1438354812"), term.getCreated()); + assertEquals(Boolean.FALSE, term.getLivemode()); assertEquals("tm_b92b879e60f62b532d6756ae12aa", term.getId()); assertEquals(Long.valueOf("1438354802"), term.getStartAt()); assertEquals(Long.valueOf("1439650803"), term.getEndAt()); @@ -53,8 +54,6 @@ public void testDeserialize() throws PayjpException, IOException { @Test public void testRetrieve() throws PayjpException { - Map listParams = new HashMap(); - listParams.put("limit", 1); stubNetwork(Term.class, "{\"id\":\"term1\"}"); Term term = Term.retrieve("term1"); verifyGet(Term.class, "https://api.pay.jp/v1/terms/term1"); @@ -64,7 +63,7 @@ public void testRetrieve() throws PayjpException { @Test public void testList() throws PayjpException { Map listParams = new HashMap(); - listParams.put("limit", 1); + listParams.put("limit", 2); stubNetwork(TermCollection.class, "{\"count\":1,\"data\":[{\"id\":\"term1\"},{\"id\":\"term2\"}]}"); List terms = Term.all(listParams).getData(); verifyGet(TermCollection.class, "https://api.pay.jp/v1/terms", listParams); From cdb36d140542dd48a66b383df73209609e7764d3 Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Thu, 28 Mar 2024 18:01:29 +0900 Subject: [PATCH 12/18] count is not 1 --- src/test/java/jp/pay/model/BalanceTest.java | 2 +- src/test/java/jp/pay/model/TermTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/jp/pay/model/BalanceTest.java b/src/test/java/jp/pay/model/BalanceTest.java index c034108..e87ea21 100644 --- a/src/test/java/jp/pay/model/BalanceTest.java +++ b/src/test/java/jp/pay/model/BalanceTest.java @@ -77,7 +77,7 @@ public void testRetrieve() throws PayjpException { public void testList() throws PayjpException { Map listParams = new HashMap(); listParams.put("limit", 2); - stubNetwork(BalanceCollection.class, "{\"count\":1,\"data\":[{\"id\":\"balance1\"},{\"id\":\"balance2\"}]}"); + stubNetwork(BalanceCollection.class, "{\"count\":2,\"data\":[{\"id\":\"balance1\"},{\"id\":\"balance2\"}]}"); List balances = Balance.all(listParams).getData(); verifyGet(BalanceCollection.class, "https://api.pay.jp/v1/balances", listParams); assertEquals(balances.size(), 2); diff --git a/src/test/java/jp/pay/model/TermTest.java b/src/test/java/jp/pay/model/TermTest.java index c4ce21a..abfb228 100644 --- a/src/test/java/jp/pay/model/TermTest.java +++ b/src/test/java/jp/pay/model/TermTest.java @@ -64,7 +64,7 @@ public void testRetrieve() throws PayjpException { public void testList() throws PayjpException { Map listParams = new HashMap(); listParams.put("limit", 2); - stubNetwork(TermCollection.class, "{\"count\":1,\"data\":[{\"id\":\"term1\"},{\"id\":\"term2\"}]}"); + stubNetwork(TermCollection.class, "{\"count\":2,\"data\":[{\"id\":\"term1\"},{\"id\":\"term2\"}]}"); List terms = Term.all(listParams).getData(); verifyGet(TermCollection.class, "https://api.pay.jp/v1/terms", listParams); assertEquals(terms.size(), 2); From f515fae53466909cd248bc94ab1afc2670dea361 Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Wed, 10 Apr 2024 11:53:04 +0900 Subject: [PATCH 13/18] follow latest specification --- src/main/java/jp/pay/model/Balance.java | 16 +- src/main/java/jp/pay/model/Statement.java | 8 + src/main/java/jp/pay/model/Term.java | 5 - src/test/java/jp/pay/model/BalanceTest.java | 9 +- src/test/java/jp/pay/model/TermTest.java | 1 - src/test/resources/jp/pay/model/balance.json | 140 +++++++++--------- .../resources/jp/pay/model/balance_event.json | 139 +++++++++-------- src/test/resources/jp/pay/model/term.json | 1 - 8 files changed, 159 insertions(+), 160 deletions(-) diff --git a/src/main/java/jp/pay/model/Balance.java b/src/main/java/jp/pay/model/Balance.java index 9616ba9..d30fa44 100644 --- a/src/main/java/jp/pay/model/Balance.java +++ b/src/main/java/jp/pay/model/Balance.java @@ -6,6 +6,7 @@ import java.math.BigInteger; import java.util.Map; +import java.util.List; public class Balance extends APIResource { @@ -13,8 +14,9 @@ public class Balance extends APIResource { String id; Boolean livemode; BigInteger net; - StatementCollection statements; - String type; + String tenantId; + List statements; + String state; Boolean closed; String dueDate; BankInfo bankInfo; @@ -34,13 +36,17 @@ public Boolean getLivemode() { public BigInteger getNet() { return net; } + + public String getTenantId() { + return tenantId; + } - public StatementCollection getStatements() { + public List getStatements() { return statements; } - public String getType() { - return type; + public String getState() { + return state; } public Boolean getClosed() { diff --git a/src/main/java/jp/pay/model/Statement.java b/src/main/java/jp/pay/model/Statement.java index 9918870..96c7b47 100644 --- a/src/main/java/jp/pay/model/Statement.java +++ b/src/main/java/jp/pay/model/Statement.java @@ -17,6 +17,8 @@ public class Statement extends APIResource { Long updated; Term term; String balanceId; + String tenantId; + String type; public class StatementItem { Integer amount; @@ -69,7 +71,13 @@ public String getBalanceId() { return balanceId; } + public String getTenantId() { + return tenantId; + } + public String getType() { + return type; + } public static Statement retrieve(String id) throws AuthenticationException, InvalidRequestException, APIConnectionException, diff --git a/src/main/java/jp/pay/model/Term.java b/src/main/java/jp/pay/model/Term.java index be3659a..988fe2b 100644 --- a/src/main/java/jp/pay/model/Term.java +++ b/src/main/java/jp/pay/model/Term.java @@ -8,7 +8,6 @@ public class Term extends APIResource { - Long created; String id; Boolean livemode; Long startAt; @@ -17,10 +16,6 @@ public class Term extends APIResource { Integer refundCount; Integer disputeCount; - public Long getCreated() { - return created; - } - public String getId() { return id; } diff --git a/src/test/java/jp/pay/model/BalanceTest.java b/src/test/java/jp/pay/model/BalanceTest.java index e87ea21..383e335 100644 --- a/src/test/java/jp/pay/model/BalanceTest.java +++ b/src/test/java/jp/pay/model/BalanceTest.java @@ -48,7 +48,8 @@ public void testDeserialize() throws PayjpException, IOException { assertEquals(Long.valueOf("1438354824"), balance.getCreated()); assertEquals(Boolean.FALSE, balance.getLivemode()); assertEquals(BigInteger.valueOf(Long.valueOf("12300000000")), balance.getNet()); - assertEquals("collecting", balance.getType()); + assertEquals("ten_4f2a6b6b8f4b0f1e8b0fa8bca8b0", balance.getTenantId()); + assertEquals("collecting", balance.getState()); assertEquals(Boolean.FALSE, balance.getClosed()); assertEquals(null, balance.getDueDate()); @@ -60,9 +61,9 @@ public void testDeserialize() throws PayjpException, IOException { assertEquals("ペイ タロウ", bankInfo.getBankAccountHolderName()); assertEquals("pending", bankInfo.getBankAccountStatus()); - StatementCollection statements = balance.getStatements(); - assertEquals("st_178fd25dc7ab7b75906f1c3c4b0e6", statements.getData().get(0).getId()); - assertEquals("st_b4a569b0122a7d08b358f198cf263", statements.getData().get(1).getId()); + List statements = balance.getStatements(); + assertEquals("st_178fd25dc7ab7b75906f1c3c4b0e6", statements.get(0).getId()); + assertEquals("st_b4a569b0122a7d08b358f198cf263", statements.get(1).getId()); } @Test diff --git a/src/test/java/jp/pay/model/TermTest.java b/src/test/java/jp/pay/model/TermTest.java index abfb228..77c032c 100644 --- a/src/test/java/jp/pay/model/TermTest.java +++ b/src/test/java/jp/pay/model/TermTest.java @@ -42,7 +42,6 @@ public class TermTest extends BasePayjpTest { public void testDeserialize() throws PayjpException, IOException { String json = resource("term.json"); Term term = APIResource.GSON.fromJson(json, Term.class); - assertEquals(Long.valueOf("1438354812"), term.getCreated()); assertEquals(Boolean.FALSE, term.getLivemode()); assertEquals("tm_b92b879e60f62b532d6756ae12aa", term.getId()); assertEquals(Long.valueOf("1438354802"), term.getStartAt()); diff --git a/src/test/resources/jp/pay/model/balance.json b/src/test/resources/jp/pay/model/balance.json index 470b6f0..f73df80 100755 --- a/src/test/resources/jp/pay/model/balance.json +++ b/src/test/resources/jp/pay/model/balance.json @@ -4,77 +4,71 @@ "livemode": false, "net": 12300000000, "object": "balance", - "type": "collecting", - "statements": { - "count": 2, - "data": [ - { - "created": 1695892351, - "id": "st_178fd25dc7ab7b75906f1c3c4b0e6", - "items": [ - { - "amount": 25, - "name": "チャージバックによる手数料返還", - "subject": "chargeback_fee_offset", - "tax_rate": "0.00" - }, - { - "amount": -775, - "name": "チャージバック", - "subject": "chargeback", - "tax_rate": "0.00" - }, - { - "amount": 36, - "name": "返金による手数料返還", - "subject": "refund_fee_offset", - "tax_rate": "0.00" - }, - { - "amount": -1800, - "name": "返金", - "subject": "gross_refund", - "tax_rate": "0.00" - }, - { - "amount": -75, - "name": "決済手数料", - "subject": "fee", - "tax_rate": "0.00" - }, - { - "amount": 3125, - "name": "売上", - "subject": "gross_sales", - "tax_rate": "0.00" - } - ], - "object": "statement", - "livemode": true, - "title": null, - "updated": 1695892351 - }, - { - "created": 1695892350, - "id": "st_b4a569b0122a7d08b358f198cf263", - "items": [ - { - "amount": -10000, - "name": "プロプラン利用料", - "subject": "proplan", - "tax_rate": "10.00" - } - ], - "object": "statement", - "livemode": true, - "title": "プロプラン月額料金", - "updated": 1695892350 - } - ], - "has_more": false, - "object": "list", - "url": "/v1/statements" - }, + "state": "collecting", + "statements": [ + { + "created": 1695892351, + "id": "st_178fd25dc7ab7b75906f1c3c4b0e6", + "items": [ + { + "amount": 25, + "name": "チャージバックによる手数料返還", + "subject": "chargeback_fee_offset", + "tax_rate": "0.00" + }, + { + "amount": -775, + "name": "チャージバック", + "subject": "chargeback", + "tax_rate": "0.00" + }, + { + "amount": 36, + "name": "返金による手数料返還", + "subject": "refund_fee_offset", + "tax_rate": "0.00" + }, + { + "amount": -1800, + "name": "返金", + "subject": "gross_refund", + "tax_rate": "0.00" + }, + { + "amount": -75, + "name": "決済手数料", + "subject": "fee", + "tax_rate": "0.00" + }, + { + "amount": 3125, + "name": "売上", + "subject": "gross_sales", + "tax_rate": "0.00" + } + ], + "object": "statement", + "livemode": true, + "title": null, + "updated": 1695892351 + }, + { + "created": 1695892350, + "id": "st_b4a569b0122a7d08b358f198cf263", + "items": [ + { + "amount": -10000, + "name": "プロプラン利用料", + "subject": "proplan", + "tax_rate": "10.00" + } + ], + "object": "statement", + "livemode": true, + "title": "プロプラン月額料金", + "updated": 1695892350 + } + ], "closed": false, "due_date": null, "bank_info": { @@ -84,5 +78,7 @@ "bank_account_number": "1234567", "bank_account_holder_name": "ペイ タロウ", "bank_account_status": "pending" - } + }, + + "tenant_id": "ten_4f2a6b6b8f4b0f1e8b0fa8bca8b0" } \ No newline at end of file diff --git a/src/test/resources/jp/pay/model/balance_event.json b/src/test/resources/jp/pay/model/balance_event.json index 31dbaaa..c1246cc 100755 --- a/src/test/resources/jp/pay/model/balance_event.json +++ b/src/test/resources/jp/pay/model/balance_event.json @@ -6,77 +6,71 @@ "livemode": false, "net": 12300000000, "object": "balance", - "type": "collecting", - "statements": { - "count": 2, - "data": [ - { - "created": 1695892351, - "id": "st_178fd25dc7ab7b75906f1c3c4b0e5", - "items": [ - { - "amount": 25, - "name": "チャージバックによる手数料返還", - "subject": "chargeback_fee_offset", - "tax_rate": "0.00" - }, - { - "amount": -775, - "name": "チャージバック", - "subject": "chargeback", - "tax_rate": "0.00" - }, - { - "amount": 36, - "name": "返金による手数料返還", - "subject": "refund_fee_offset", - "tax_rate": "0.00" - }, - { - "amount": -1800, - "name": "返金", - "subject": "gross_refund", - "tax_rate": "0.00" - }, - { - "amount": -75, - "name": "決済手数料", - "subject": "fee", - "tax_rate": "0.00" - }, - { - "amount": 3125, - "name": "売上", - "subject": "gross_sales", - "tax_rate": "0.00" - } - ], - "object": "statement", - "livemode": true, - "title": null, - "updated": 1695892351 - }, - { - "created": 1695892350, - "id": "st_b4a569b0122a7d08b358f198cf263", - "items": [ - { - "amount": -10000, - "name": "プロプラン利用料", - "subject": "proplan", - "tax_rate": "10.00" - } - ], - "object": "statement", - "livemode": true, - "title": "プロプラン月額料金", - "updated": 1695892350 - } - ], - "has_more": false, - "object": "list", - "url": "/v1/statements" - }, + "state": "collecting", + "statements": [ + { + "created": 1695892351, + "id": "st_178fd25dc7ab7b75906f1c3c4b0e5", + "items": [ + { + "amount": 25, + "name": "チャージバックによる手数料返還", + "subject": "chargeback_fee_offset", + "tax_rate": "0.00" + }, + { + "amount": -775, + "name": "チャージバック", + "subject": "chargeback", + "tax_rate": "0.00" + }, + { + "amount": 36, + "name": "返金による手数料返還", + "subject": "refund_fee_offset", + "tax_rate": "0.00" + }, + { + "amount": -1800, + "name": "返金", + "subject": "gross_refund", + "tax_rate": "0.00" + }, + { + "amount": -75, + "name": "決済手数料", + "subject": "fee", + "tax_rate": "0.00" + }, + { + "amount": 3125, + "name": "売上", + "subject": "gross_sales", + "tax_rate": "0.00" + } + ], + "object": "statement", + "livemode": true, + "title": null, + "updated": 1695892351 + }, + { + "created": 1695892350, + "id": "st_b4a569b0122a7d08b358f198cf263", + "items": [ + { + "amount": -10000, + "name": "プロプラン利用料", + "subject": "proplan", + "tax_rate": "10.00" + } + ], + "object": "statement", + "livemode": true, + "title": "プロプラン月額料金", + "updated": 1695892350 + } + ], "closed": false, "due_date": null, "bank_info": { @@ -86,7 +80,8 @@ "bank_account_number": "1234567", "bank_account_holder_name": "ペイ タロウ", "bank_account_status": "pending" - } + }, + "tenant_id": "ten_4f2a6b6b8f4b0f1e8b0fa8bca8b3" }, "id": "evnt_2f7436fe0017098bc8d22221d1e", "livemode": false, diff --git a/src/test/resources/jp/pay/model/term.json b/src/test/resources/jp/pay/model/term.json index 9bb76df..22a269f 100755 --- a/src/test/resources/jp/pay/model/term.json +++ b/src/test/resources/jp/pay/model/term.json @@ -1,5 +1,4 @@ { - "created": 1438354812, "id": "tm_b92b879e60f62b532d6756ae12aa", "livemode": false, "object": "term", From b705a942513ad50a21893b9c6ffcfc3002fa9dda Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Wed, 10 Apr 2024 16:33:02 +0900 Subject: [PATCH 14/18] add Statement.net property --- src/main/java/jp/pay/model/Statement.java | 6 ++++++ src/test/java/jp/pay/model/DeserializerTest.java | 2 ++ src/test/resources/jp/pay/model/statement_event.json | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/jp/pay/model/Statement.java b/src/main/java/jp/pay/model/Statement.java index 96c7b47..fcac84f 100644 --- a/src/main/java/jp/pay/model/Statement.java +++ b/src/main/java/jp/pay/model/Statement.java @@ -4,6 +4,7 @@ import jp.pay.net.APIResource; import jp.pay.net.RequestOptions; +import java.math.BigInteger; import java.util.List; import java.util.Map; @@ -19,6 +20,7 @@ public class Statement extends APIResource { String balanceId; String tenantId; String type; + BigInteger net; public class StatementItem { Integer amount; @@ -79,6 +81,10 @@ public String getType() { return type; } + public BigInteger getNet() { + return net; + } + public static Statement retrieve(String id) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException { diff --git a/src/test/java/jp/pay/model/DeserializerTest.java b/src/test/java/jp/pay/model/DeserializerTest.java index 97402ab..00c8f70 100644 --- a/src/test/java/jp/pay/model/DeserializerTest.java +++ b/src/test/java/jp/pay/model/DeserializerTest.java @@ -28,6 +28,7 @@ import org.junit.Test; import java.io.IOException; +import java.math.BigInteger; import jp.pay.BasePayjpTest; import jp.pay.net.APIResource; @@ -69,6 +70,7 @@ public void deserializeStatementEvent() throws IOException { Statement obj = (Statement)e.getData(); assertEquals("st_178fd25dc7ab7b75906f5d4c4b0e6", obj.getId()); assertEquals("ba_b92b879e60f62b532d6756ae90af", obj.getBalanceId()); + assertEquals(BigInteger.valueOf(Long.valueOf("12340000000")), obj.getNet()); Term term = obj.getTerm(); assertEquals("tm_b92b879e60f62b532d6756ae12dd", term.getId()); diff --git a/src/test/resources/jp/pay/model/statement_event.json b/src/test/resources/jp/pay/model/statement_event.json index ab0b65c..635184b 100755 --- a/src/test/resources/jp/pay/model/statement_event.json +++ b/src/test/resources/jp/pay/model/statement_event.json @@ -56,7 +56,8 @@ "end_at": 1439650800, "start_at": 1438354801 }, - "balance_id": "ba_b92b879e60f62b532d6756ae90af" + "balance_id": "ba_b92b879e60f62b532d6756ae90af", + "net": 12340000000 }, "id": "evnt_2f7436fe0017098bc8d22221d1e", "livemode": false, From 1cfe8d42fd50d50bada00e912c1b5cda6df46f52 Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Wed, 10 Apr 2024 16:40:08 +0900 Subject: [PATCH 15/18] increment version, remove sk_test --- README.md | 6 +++--- VERSION | 2 +- src/main/java/jp/pay/Payjp.java | 2 +- src/test/java/jp/pay/PayjpScenarioTest.java | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 73822b6..6edbd5f 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Add this dependency to your project's POM: jp.pay payjp-java - 0.6.2 + 0.6.3 ``` @@ -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.6.2" +compile "jp.pay:payjp-java:0.6.3" ``` ### Others @@ -62,7 +62,7 @@ import jp.pay.net.RequestOptions; public class PayjpExample { public static void main(String[] args) { - Payjp.apiKey = "sk_test_c62fade9d045b54cd76d7036"; + Payjp.apiKey = "your_secret_key"; Map chargeMap = new HashMap(); chargeMap.put("amount", 3500); chargeMap.put("currency", "jpy"); diff --git a/VERSION b/VERSION index b616048..844f6a9 100755 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.6.2 +0.6.3 diff --git a/src/main/java/jp/pay/Payjp.java b/src/main/java/jp/pay/Payjp.java index f1a92a6..b38f502 100644 --- a/src/main/java/jp/pay/Payjp.java +++ b/src/main/java/jp/pay/Payjp.java @@ -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.6.2"; + public static final String VERSION = "0.6.3"; public static volatile String apiKey; public static volatile String apiVersion; public static volatile Integer maxRetry = 0; diff --git a/src/test/java/jp/pay/PayjpScenarioTest.java b/src/test/java/jp/pay/PayjpScenarioTest.java index 0bb379d..9b67ac9 100644 --- a/src/test/java/jp/pay/PayjpScenarioTest.java +++ b/src/test/java/jp/pay/PayjpScenarioTest.java @@ -37,7 +37,7 @@ public class PayjpScenarioTest extends BasePayjpTest { @BeforeClass public static void setUp() { - Payjp.apiKey = "sk_test_c62fade9d045b54cd76d7036"; // public api key for test + Payjp.apiKey = "your_secret_key"; // public api key for test } @Ignore From 7cd4bbce211a735116ade3ec2597548381f30dd3 Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Wed, 10 Apr 2024 16:42:36 +0900 Subject: [PATCH 16/18] forget increment --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 40aec18..5133d77 100755 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ jp.pay payjp-java jar - 0.6.2 + 0.6.3 pay-java https://github.com/payjp/payjp-java From 5518180bc88c91bf7a997795e9495bc27bd1e70b Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Wed, 10 Apr 2024 16:58:52 +0900 Subject: [PATCH 17/18] 0.7.0 --- README.md | 4 ++-- VERSION | 2 +- pom.xml | 2 +- src/main/java/jp/pay/Payjp.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6edbd5f..6902945 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Add this dependency to your project's POM: jp.pay payjp-java - 0.6.3 + 0.7.0 ``` @@ -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.6.3" +compile "jp.pay:payjp-java:0.7.0" ``` ### Others diff --git a/VERSION b/VERSION index 844f6a9..faef31a 100755 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.6.3 +0.7.0 diff --git a/pom.xml b/pom.xml index 5133d77..f62d524 100755 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ jp.pay payjp-java jar - 0.6.3 + 0.7.0 pay-java https://github.com/payjp/payjp-java diff --git a/src/main/java/jp/pay/Payjp.java b/src/main/java/jp/pay/Payjp.java index b38f502..7b21439 100644 --- a/src/main/java/jp/pay/Payjp.java +++ b/src/main/java/jp/pay/Payjp.java @@ -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.6.3"; + public static final String VERSION = "0.7.0"; public static volatile String apiKey; public static volatile String apiVersion; public static volatile Integer maxRetry = 0; From 07c9d92bae6ca356642c1a82ca53b4da7b6a4855 Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Wed, 10 Apr 2024 18:33:25 +0900 Subject: [PATCH 18/18] add title, updated getter --- src/main/java/jp/pay/model/Statement.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/jp/pay/model/Statement.java b/src/main/java/jp/pay/model/Statement.java index fcac84f..a6354ef 100644 --- a/src/main/java/jp/pay/model/Statement.java +++ b/src/main/java/jp/pay/model/Statement.java @@ -53,6 +53,14 @@ public Long getCreated() { return created; } + public String getTitle() { + return title; + } + + public Long getUpdated() { + return updated; + } + public String getId() { return id; }