Skip to content

Commit d00ecbc

Browse files
Merge pull request #2194 from stripe/latest-codegen-beta
Update generated code for beta
2 parents 45d2730 + 48c442b commit d00ecbc

21 files changed

Lines changed: 764 additions & 387 deletions

CODEGEN_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
58595eed5a9dffbf0f297ecaf3ac45acf36c5de3
1+
25e6bd225852aa44d783e9fb3b9895af39479331

OPENAPI_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2205
1+
v2206

src/main/java/com/stripe/exception/RateLimitException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import lombok.Getter;
88

99
@Getter
10-
public class RateLimitException extends ApiException {
10+
public class RateLimitException extends StripeException {
1111
private static final long serialVersionUID = 2L;
1212

1313
private final String param;

src/main/java/com/stripe/exception/StripeException.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ public abstract class StripeException extends Exception {
2020
ApiMode stripeErrorApiMode;
2121

2222
public void setStripeError(StripeError err) {
23+
setStripeError(err, ApiMode.V1);
24+
}
25+
26+
public void setStripeError(StripeError err, ApiMode mode) {
2327
stripeError = err;
24-
stripeErrorApiMode = ApiMode.V1;
28+
stripeErrorApiMode = mode;
2529
}
2630

2731
public void setStripeV2Error(StripeError err) {
28-
stripeError = err;
29-
stripeErrorApiMode = ApiMode.V2;
32+
setStripeError(err, ApiMode.V2);
3033
}
3134
/**
3235
* Returns the error code of the response that triggered this exception. For {@link ApiException}

src/main/java/com/stripe/model/PaymentIntent.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7192,9 +7192,6 @@ public static class Sofort extends StripeObject {
71927192
@Setter
71937193
@EqualsAndHashCode(callSuper = false)
71947194
public static class StripeBalance extends StripeObject {
7195-
@SerializedName("mandate_options")
7196-
MandateOptions mandateOptions;
7197-
71987195
/**
71997196
* Indicates that you intend to make future payments with this PaymentIntent's payment method.
72007197
*
@@ -7218,19 +7215,6 @@ public static class StripeBalance extends StripeObject {
72187215
*/
72197216
@SerializedName("setup_future_usage")
72207217
String setupFutureUsage;
7221-
7222-
/**
7223-
* For more details about MandateOptions, please refer to the <a
7224-
* href="https://docs.stripe.com/api">API Reference.</a>
7225-
*/
7226-
@Getter
7227-
@Setter
7228-
@EqualsAndHashCode(callSuper = false)
7229-
public static class MandateOptions extends StripeObject {
7230-
/** The ID of the Stripe Balance Debit Agreement used for this mandate. */
7231-
@SerializedName("stripe_balance_debit_agreement")
7232-
String stripeBalanceDebitAgreement;
7233-
}
72347218
}
72357219

72367220
/**

src/main/java/com/stripe/model/SetupIntent.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,9 +1151,6 @@ public static class PaymentMethodOptions extends StripeObject {
11511151
@SerializedName("sepa_debit")
11521152
SepaDebit sepaDebit;
11531153

1154-
@SerializedName("stripe_balance")
1155-
StripeBalance stripeBalance;
1156-
11571154
@SerializedName("upi")
11581155
Upi upi;
11591156

@@ -1629,31 +1626,6 @@ public static class MandateOptions extends StripeObject {
16291626
}
16301627
}
16311628

1632-
/**
1633-
* For more details about StripeBalance, please refer to the <a
1634-
* href="https://docs.stripe.com/api">API Reference.</a>
1635-
*/
1636-
@Getter
1637-
@Setter
1638-
@EqualsAndHashCode(callSuper = false)
1639-
public static class StripeBalance extends StripeObject {
1640-
@SerializedName("mandate_options")
1641-
MandateOptions mandateOptions;
1642-
1643-
/**
1644-
* For more details about MandateOptions, please refer to the <a
1645-
* href="https://docs.stripe.com/api">API Reference.</a>
1646-
*/
1647-
@Getter
1648-
@Setter
1649-
@EqualsAndHashCode(callSuper = false)
1650-
public static class MandateOptions extends StripeObject {
1651-
/** The ID of the Stripe Balance Debit Agreement used for this mandate. */
1652-
@SerializedName("stripe_balance_debit_agreement")
1653-
String stripeBalanceDebitAgreement;
1654-
}
1655-
}
1656-
16571629
/**
16581630
* For more details about Upi, please refer to the <a href="https://docs.stripe.com/api">API
16591631
* Reference.</a>

src/main/java/com/stripe/net/LiveStripeResponseGetter.java

Lines changed: 45 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -331,110 +331,69 @@ private void handleError(StripeResponse response, ApiMode apiMode) throws Stripe
331331
}
332332

333333
private void handleV1ApiError(StripeResponse response) throws StripeException {
334-
StripeException exception = null;
335-
336-
StripeError error =
337-
parseStripeError(response.body(), response.code(), response.requestId(), StripeError.class);
338-
339-
error.setLastResponse(response);
340-
switch (response.code()) {
341-
case 400:
342-
case 404:
343-
if ("idempotency_error".equals(error.getType())) {
344-
exception =
345-
new IdempotencyException(
346-
error.getMessage(), response.requestId(), error.getCode(), response.code());
347-
} else {
348-
exception =
349-
new InvalidRequestException(
350-
error.getMessage(),
351-
error.getParam(),
352-
response.requestId(),
353-
error.getCode(),
354-
response.code(),
355-
null);
356-
}
357-
break;
358-
case 401:
359-
exception =
360-
new AuthenticationException(
361-
error.getMessage(), response.requestId(), error.getCode(), response.code());
362-
break;
363-
case 402:
364-
exception =
365-
new CardException(
366-
error.getMessage(),
367-
response.requestId(),
368-
error.getCode(),
369-
error.getParam(),
370-
error.getDeclineCode(),
371-
error.getCharge(),
372-
response.code(),
373-
null);
374-
break;
375-
case 403:
376-
exception =
377-
new PermissionException(
378-
error.getMessage(), response.requestId(), error.getCode(), response.code());
379-
break;
380-
case 429:
381-
exception =
382-
new RateLimitException(
383-
error.getMessage(),
384-
error.getParam(),
385-
response.requestId(),
386-
error.getCode(),
387-
response.code(),
388-
null);
389-
break;
390-
default:
391-
exception =
392-
new ApiException(
393-
error.getMessage(), response.requestId(), error.getCode(), response.code(), null);
394-
break;
395-
}
396-
exception.setStripeError(error);
397-
398-
throw exception;
334+
throwStripeException(response, ApiMode.V1);
399335
}
400336

401337
private void handleV2ApiError(StripeResponse response) throws StripeException {
338+
// First try to throw an exception based on the "type" field, if it exists and we
339+
// recognize it. Otherwise, we will fall back to throwing an exception based on status code.
402340
JsonObject body =
403341
ApiResource.GSON.fromJson(response.body(), JsonObject.class).getAsJsonObject("error");
404-
405342
JsonElement typeElement = body == null ? null : body.get("type");
406-
JsonElement codeElement = body == null ? null : body.get("code");
407343
String type = typeElement == null ? "<no_type>" : typeElement.getAsString();
408-
String code = codeElement == null ? "<no_code>" : codeElement.getAsString();
409-
410344
StripeException exception =
411345
StripeException.parseV2Exception(type, body, response.code(), response.requestId(), this);
412346
if (exception != null) {
413347
throw exception;
414348
}
415349

416-
StripeError error;
417-
try {
418-
error =
419-
parseStripeError(
420-
response.body(), response.code(), response.requestId(), StripeError.class);
421-
} catch (ApiException e) {
422-
String message = "Unrecognized error type '" + type + "'";
423-
JsonElement messageField = body == null ? null : body.get("message");
424-
if (messageField != null && messageField.isJsonPrimitive()) {
425-
message = messageField.getAsString();
426-
}
427-
428-
throw new ApiException(message, response.requestId(), code, response.code(), null);
429-
}
350+
throwStripeException(response, ApiMode.V2);
351+
}
430352

353+
private void throwStripeException(StripeResponse response, ApiMode apiMode)
354+
throws StripeException {
355+
StripeError error =
356+
parseStripeError(response.body(), response.code(), response.requestId(), StripeError.class);
431357
error.setLastResponse(response);
432-
exception =
433-
new ApiException(error.getMessage(), response.requestId(), code, response.code(), null);
434-
exception.setStripeV2Error(error);
358+
StripeException exception = exceptionFromStatus(response.code(), response.requestId(), error);
359+
exception.setStripeError(error, apiMode);
435360
throw exception;
436361
}
437362

363+
private StripeException exceptionFromStatus(int statusCode, String requestId, StripeError error) {
364+
switch (statusCode) {
365+
case 400:
366+
case 404:
367+
if ("idempotency_error".equals(error.getType())) {
368+
return new IdempotencyException(
369+
error.getMessage(), requestId, error.getCode(), statusCode);
370+
} else {
371+
return new InvalidRequestException(
372+
error.getMessage(), error.getParam(), requestId, error.getCode(), statusCode, null);
373+
}
374+
case 401:
375+
return new AuthenticationException(
376+
error.getMessage(), requestId, error.getCode(), statusCode);
377+
case 402:
378+
return new CardException(
379+
error.getMessage(),
380+
requestId,
381+
error.getCode(),
382+
error.getParam(),
383+
error.getDeclineCode(),
384+
error.getCharge(),
385+
statusCode,
386+
null);
387+
case 403:
388+
return new PermissionException(error.getMessage(), requestId, error.getCode(), statusCode);
389+
case 429:
390+
return new RateLimitException(
391+
error.getMessage(), error.getParam(), requestId, error.getCode(), statusCode, null);
392+
default:
393+
return new ApiException(error.getMessage(), requestId, error.getCode(), statusCode, null);
394+
}
395+
}
396+
438397
private void handleOAuthError(StripeResponse response) throws StripeException {
439398
OAuthError error = null;
440399
StripeException exception = null;

src/main/java/com/stripe/param/SetupIntentConfirmParams.java

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -7409,13 +7409,6 @@ public static class PaymentMethodOptions {
74097409
@SerializedName("sepa_debit")
74107410
SepaDebit sepaDebit;
74117411

7412-
/**
7413-
* If this is a {@code stripe_balance} PaymentMethod, this sub-hash contains details about the
7414-
* Stripe Balance payment method options.
7415-
*/
7416-
@SerializedName("stripe_balance")
7417-
StripeBalance stripeBalance;
7418-
74197412
/**
74207413
* If this is a {@code upi} SetupIntent, this sub-hash contains details about the UPI payment
74217414
* method options.
@@ -7443,7 +7436,6 @@ private PaymentMethodOptions(
74437436
Payto payto,
74447437
Pix pix,
74457438
SepaDebit sepaDebit,
7446-
StripeBalance stripeBalance,
74477439
Upi upi,
74487440
UsBankAccount usBankAccount) {
74497441
this.acssDebit = acssDebit;
@@ -7458,7 +7450,6 @@ private PaymentMethodOptions(
74587450
this.payto = payto;
74597451
this.pix = pix;
74607452
this.sepaDebit = sepaDebit;
7461-
this.stripeBalance = stripeBalance;
74627453
this.upi = upi;
74637454
this.usBankAccount = usBankAccount;
74647455
}
@@ -7492,8 +7483,6 @@ public static class Builder {
74927483

74937484
private SepaDebit sepaDebit;
74947485

7495-
private StripeBalance stripeBalance;
7496-
74977486
private Upi upi;
74987487

74997488
private UsBankAccount usBankAccount;
@@ -7513,7 +7502,6 @@ public SetupIntentConfirmParams.PaymentMethodOptions build() {
75137502
this.payto,
75147503
this.pix,
75157504
this.sepaDebit,
7516-
this.stripeBalance,
75177505
this.upi,
75187506
this.usBankAccount);
75197507
}
@@ -7646,16 +7634,6 @@ public Builder setSepaDebit(
76467634
return this;
76477635
}
76487636

7649-
/**
7650-
* If this is a {@code stripe_balance} PaymentMethod, this sub-hash contains details about the
7651-
* Stripe Balance payment method options.
7652-
*/
7653-
public Builder setStripeBalance(
7654-
SetupIntentConfirmParams.PaymentMethodOptions.StripeBalance stripeBalance) {
7655-
this.stripeBalance = stripeBalance;
7656-
return this;
7657-
}
7658-
76597637
/**
76607638
* If this is a {@code upi} SetupIntent, this sub-hash contains details about the UPI payment
76617639
* method options.
@@ -11411,64 +11389,6 @@ public Builder setReferencePrefix(EmptyParam referencePrefix) {
1141111389
}
1141211390
}
1141311391

11414-
@Getter
11415-
@EqualsAndHashCode(callSuper = false)
11416-
public static class StripeBalance {
11417-
/**
11418-
* Map of extra parameters for custom features not available in this client library. The
11419-
* content in this map is not serialized under this field's {@code @SerializedName} value.
11420-
* Instead, each key/value pair is serialized as if the key is a root-level field (serialized)
11421-
* name in this param object. Effectively, this map is flattened to its parent instance.
11422-
*/
11423-
@SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY)
11424-
Map<String, Object> extraParams;
11425-
11426-
private StripeBalance(Map<String, Object> extraParams) {
11427-
this.extraParams = extraParams;
11428-
}
11429-
11430-
public static Builder builder() {
11431-
return new Builder();
11432-
}
11433-
11434-
public static class Builder {
11435-
private Map<String, Object> extraParams;
11436-
11437-
/** Finalize and obtain parameter instance from this builder. */
11438-
public SetupIntentConfirmParams.PaymentMethodOptions.StripeBalance build() {
11439-
return new SetupIntentConfirmParams.PaymentMethodOptions.StripeBalance(this.extraParams);
11440-
}
11441-
11442-
/**
11443-
* Add a key/value pair to `extraParams` map. A map is initialized for the first
11444-
* `put/putAll` call, and subsequent calls add additional key/value pairs to the original
11445-
* map. See {@link SetupIntentConfirmParams.PaymentMethodOptions.StripeBalance#extraParams}
11446-
* for the field documentation.
11447-
*/
11448-
public Builder putExtraParam(String key, Object value) {
11449-
if (this.extraParams == null) {
11450-
this.extraParams = new HashMap<>();
11451-
}
11452-
this.extraParams.put(key, value);
11453-
return this;
11454-
}
11455-
11456-
/**
11457-
* Add all map key/value pairs to `extraParams` map. A map is initialized for the first
11458-
* `put/putAll` call, and subsequent calls add additional key/value pairs to the original
11459-
* map. See {@link SetupIntentConfirmParams.PaymentMethodOptions.StripeBalance#extraParams}
11460-
* for the field documentation.
11461-
*/
11462-
public Builder putAllExtraParam(Map<String, Object> map) {
11463-
if (this.extraParams == null) {
11464-
this.extraParams = new HashMap<>();
11465-
}
11466-
this.extraParams.putAll(map);
11467-
return this;
11468-
}
11469-
}
11470-
}
11471-
1147211392
@Getter
1147311393
@EqualsAndHashCode(callSuper = false)
1147411394
public static class Upi {

0 commit comments

Comments
 (0)