Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stripe-java v23 release #1622

Merged
merged 5 commits into from
Aug 16, 2023
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
80 changes: 77 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,82 @@
# Changelog

## 22.31.0 - 2023-08-10
* [#1623](https://github.com/stripe/stripe-java/pull/1623) Update generated code
* Add support for new values `incorporated_partnership` and `unincorporated_partnership` on enums `AccountCreateParams.company.structure`, `AccountUpdateParams.company.structure`, and `TokenCreateParams.account.company.structure`

## 23.0.0 - 2023-08-16

### StripeClient

`StripeClient` and the new service-based pattern is introduced. `StripeClient` has multiple benefits over existing resource-based patterns:
1. Allows to have multiple clients with different connection options (different API keys).
2. All operations can be performed in a single HTTP call.
```java
// Before: creating funding instructions takes two HTTP calls
Customer customer = Customer.retrieve("cus_123"); // HTTP call 1
customer.createFundingInstructions(..); // HTTP call 2

// After: creating funding instructions is a single HTTP call
StripeClient client = new StripeClient();
client.customers().createFundingInstructions("cus_123", ...); // HTTP call 1
```
3. `StripeClient` is easier to mock for testing as all methods are instance methods.

### Migration

To migrate from resource-based to service-based pattern:
1. Initialize a `StripeClient` instance.
```java
// Before
Stripe.apiKey = "sk_test_123"

// After
StripeClient client = new StripeClient("sk_test_123");
```
2. Convert static resource method calls to `StripeClient` calls:
```java
// Before
Customer customer = Customer.retrieve("cus_123");

// After
client.customers().retrieve("cus_123");
```
3. Convert instance resource method calls to `StripeClient` calls. Params classes will, in most cases, stay the same as you used for resource-based calls.
```java
// Before
Customer customer = Customer.retrive("cus_123");
customer.delete();

// After
client.customers().delete("cus_123");

// After
client.customers().delete(customer.id);
PaymentMethod pm = client.customers().retrievePaymentMethod(customer.id, "pm_123");
```

### Breaking changes

- `RequestOptions.getReadTimeout()`, `getConnectTimeout()`, `getMaxNetworkRetries()` now return `Integer` instead of `int`.
- `RequestOptions.getDefault()` does not apply global configuration options from `Stripe` class, all fields are initialized to `null`.
- `RequestOptionsBuilder` does not apply global configuration options from `Stripe` class, all fields are initialized to `null`.
- `StripeResponseGetter.oauthRequest(...)` was removed. OAuth requests are now performed via `StripeResponseGetter.request` with `ApiMode.OAuth`.
- `StripeResponseGetter.request(...)`, `streamRequest(...)` signatures changed.
- `BaseAddress` parameter added.
- `url` renamed to `path` and is a relative to the base address
- `apiMode` parameter added to control how request is sent and response is handled, `V1` and `OAuth` are supported values.
- Deprecated `ApiResource.className()` `singleClassUrl()`, `classUrl()`, `instanceUrl()`, `subresourceUrl()` methods removed.
- `ApiResource.request()`, `requestStream()`, `requestCollection()`, `requestSearchResult()` methods removed.
If you were using one of these methods, please migrate to `StripeClient.getResponseGetter().request()`:
```java
StripeClient client = new StripeClient("sk_test_...");
client.getResponseGetter().request(
BaseAddress.API,
ApiResource.RequestMethod.GET,
"/customers",
null, // params
Customer.class, // type
null, // options
ApiMode.V1);
```


## 22.30.0 - 2023-08-03
* [#1620](https://github.com/stripe/stripe-java/pull/1620) Update generated code
Expand Down
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Stripe Java client library

[![Maven Central](https://img.shields.io/badge/maven--central-v22.31.0-blue)](https://mvnrepository.com/artifact/com.stripe/stripe-java)
[![Maven Central](https://img.shields.io/badge/maven--central-v22.30.0-blue)](https://mvnrepository.com/artifact/com.stripe/stripe-java)
[![JavaDoc](http://img.shields.io/badge/javadoc-reference-blue.svg)](https://stripe.dev/stripe-java)
[![Build Status](https://github.com/stripe/stripe-java/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/stripe/stripe-java/actions?query=branch%3Amaster)
[![Coverage Status](https://coveralls.io/repos/github/stripe/stripe-java/badge.svg?branch=master)](https://coveralls.io/github/stripe/stripe-java?branch=master)
Expand All @@ -18,7 +18,7 @@ The official [Stripe][stripe] Java client library.
Add this dependency to your project's build file:

```groovy
implementation "com.stripe:stripe-java:22.31.0"
implementation "com.stripe:stripe-java:22.30.0"
```

### Maven users
Expand All @@ -29,15 +29,15 @@ Add this dependency to your project's POM:
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>22.31.0</version>
<version>22.30.0</version>
</dependency>
```

### Others

You'll need to manually install the following JARs:

- [The Stripe JAR](https://search.maven.org/remotecontent?filepath=com/stripe/stripe-java/22.31.0/stripe-java-22.31.0.jar)
- [The Stripe JAR](https://search.maven.org/remotecontent?filepath=com/stripe/stripe-java/22.30.0/stripe-java-22.30.0.jar)
- [Google Gson][gson] from <https://repo1.maven.org/maven2/com/google/code/gson/gson/2.10.1/gson-2.10.1.jar>.

### [ProGuard][proguard]
Expand Down Expand Up @@ -67,7 +67,7 @@ StripeExample.java
import java.util.HashMap;
import java.util.Map;

import com.stripe.Stripe;
import com.stripe.StripeClient;
import com.stripe.exception.StripeException;
import com.stripe.model.Customer;
import com.stripe.net.RequestOptions;
Expand All @@ -76,8 +76,7 @@ import com.stripe.param.CustomerCreateParams;
public class StripeExample {

public static void main(String[] args) {
Stripe.apiKey = "sk_test_...";

StripeClient client = new StripeClient("sk_test_...");
CustomerCreateParams params =
CustomerCreateParams
.builder()
Expand All @@ -87,7 +86,7 @@ public class StripeExample {
.build();

try {
Customer customer = Customer.create(params);
Customer customer = client.customers().create(params);
System.out.println(customer);
} catch (StripeException e) {
e.printStackTrace();
Expand All @@ -112,9 +111,9 @@ RequestOptions requestOptions = RequestOptions.builder()
.setStripeAccount("acct_...")
.build();

Customer.list(null, requestOptions);
client.customers().list(requestOptions);

Customer.retrieve("cus_123456789", requestOptions);
client.customers().retrieve("cus_123456789", requestOptions);
```

### Configuring automatic retries
Expand All @@ -124,7 +123,9 @@ an intermittent network problem or other knowingly non-deterministic errors.
This can be enabled globally:

```java
Stripe.setMaxNetworkRetries(2);
StripeClient client = StripeClient.builder()
.setMaxNetworkRetries(2)
.build();
```

Or on a finer grain level using `RequestOptions`:
Expand All @@ -133,7 +134,7 @@ Or on a finer grain level using `RequestOptions`:
RequestOptions options = RequestOptions.builder()
.setMaxNetworkRetries(2)
.build();
Customer.create(params, options);
client.customers().create(params, options);
```

[Idempotency keys][idempotency-keys] are added to requests to guarantee that
Expand All @@ -144,8 +145,10 @@ retries are safe.
Connect and read timeouts can be configured globally:

```java
Stripe.setConnectTimeout(30 * 1000); // in milliseconds
Stripe.setReadTimeout(80 * 1000);
StripeClient client = StripeClient.builder()
.setConnectTimeout(30 * 1000); // in milliseconds
.setReadTimeout(80 * 1000);
.build();
```

Or on a finer grain level using `RequestOptions`:
Expand All @@ -155,7 +158,7 @@ RequestOptions options = RequestOptions.builder()
.setConnectTimeout(30 * 1000) // in milliseconds
.setReadTimeout(80 * 1000)
.build();
Customer.create(params, options);
client.customers().create(params, options);
```

Please take care to set conservative read timeouts. Some API requests can take
Expand Down Expand Up @@ -191,15 +194,15 @@ CustomerCreateParams params =
.putExtraParam("secret_parameter[secondary]", "secondary value")
.build();

Customer customer = customer.Create(params);
client.customers().create(params);
```

#### Properties

To retrieve undocumented properties from Stripe using Java you can use an option in the library to return the raw JSON object and return the property as a native type. An example of this is shown below:

```java
final Customer customer = Customer.retrieve("cus_1234");
final Customer customer = client.customers().retrieve("cus_1234");
Boolean featureEnabled =
customer.getRawJsonObject()
.getAsJsonPrimitive("secret_feature_enabled")
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22.31.0
22.30.0
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GROUP=com.stripe
VERSION_NAME=22.31.0
VERSION_NAME=22.30.0

POM_URL=https://github.com/stripe/stripe-java
POM_SCM_URL=git@github.com:stripe/stripe-java.git
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/stripe/Stripe.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class Stripe {
public static final String CONNECT_API_BASE = "https://connect.stripe.com";
public static final String LIVE_API_BASE = "https://api.stripe.com";
public static final String UPLOAD_API_BASE = "https://files.stripe.com";
public static final String VERSION = "22.31.0";
public static final String VERSION = "22.30.0";

public static volatile String apiKey;
public static volatile String clientId;
Expand Down
Loading