Skip to content
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 .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

直近のactionsで下記のメッセージが出てた
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/

with:
java-version: ${{ matrix.java-version }}
distribution: 'adopt'
Expand Down
6 changes: 3 additions & 3 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.6.2</version>
<version>0.7.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.6.2"
compile "jp.pay:payjp-java:0.7.0"
```

### Others
Expand Down Expand Up @@ -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<String, Object> chargeMap = new HashMap<String, Object>();
chargeMap.put("amount", 3500);
chargeMap.put("currency", "jpy");
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.2
0.7.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.6.2</version>
<version>0.7.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.6.2";
public static final String VERSION = "0.7.0";
public static volatile String apiKey;
public static volatile String apiVersion;
public static volatile Integer maxRetry = 0;
Expand Down
88 changes: 88 additions & 0 deletions src/main/java/jp/pay/model/Balance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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.Map;
import java.util.List;


public class Balance extends APIResource {
Long created;
String id;
Boolean livemode;
BigInteger net;
String tenantId;
List<Statement> statements;
String state;
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 String getTenantId() {
return tenantId;
}

public List<Statement> getStatements() {
return statements;
}

public String getState() {
return state;
}

public Boolean getClosed() {
return closed;
}

public String getDueDate() {
return dueDate;
}
Comment on lines +56 to +58
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ここも null ありえそうですが、String のメソッド使えないくらいなので影響はそれほどなんですかね。
これは質問の割合のほうが大きいです。


public BankInfo getBankInfo() {
return bankInfo;
}
Comment on lines +60 to +62
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

bank_info は null があり得るので、ぬるぽ出ませんかね?

balance.getBankInfo().getBankCode()

他にも該当するコードはありそう。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

GSONでのシリアライズ時点では出ないです。一応ローカルのbalance.jsonに "bank_info": null 書いて確かめましたがbalance.getBankInfo()でもnullが返ってくるだけ。
Javaのプリミティブ型以外は全部nullがあり得るのでその先のnull考慮は使用者の責任かと。
以降のnullの話も同じくです


public static Balance retrieve(String id) throws AuthenticationException,
InvalidRequestException, APIConnectionException,
CardException, APIException {
return retrieve(id, (RequestOptions) null);
}

public static BalanceCollection all(Map<String, Object> 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<String, Object> params,
RequestOptions options) throws AuthenticationException,
InvalidRequestException, APIConnectionException,
CardException, APIException {
return request(RequestMethod.GET, classURL(Balance.class), params, BalanceCollection.class, options);
}
}
4 changes: 4 additions & 0 deletions src/main/java/jp/pay/model/BalanceCollection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package jp.pay.model;

public class BalanceCollection extends PayjpCollection<Balance> {
}
35 changes: 35 additions & 0 deletions src/main/java/jp/pay/model/BankInfo.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
5 changes: 5 additions & 0 deletions src/main/java/jp/pay/model/Charge.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class Charge extends APIResource implements MetadataStore<Charge> {
Map<String, String> metadata = new HashMap<String, String>();
String feeRate;
String threeDSecureStatus;
String termId;

public String getId() {
return id;
Expand Down Expand Up @@ -196,6 +197,10 @@ public Map<String, String> 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().
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/jp/pay/model/PayjpObjectDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class PayjpObjectDeserializer implements JsonDeserializer<PayjpObject> {
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);
Comment on lines +55 to +57
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

tab と space 気になったけどどっちに揃えるのがいいんでしょう。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

4スペースが多そう

現状いろんなとこで入り混じってるので揃えるなら別PRにしてlinter入れたい

}

private Object deserializeJsonPrimitive(JsonPrimitive element) {
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/jp/pay/model/Statement.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -15,6 +16,11 @@ public class Statement extends APIResource {
Boolean livemode;
String title;
Long updated;
Term term;
String balanceId;
String tenantId;
String type;
BigInteger net;

public class StatementItem {
Integer amount;
Expand Down Expand Up @@ -47,6 +53,14 @@ public Long getCreated() {
return created;
}

public String getTitle() {
return title;
}

public Long getUpdated() {
return updated;
}

public String getId() {
return id;
}
Expand All @@ -59,6 +73,25 @@ public void setLivemode(Boolean livemode) {
this.livemode = livemode;
}

public Term getTerm() {
return term;
}
Comment on lines +76 to +78
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ここも term に null がありえそうです。


public String getBalanceId() {
return balanceId;
}

public String getTenantId() {
return tenantId;
}

public String getType() {
return type;
}

public BigInteger getNet() {
return net;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

title の getter がなさそう?
他には updated の getter がなさそうですが理由はあるように見えるので聞いておきたいです。


public static Statement retrieve(String id) throws AuthenticationException,
InvalidRequestException, APIConnectionException,
Expand Down
72 changes: 72 additions & 0 deletions src/main/java/jp/pay/model/Term.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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 {
String id;
Boolean livemode;
Long startAt;
Long endAt;
Integer chargeCount;
Integer refundCount;
Integer disputeCount;

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<String, Object> 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<String, Object> params,
RequestOptions options) throws AuthenticationException,
InvalidRequestException, APIConnectionException,
CardException, APIException {
return request(RequestMethod.GET, classURL(Term.class), params, TermCollection.class, options);
}
}
4 changes: 4 additions & 0 deletions src/main/java/jp/pay/model/TermCollection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package jp.pay.model;

public class TermCollection extends PayjpCollection<Term> {
}
20 changes: 20 additions & 0 deletions src/test/java/jp/pay/BasePayjpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package jp.pay;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.mockito.ArgumentMatcher;
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
}
Loading