Java 1.6 and later.
Add this dependency to your project's POM:
<dependency>
<groupId>jp.pay</groupId>
<artifactId>payjp-java</artifactId>
<version>0.8.0</version>
</dependency>
Add this dependency to your project's build file:
compile "jp.pay:payjp-java:0.8.0"
You'll need to manually install the following JARs:
- The Payjp JAR from https://github.com/payjp/payjp-java/releases/latest
- Google Gson from http://google-gson.googlecode.com/files/google-gson-2.2.4-release.zip.
- javax.mail from http://central.maven.org/maven2/javax/mail/mail/1.4.7/mail-1.4.7.jar
If you're planning on using ProGuard, make sure that you exclude the Payjp bindings. You can do this by adding the following to your proguard.cfg
file:
-keep class jp.pay.** { *; }
In advance, you need to get token by Checkout.
PayjpExample.java
import java.util.HashMap;
import java.util.Map;
import jp.pay.Payjp;
import jp.pay.model.Charge;
import jp.pay.net.RequestOptions;
public class PayjpExample {
public static void main(String[] args) {
Payjp.apiKey = "your_secret_key";
Map<String, Object> chargeMap = new HashMap<String, Object>();
chargeMap.put("amount", 3500);
chargeMap.put("currency", "jpy");
chargeMap.put("card", "<your_token_id>");
try {
Charge charge = Charge.create(chargeMap);
System.out.println(charge);
} catch (Exception e) {
e.printStackTrace();
}
}
}
- See Rate Limit Guideline
- When you exceeded rate-limit, you can retry request by setting
Payjp.maxRetry
likePayjp.maxRetry = 3;
. - The retry interval base value is
Payjp.retryInitialDelay
Adjust the value likePayjp.retryInitialDelay = 4;
The smaller is shorter. - The retry interval calcurating is based on "Exponential backoff with equal jitter" algorithm.
See https://aws.amazon.com/jp/blogs/architecture/exponential-backoff-and-jitter/
You must have Maven installed. To run the tests, simply run mvn test
. You can run particular tests by passing -D test=Class#method
-- for example, -D test=PayjpTest#testChargeCreate
.