• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stripe / stripe-java / #16380

30 Aug 2024 07:54PM UTC coverage: 12.882% (-0.004%) from 12.886%
#16380

push

github

web-flow
Merge from master after the changes to not pass api_mode from individual methods (#1857)

* Generate SDK for OpenAPI spec version 1230 (#1856)

* Bump version to 26.9.0

* No need for APIMode to be passed around from individual API methods (#1855)

* Generated code

* Update the code around raw request

* Update the v2 tests to use v2 path

16 of 23 new or added lines in 7 files covered. (69.57%)

706 existing lines in 213 files now uncovered.

18468 of 143365 relevant lines covered (12.88%)

0.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.91
/src/main/java/com/stripe/service/PaymentMethodService.java
1
// File generated from our OpenAPI spec
2
package com.stripe.service;
3

4
import com.google.gson.reflect.TypeToken;
5
import com.stripe.exception.StripeException;
6
import com.stripe.model.PaymentMethod;
7
import com.stripe.model.StripeCollection;
8
import com.stripe.net.ApiRequest;
9
import com.stripe.net.ApiRequestParams;
10
import com.stripe.net.ApiResource;
11
import com.stripe.net.ApiService;
12
import com.stripe.net.BaseAddress;
13
import com.stripe.net.RequestOptions;
14
import com.stripe.net.StripeResponseGetter;
15
import com.stripe.param.PaymentMethodAttachParams;
16
import com.stripe.param.PaymentMethodCreateParams;
17
import com.stripe.param.PaymentMethodDetachParams;
18
import com.stripe.param.PaymentMethodListParams;
19
import com.stripe.param.PaymentMethodRetrieveParams;
20
import com.stripe.param.PaymentMethodUpdateParams;
21

22
public final class PaymentMethodService extends ApiService {
23
  public PaymentMethodService(StripeResponseGetter responseGetter) {
24
    super(responseGetter);
1✔
25
  }
1✔
26

27
  /**
28
   * Returns a list of PaymentMethods for Treasury flows. If you want to list the PaymentMethods
29
   * attached to a Customer for payments, you should use the <a
30
   * href="https://stripe.com/docs/api/payment_methods/customer_list">List a Customer’s
31
   * PaymentMethods</a> API instead.
32
   */
33
  public StripeCollection<PaymentMethod> list(PaymentMethodListParams params)
34
      throws StripeException {
35
    return list(params, (RequestOptions) null);
1✔
36
  }
37
  /**
38
   * Returns a list of PaymentMethods for Treasury flows. If you want to list the PaymentMethods
39
   * attached to a Customer for payments, you should use the <a
40
   * href="https://stripe.com/docs/api/payment_methods/customer_list">List a Customer’s
41
   * PaymentMethods</a> API instead.
42
   */
43
  public StripeCollection<PaymentMethod> list(RequestOptions options) throws StripeException {
44
    return list((PaymentMethodListParams) null, options);
×
45
  }
46
  /**
47
   * Returns a list of PaymentMethods for Treasury flows. If you want to list the PaymentMethods
48
   * attached to a Customer for payments, you should use the <a
49
   * href="https://stripe.com/docs/api/payment_methods/customer_list">List a Customer’s
50
   * PaymentMethods</a> API instead.
51
   */
52
  public StripeCollection<PaymentMethod> list() throws StripeException {
53
    return list((PaymentMethodListParams) null, (RequestOptions) null);
×
54
  }
55
  /**
56
   * Returns a list of PaymentMethods for Treasury flows. If you want to list the PaymentMethods
57
   * attached to a Customer for payments, you should use the <a
58
   * href="https://stripe.com/docs/api/payment_methods/customer_list">List a Customer’s
59
   * PaymentMethods</a> API instead.
60
   */
61
  public StripeCollection<PaymentMethod> list(
62
      PaymentMethodListParams params, RequestOptions options) throws StripeException {
63
    String path = "/v1/payment_methods";
1✔
64
    ApiRequest request =
1✔
65
        new ApiRequest(
66
            BaseAddress.API,
67
            ApiResource.RequestMethod.GET,
68
            path,
69
            ApiRequestParams.paramsToMap(params),
1✔
70
            options);
71
    return this.request(request, new TypeToken<StripeCollection<PaymentMethod>>() {}.getType());
1✔
72
  }
73
  /**
74
   * Creates a PaymentMethod object. Read the <a
75
   * href="https://stripe.com/docs/stripe-js/reference#stripe-create-payment-method">Stripe.js
76
   * reference</a> to learn how to create PaymentMethods via Stripe.js.
77
   *
78
   * <p>Instead of creating a PaymentMethod directly, we recommend using the <a
79
   * href="https://stripe.com/docs/payments/accept-a-payment">PaymentIntents</a> API to accept a
80
   * payment immediately or the <a
81
   * href="https://stripe.com/docs/payments/save-and-reuse">SetupIntent</a> API to collect payment
82
   * method details ahead of a future payment.
83
   */
84
  public PaymentMethod create(PaymentMethodCreateParams params) throws StripeException {
85
    return create(params, (RequestOptions) null);
×
86
  }
87
  /**
88
   * Creates a PaymentMethod object. Read the <a
89
   * href="https://stripe.com/docs/stripe-js/reference#stripe-create-payment-method">Stripe.js
90
   * reference</a> to learn how to create PaymentMethods via Stripe.js.
91
   *
92
   * <p>Instead of creating a PaymentMethod directly, we recommend using the <a
93
   * href="https://stripe.com/docs/payments/accept-a-payment">PaymentIntents</a> API to accept a
94
   * payment immediately or the <a
95
   * href="https://stripe.com/docs/payments/save-and-reuse">SetupIntent</a> API to collect payment
96
   * method details ahead of a future payment.
97
   */
98
  public PaymentMethod create(RequestOptions options) throws StripeException {
99
    return create((PaymentMethodCreateParams) null, options);
×
100
  }
101
  /**
102
   * Creates a PaymentMethod object. Read the <a
103
   * href="https://stripe.com/docs/stripe-js/reference#stripe-create-payment-method">Stripe.js
104
   * reference</a> to learn how to create PaymentMethods via Stripe.js.
105
   *
106
   * <p>Instead of creating a PaymentMethod directly, we recommend using the <a
107
   * href="https://stripe.com/docs/payments/accept-a-payment">PaymentIntents</a> API to accept a
108
   * payment immediately or the <a
109
   * href="https://stripe.com/docs/payments/save-and-reuse">SetupIntent</a> API to collect payment
110
   * method details ahead of a future payment.
111
   */
112
  public PaymentMethod create() throws StripeException {
113
    return create((PaymentMethodCreateParams) null, (RequestOptions) null);
×
114
  }
115
  /**
116
   * Creates a PaymentMethod object. Read the <a
117
   * href="https://stripe.com/docs/stripe-js/reference#stripe-create-payment-method">Stripe.js
118
   * reference</a> to learn how to create PaymentMethods via Stripe.js.
119
   *
120
   * <p>Instead of creating a PaymentMethod directly, we recommend using the <a
121
   * href="https://stripe.com/docs/payments/accept-a-payment">PaymentIntents</a> API to accept a
122
   * payment immediately or the <a
123
   * href="https://stripe.com/docs/payments/save-and-reuse">SetupIntent</a> API to collect payment
124
   * method details ahead of a future payment.
125
   */
126
  public PaymentMethod create(PaymentMethodCreateParams params, RequestOptions options)
127
      throws StripeException {
128
    String path = "/v1/payment_methods";
×
129
    ApiRequest request =
×
130
        new ApiRequest(
131
            BaseAddress.API,
132
            ApiResource.RequestMethod.POST,
133
            path,
134
            ApiRequestParams.paramsToMap(params),
×
135
            options);
UNCOV
136
    return this.request(request, PaymentMethod.class);
×
137
  }
138
  /**
139
   * Retrieves a PaymentMethod object attached to the StripeAccount. To retrieve a payment method
140
   * attached to a Customer, you should use <a
141
   * href="https://stripe.com/docs/api/payment_methods/customer">Retrieve a Customer’s
142
   * PaymentMethods</a>
143
   */
144
  public PaymentMethod retrieve(String paymentMethod, PaymentMethodRetrieveParams params)
145
      throws StripeException {
146
    return retrieve(paymentMethod, params, (RequestOptions) null);
1✔
147
  }
148
  /**
149
   * Retrieves a PaymentMethod object attached to the StripeAccount. To retrieve a payment method
150
   * attached to a Customer, you should use <a
151
   * href="https://stripe.com/docs/api/payment_methods/customer">Retrieve a Customer’s
152
   * PaymentMethods</a>
153
   */
154
  public PaymentMethod retrieve(String paymentMethod, RequestOptions options)
155
      throws StripeException {
156
    return retrieve(paymentMethod, (PaymentMethodRetrieveParams) null, options);
×
157
  }
158
  /**
159
   * Retrieves a PaymentMethod object attached to the StripeAccount. To retrieve a payment method
160
   * attached to a Customer, you should use <a
161
   * href="https://stripe.com/docs/api/payment_methods/customer">Retrieve a Customer’s
162
   * PaymentMethods</a>
163
   */
164
  public PaymentMethod retrieve(String paymentMethod) throws StripeException {
165
    return retrieve(paymentMethod, (PaymentMethodRetrieveParams) null, (RequestOptions) null);
×
166
  }
167
  /**
168
   * Retrieves a PaymentMethod object attached to the StripeAccount. To retrieve a payment method
169
   * attached to a Customer, you should use <a
170
   * href="https://stripe.com/docs/api/payment_methods/customer">Retrieve a Customer’s
171
   * PaymentMethods</a>
172
   */
173
  public PaymentMethod retrieve(
174
      String paymentMethod, PaymentMethodRetrieveParams params, RequestOptions options)
175
      throws StripeException {
176
    String path = String.format("/v1/payment_methods/%s", ApiResource.urlEncodeId(paymentMethod));
1✔
177
    ApiRequest request =
1✔
178
        new ApiRequest(
179
            BaseAddress.API,
180
            ApiResource.RequestMethod.GET,
181
            path,
182
            ApiRequestParams.paramsToMap(params),
1✔
183
            options);
184
    return this.request(request, PaymentMethod.class);
1✔
185
  }
186
  /** Updates a PaymentMethod object. A PaymentMethod must be attached a customer to be updated. */
187
  public PaymentMethod update(String paymentMethod, PaymentMethodUpdateParams params)
188
      throws StripeException {
189
    return update(paymentMethod, params, (RequestOptions) null);
1✔
190
  }
191
  /** Updates a PaymentMethod object. A PaymentMethod must be attached a customer to be updated. */
192
  public PaymentMethod update(String paymentMethod, RequestOptions options) throws StripeException {
193
    return update(paymentMethod, (PaymentMethodUpdateParams) null, options);
×
194
  }
195
  /** Updates a PaymentMethod object. A PaymentMethod must be attached a customer to be updated. */
196
  public PaymentMethod update(String paymentMethod) throws StripeException {
197
    return update(paymentMethod, (PaymentMethodUpdateParams) null, (RequestOptions) null);
×
198
  }
199
  /** Updates a PaymentMethod object. A PaymentMethod must be attached a customer to be updated. */
200
  public PaymentMethod update(
201
      String paymentMethod, PaymentMethodUpdateParams params, RequestOptions options)
202
      throws StripeException {
203
    String path = String.format("/v1/payment_methods/%s", ApiResource.urlEncodeId(paymentMethod));
1✔
204
    ApiRequest request =
1✔
205
        new ApiRequest(
206
            BaseAddress.API,
207
            ApiResource.RequestMethod.POST,
208
            path,
209
            ApiRequestParams.paramsToMap(params),
1✔
210
            options);
211
    return this.request(request, PaymentMethod.class);
1✔
212
  }
213
  /**
214
   * Attaches a PaymentMethod object to a Customer.
215
   *
216
   * <p>To attach a new PaymentMethod to a customer for future payments, we recommend you use a <a
217
   * href="https://stripe.com/docs/api/setup_intents">SetupIntent</a> or a PaymentIntent with <a
218
   * href="https://stripe.com/docs/api/payment_intents/create#create_payment_intent-setup_future_usage">setup_future_usage</a>.
219
   * These approaches will perform any necessary steps to set up the PaymentMethod for future
220
   * payments. Using the {@code /v1/payment_methods/:id/attach} endpoint without first using a
221
   * SetupIntent or PaymentIntent with {@code setup_future_usage} does not optimize the
222
   * PaymentMethod for future use, which makes later declines and payment friction more likely. See
223
   * <a href="https://stripe.com/docs/payments/payment-intents#future-usage">Optimizing cards for
224
   * future payments</a> for more information about setting up future payments.
225
   *
226
   * <p>To use this PaymentMethod as the default for invoice or subscription payments, set <a
227
   * href="https://stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method">{@code
228
   * invoice_settings.default_payment_method}</a>, on the Customer to the PaymentMethod’s ID.
229
   */
230
  public PaymentMethod attach(String paymentMethod, PaymentMethodAttachParams params)
231
      throws StripeException {
232
    return attach(paymentMethod, params, (RequestOptions) null);
1✔
233
  }
234
  /**
235
   * Attaches a PaymentMethod object to a Customer.
236
   *
237
   * <p>To attach a new PaymentMethod to a customer for future payments, we recommend you use a <a
238
   * href="https://stripe.com/docs/api/setup_intents">SetupIntent</a> or a PaymentIntent with <a
239
   * href="https://stripe.com/docs/api/payment_intents/create#create_payment_intent-setup_future_usage">setup_future_usage</a>.
240
   * These approaches will perform any necessary steps to set up the PaymentMethod for future
241
   * payments. Using the {@code /v1/payment_methods/:id/attach} endpoint without first using a
242
   * SetupIntent or PaymentIntent with {@code setup_future_usage} does not optimize the
243
   * PaymentMethod for future use, which makes later declines and payment friction more likely. See
244
   * <a href="https://stripe.com/docs/payments/payment-intents#future-usage">Optimizing cards for
245
   * future payments</a> for more information about setting up future payments.
246
   *
247
   * <p>To use this PaymentMethod as the default for invoice or subscription payments, set <a
248
   * href="https://stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method">{@code
249
   * invoice_settings.default_payment_method}</a>, on the Customer to the PaymentMethod’s ID.
250
   */
251
  public PaymentMethod attach(
252
      String paymentMethod, PaymentMethodAttachParams params, RequestOptions options)
253
      throws StripeException {
254
    String path =
1✔
255
        String.format("/v1/payment_methods/%s/attach", ApiResource.urlEncodeId(paymentMethod));
1✔
256
    ApiRequest request =
1✔
257
        new ApiRequest(
258
            BaseAddress.API,
259
            ApiResource.RequestMethod.POST,
260
            path,
261
            ApiRequestParams.paramsToMap(params),
1✔
262
            options);
263
    return this.request(request, PaymentMethod.class);
1✔
264
  }
265
  /**
266
   * Detaches a PaymentMethod object from a Customer. After a PaymentMethod is detached, it can no
267
   * longer be used for a payment or re-attached to a Customer.
268
   */
269
  public PaymentMethod detach(String paymentMethod, PaymentMethodDetachParams params)
270
      throws StripeException {
271
    return detach(paymentMethod, params, (RequestOptions) null);
1✔
272
  }
273
  /**
274
   * Detaches a PaymentMethod object from a Customer. After a PaymentMethod is detached, it can no
275
   * longer be used for a payment or re-attached to a Customer.
276
   */
277
  public PaymentMethod detach(String paymentMethod, RequestOptions options) throws StripeException {
278
    return detach(paymentMethod, (PaymentMethodDetachParams) null, options);
×
279
  }
280
  /**
281
   * Detaches a PaymentMethod object from a Customer. After a PaymentMethod is detached, it can no
282
   * longer be used for a payment or re-attached to a Customer.
283
   */
284
  public PaymentMethod detach(String paymentMethod) throws StripeException {
285
    return detach(paymentMethod, (PaymentMethodDetachParams) null, (RequestOptions) null);
×
286
  }
287
  /**
288
   * Detaches a PaymentMethod object from a Customer. After a PaymentMethod is detached, it can no
289
   * longer be used for a payment or re-attached to a Customer.
290
   */
291
  public PaymentMethod detach(
292
      String paymentMethod, PaymentMethodDetachParams params, RequestOptions options)
293
      throws StripeException {
294
    String path =
1✔
295
        String.format("/v1/payment_methods/%s/detach", ApiResource.urlEncodeId(paymentMethod));
1✔
296
    ApiRequest request =
1✔
297
        new ApiRequest(
298
            BaseAddress.API,
299
            ApiResource.RequestMethod.POST,
300
            path,
301
            ApiRequestParams.paramsToMap(params),
1✔
302
            options);
303
    return this.request(request, PaymentMethod.class);
1✔
304
  }
305
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc