Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
84d0c6f
Upgrade SDK to support Payload API v2 and address review feedback
NathanYearout Feb 9, 2026
e51860f
Update json bug
NathanYearout Feb 10, 2026
512301e
Fix tests
NathanYearout Feb 13, 2026
0069861
Remove hardcoded attr function methods from Attr class
NathanYearout Feb 13, 2026
1b80080
fixed TransactionDeclined exception, adding missing card_code, fixed …
ianhalpern Feb 16, 2026
44f6d98
update test workflow job name
ianhalpern Feb 16, 2026
11c9c35
API v2
NathanYearout Feb 16, 2026
b1aec23
Add the filter_bys
NathanYearout Feb 16, 2026
3d888ef
Appending S logic
NathanYearout Feb 16, 2026
041aa2b
redundant endpoint
NathanYearout Feb 16, 2026
d390725
New session logic similar to the python SDKs
NathanYearout Feb 16, 2026
99d3335
Restore helper methods in TransactionDeclined exception - From AI review
NathanYearout Feb 16, 2026
bf2777e
Improve exception handling in ARMObject.getList - From AI review
NathanYearout Feb 16, 2026
82225c0
Safer JSON parsing in ARMRequest response - From AI review
NathanYearout Feb 16, 2026
04a6d9e
Remove side-effects from ARMRequest.first() - From AI review
NathanYearout Feb 16, 2026
7eed592
Fix compilation error in ARMObject.getList - From AI review
NathanYearout Feb 16, 2026
72406fe
Updated Session setup
ianhalpern Feb 17, 2026
b97b2c8
Remove em
NathanYearout Feb 17, 2026
2afb7ee
simplified Session.java using generic types and added bulk create sup…
ianhalpern Feb 17, 2026
c99caf3
Added check for bulk create if no args are provided
ianhalpern Feb 17, 2026
889b85d
Update version to 1.2.0
ianhalpern Feb 17, 2026
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
12 changes: 3 additions & 9 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
- name: Set up Maven Central Repository
- uses: actions/checkout@v4
- name: Set up Java and Maven Central Repository
uses: actions/setup-java@v4
with:
java-version: '11'
Expand All @@ -23,9 +18,8 @@ jobs:
gpg-private-key: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
gpg-passphrase: GPG_PASSPHRASE
- name: Publish package
run: mvn --batch-mode deploy
run: mvn --batch-mode deploy -DskipTests
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
API_KEY: ${{ secrets.API_KEY }}
2 changes: 1 addition & 1 deletion .github/workflows/test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- master

jobs:
build:
test:
runs-on: ubuntu-latest
env:
API_KEY: ${{ secrets.API_KEY }}
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

Copyright (c) 2024 Payload (https://payload.com)
Copyright (c) 2026 Payload (https://payload.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ A Java library for integrating [Payload](https://payload.com).
<dependency>
<groupId>com.payload</groupId>
<artifactId>payload</artifactId>
<version>2.0.0</version>
<version>1.2.0</version>
</dependency>
```

Expand All @@ -55,12 +55,14 @@ Session sess = new Session("secret_key_3bW9JMZtPVDOfFNzwRdfE");

### API Version

To specify which version of the Payload API to use, set the `api_version` property. When set, all requests will include the `X-API-Version` header.
To specify which version of the Payload API to use, pass it as the second argument to `Session` or use the `apiVersion` method.

```java
import com.payload.pl;
Session sess = new Session("secret_key_3bW9JMZtPVDOfFNzwRdfE", "2");
```

pl.api_version = "2";
```java
Session sess = new Session("secret_key_3bW9JMZtPVDOfFNzwRdfE").apiVersion("2");
```

### Creating an Object
Expand Down
23 changes: 9 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.payload</groupId>
<artifactId>payload</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<name>payload</name>
<description>Payload Java Library</description>
<url>https://github.com/payload-code/payload-java</url>
Expand Down Expand Up @@ -90,7 +90,7 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<version>3.11.0</version>
<executions>
<execution>
<id>compile-java-7</id>
Expand Down Expand Up @@ -123,24 +123,16 @@
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
Expand All @@ -160,6 +152,7 @@
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>attach-sources</id>
Expand Down Expand Up @@ -223,10 +216,12 @@
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.5.0</version>
<version>0.7.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
<autoPublish>true</autoPublish>
<waitUntil>published</waitUntil>
</configuration>
</plugin>
</plugins>
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/com/payload/Exceptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,9 @@ public ServiceUnavailable(JSONObject details) {
}
}

public static class TransactionDeclined extends PayloadError {
private String transactionId;
private String declineReason;

public TransactionDeclined(String message, String transactionId, String declineReason) {
super(message);
this.transactionId = transactionId;
this.declineReason = declineReason;
}

public String getTransactionId() {
return transactionId;
}

public String getDeclineReason() {
return declineReason;
public static class TransactionDeclined extends BadRequest {
public TransactionDeclined(JSONObject details) {
super(details);
}
}

Expand Down
116 changes: 30 additions & 86 deletions src/main/java/com/payload/Session.java
Original file line number Diff line number Diff line change
@@ -1,121 +1,65 @@
package com.payload;

import java.util.List;
import java.util.Arrays;
import com.payload.pl;
import com.payload.arm.ARMObject;
import com.payload.arm.ARMRequest;

public class Session {

private volatile String api_key;
private volatile String api_url;
private volatile String api_version;

public Session(String api_key) {
this.api_key = api_key;
}

public Session(String api_key, String api_url) {
public Session(String api_key, String api_version) {
this.api_key = api_key;
this.api_version = api_version;
}

public Session apiUrl(String api_url) {
this.api_url = api_url;
return this;
}

public Session apiVersion(String api_version) {
this.api_version = api_version;
return this;
}

public String getApiKey() { return this.api_key != null ? this.api_key : pl.api_key; }
public String getApiUrl() { return this.api_url != null ? this.api_url : pl.api_url; }
public String getApiVersion() { return pl.api_version; }
public String getApiVersion() { return this.api_version != null ? this.api_version : pl.api_version; }

public <T> ARMRequest<T> select(Class<T> cls) throws Exceptions.PayloadError {
return new ARMRequest<T>(cls, this);
}

public pl.AccessToken create(pl.AccessToken obj) throws Exceptions.PayloadError {
return obj.create(this);
}

public pl.ClientToken create(pl.ClientToken obj) throws Exceptions.PayloadError {
return obj.create(this);
}

public pl.Customer create(pl.Customer obj) throws Exceptions.PayloadError {
return obj.create(this);
}

public pl.ProcessingAccount create(pl.ProcessingAccount obj) throws Exceptions.PayloadError {
return obj.create(this);
}

public pl.Org create(pl.Org obj) throws Exceptions.PayloadError {
return obj.create(this);
}

public pl.Transaction create(pl.Transaction obj) throws Exceptions.PayloadError {
return obj.create(this);
}

public pl.Payment create(pl.Payment obj) throws Exceptions.PayloadError {
return obj.create(this);
}

public pl.Refund create(pl.Refund obj) throws Exceptions.PayloadError {
return obj.create(this);
}

public pl.Credit create(pl.Credit obj) throws Exceptions.PayloadError {
return obj.create(this);
}

public pl.Deposit create(pl.Deposit obj) throws Exceptions.PayloadError {
return obj.create(this);
}

public pl.Ledger create(pl.Ledger obj) throws Exceptions.PayloadError {
return obj.create(this);
}

public pl.PaymentMethod create(pl.PaymentMethod obj) throws Exceptions.PayloadError {
return obj.create(this);
}

public pl.Card create(pl.Card obj) throws Exceptions.PayloadError {
return (pl.Card)obj.create(this);
}

public pl.BankAccount create(pl.BankAccount obj) throws Exceptions.PayloadError {
return (pl.BankAccount)obj.create(this);
}

public pl.BillingSchedule create(pl.BillingSchedule obj) throws Exceptions.PayloadError {
return obj.create(this);
}

public pl.BillingCharge create(pl.BillingCharge obj) throws Exceptions.PayloadError {
return obj.create(this);
}

public pl.Invoice create(pl.Invoice obj) throws Exceptions.PayloadError {
return obj.create(this);
}

public pl.LineItem create(pl.LineItem obj) throws Exceptions.PayloadError {
return obj.create(this);
}

public pl.ChargeItem create(pl.ChargeItem obj) throws Exceptions.PayloadError {
return (pl.ChargeItem)obj.create(this);
}

public pl.PaymentItem create(pl.PaymentItem obj) throws Exceptions.PayloadError {
return (pl.PaymentItem)obj.create(this);
public <T> ARMRequest<T> select(Class<T> cls, String... args) {
return new ARMRequest<T>(cls).select(args);
}

public pl.Webhook create(pl.Webhook obj) throws Exceptions.PayloadError {
return obj.create(this);
@SuppressWarnings("unchecked")
public <T extends ARMObject> T create(T obj) throws Exceptions.PayloadError {
return (T) obj.create(this);
}

public pl.PaymentLink create(pl.PaymentLink obj) throws Exceptions.PayloadError {
return obj.create(this);
@SafeVarargs
@SuppressWarnings("unchecked")
public final <T extends ARMObject> List<T> create(T... args) throws Exceptions.PayloadError {
if (args.length == 0)
throw new IllegalArgumentException("create requires at least one argument");
Class<T> cls = (Class<T>) args[0].getClass();
return new ARMRequest<T>(cls, this).create(Arrays.asList(args));
}

public pl.PaymentActivation create(pl.PaymentActivation obj) throws Exceptions.PayloadError {
return obj.create(this);
public void delete(ARMObject obj) throws Exceptions.PayloadError {
obj.session = this;
obj.delete();
}

}
62 changes: 61 additions & 1 deletion src/main/java/com/payload/arm/ARMObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public class ARMObject<T> {
public String getObject(){ return ""; }
public String[] getPoly(){ return null; }
public Map<String,String> fieldmap(){ return null; }
public String getEndpoint() { return "/"+getObject()+"s"; }
public String getEndpoint() {
String obj = getObject();
return "/" + obj + (obj.endsWith("s") ? "" : "s");
}
public JSONObject obj;
public Session session;

Expand Down Expand Up @@ -57,10 +60,67 @@ public float getFloat(String key) {
return (float)mappedObj(key).getDouble(key);
}

public boolean getBool(String key) {
return mappedObj(key).getBoolean(key);
}

public boolean getBool(String key, boolean defaultVal) {
try {
return mappedObj(key).getBoolean(key);
} catch (JSONException exc) {
return defaultVal;
}
}

public JSONObject getJObj(String key) {
return mappedObj(key).getJSONObject(key);
}

public JSONArray getJArr(String key) {
return mappedObj(key).getJSONArray(key);
}

public ARMObject getObj(String key) {
try {
JSONObject nested = mappedObj(key).getJSONObject(key);
ARMObject wrapper = new ARMObject();
wrapper.setJson(nested);
return wrapper;
} catch (JSONException exc) {
return null;
}
}

public java.util.List<ARMObject> getList(String key) {
java.util.List<ARMObject> result = new java.util.ArrayList<>();
try {
JSONArray arr = mappedObj(key).getJSONArray(key);
for (int i = 0; i < arr.length(); i++) {
ARMObject item = new ARMObject();
item.setJson(arr.getJSONObject(i));
result.add(item);
}
} catch (JSONException exc) {
// Return empty list on error
}
return result;
}

public <E extends ARMObject> java.util.List<E> getList(String key, Class<E> clazz) {
java.util.List<E> result = new java.util.ArrayList<>();
try {
JSONArray arr = mappedObj(key).getJSONArray(key);
for (int i = 0; i < arr.length(); i++) {
E item = clazz.getDeclaredConstructor().newInstance();
item.setJson(arr.getJSONObject(i));
result.add(item);
}
} catch (JSONException | ReflectiveOperationException exc) {
// Return empty list on error
}
return result;
}

public T set(String key, Object value) {
mappedObj(key).put(key, value);
return (T)this;
Expand Down
Loading