1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
|
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._stripe_service import StripeService
from stripe._util import sanitize_id
from typing import Optional, cast
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from stripe._list_object import ListObject
from stripe._payment_method import PaymentMethod
from stripe._request_options import RequestOptions
from stripe.params._payment_method_attach_params import (
PaymentMethodAttachParams,
)
from stripe.params._payment_method_create_params import (
PaymentMethodCreateParams,
)
from stripe.params._payment_method_detach_params import (
PaymentMethodDetachParams,
)
from stripe.params._payment_method_list_params import (
PaymentMethodListParams,
)
from stripe.params._payment_method_retrieve_params import (
PaymentMethodRetrieveParams,
)
from stripe.params._payment_method_update_params import (
PaymentMethodUpdateParams,
)
class PaymentMethodService(StripeService):
def list(
self,
params: Optional["PaymentMethodListParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "ListObject[PaymentMethod]":
"""
Returns a list of PaymentMethods for Treasury flows. If you want to list the PaymentMethods attached to a Customer for payments, you should use the [List a Customer's PaymentMethods](https://docs.stripe.com/docs/api/payment_methods/customer_list) API instead.
"""
return cast(
"ListObject[PaymentMethod]",
self._request(
"get",
"/v1/payment_methods",
base_address="api",
params=params,
options=options,
),
)
async def list_async(
self,
params: Optional["PaymentMethodListParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "ListObject[PaymentMethod]":
"""
Returns a list of PaymentMethods for Treasury flows. If you want to list the PaymentMethods attached to a Customer for payments, you should use the [List a Customer's PaymentMethods](https://docs.stripe.com/docs/api/payment_methods/customer_list) API instead.
"""
return cast(
"ListObject[PaymentMethod]",
await self._request_async(
"get",
"/v1/payment_methods",
base_address="api",
params=params,
options=options,
),
)
def create(
self,
params: Optional["PaymentMethodCreateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "PaymentMethod":
"""
Creates a PaymentMethod object. Read the [Stripe.js reference](https://docs.stripe.com/docs/stripe-js/reference#stripe-create-payment-method) to learn how to create PaymentMethods via Stripe.js.
Instead of creating a PaymentMethod directly, we recommend using the [PaymentIntents API to accept a payment immediately or the <a href="/docs/payments/save-and-reuse">SetupIntent](https://docs.stripe.com/docs/payments/accept-a-payment) API to collect payment method details ahead of a future payment.
"""
return cast(
"PaymentMethod",
self._request(
"post",
"/v1/payment_methods",
base_address="api",
params=params,
options=options,
),
)
async def create_async(
self,
params: Optional["PaymentMethodCreateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "PaymentMethod":
"""
Creates a PaymentMethod object. Read the [Stripe.js reference](https://docs.stripe.com/docs/stripe-js/reference#stripe-create-payment-method) to learn how to create PaymentMethods via Stripe.js.
Instead of creating a PaymentMethod directly, we recommend using the [PaymentIntents API to accept a payment immediately or the <a href="/docs/payments/save-and-reuse">SetupIntent](https://docs.stripe.com/docs/payments/accept-a-payment) API to collect payment method details ahead of a future payment.
"""
return cast(
"PaymentMethod",
await self._request_async(
"post",
"/v1/payment_methods",
base_address="api",
params=params,
options=options,
),
)
def retrieve(
self,
payment_method: str,
params: Optional["PaymentMethodRetrieveParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "PaymentMethod":
"""
Retrieves a PaymentMethod object attached to the StripeAccount. To retrieve a payment method attached to a Customer, you should use [Retrieve a Customer's PaymentMethods](https://docs.stripe.com/docs/api/payment_methods/customer)
"""
return cast(
"PaymentMethod",
self._request(
"get",
"/v1/payment_methods/{payment_method}".format(
payment_method=sanitize_id(payment_method),
),
base_address="api",
params=params,
options=options,
),
)
async def retrieve_async(
self,
payment_method: str,
params: Optional["PaymentMethodRetrieveParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "PaymentMethod":
"""
Retrieves a PaymentMethod object attached to the StripeAccount. To retrieve a payment method attached to a Customer, you should use [Retrieve a Customer's PaymentMethods](https://docs.stripe.com/docs/api/payment_methods/customer)
"""
return cast(
"PaymentMethod",
await self._request_async(
"get",
"/v1/payment_methods/{payment_method}".format(
payment_method=sanitize_id(payment_method),
),
base_address="api",
params=params,
options=options,
),
)
def update(
self,
payment_method: str,
params: Optional["PaymentMethodUpdateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "PaymentMethod":
"""
Updates a PaymentMethod object. A PaymentMethod must be attached to a customer to be updated.
"""
return cast(
"PaymentMethod",
self._request(
"post",
"/v1/payment_methods/{payment_method}".format(
payment_method=sanitize_id(payment_method),
),
base_address="api",
params=params,
options=options,
),
)
async def update_async(
self,
payment_method: str,
params: Optional["PaymentMethodUpdateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "PaymentMethod":
"""
Updates a PaymentMethod object. A PaymentMethod must be attached to a customer to be updated.
"""
return cast(
"PaymentMethod",
await self._request_async(
"post",
"/v1/payment_methods/{payment_method}".format(
payment_method=sanitize_id(payment_method),
),
base_address="api",
params=params,
options=options,
),
)
def attach(
self,
payment_method: str,
params: "PaymentMethodAttachParams",
options: Optional["RequestOptions"] = None,
) -> "PaymentMethod":
"""
Attaches a PaymentMethod object to a Customer.
To attach a new PaymentMethod to a customer for future payments, we recommend you use a [SetupIntent](https://docs.stripe.com/docs/api/setup_intents)
or a PaymentIntent with [setup_future_usage](https://docs.stripe.com/docs/api/payment_intents/create#create_payment_intent-setup_future_usage).
These approaches will perform any necessary steps to set up the PaymentMethod for future payments. Using the /v1/payment_methods/:id/attach
endpoint without first using a SetupIntent or PaymentIntent with setup_future_usage does not optimize the PaymentMethod for
future use, which makes later declines and payment friction more likely.
See [Optimizing cards for future payments](https://docs.stripe.com/docs/payments/payment-intents#future-usage) for more information about setting up
future payments.
To use this PaymentMethod as the default for invoice or subscription payments,
set [invoice_settings.default_payment_method](https://docs.stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method),
on the Customer to the PaymentMethod's ID.
"""
return cast(
"PaymentMethod",
self._request(
"post",
"/v1/payment_methods/{payment_method}/attach".format(
payment_method=sanitize_id(payment_method),
),
base_address="api",
params=params,
options=options,
),
)
async def attach_async(
self,
payment_method: str,
params: "PaymentMethodAttachParams",
options: Optional["RequestOptions"] = None,
) -> "PaymentMethod":
"""
Attaches a PaymentMethod object to a Customer.
To attach a new PaymentMethod to a customer for future payments, we recommend you use a [SetupIntent](https://docs.stripe.com/docs/api/setup_intents)
or a PaymentIntent with [setup_future_usage](https://docs.stripe.com/docs/api/payment_intents/create#create_payment_intent-setup_future_usage).
These approaches will perform any necessary steps to set up the PaymentMethod for future payments. Using the /v1/payment_methods/:id/attach
endpoint without first using a SetupIntent or PaymentIntent with setup_future_usage does not optimize the PaymentMethod for
future use, which makes later declines and payment friction more likely.
See [Optimizing cards for future payments](https://docs.stripe.com/docs/payments/payment-intents#future-usage) for more information about setting up
future payments.
To use this PaymentMethod as the default for invoice or subscription payments,
set [invoice_settings.default_payment_method](https://docs.stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method),
on the Customer to the PaymentMethod's ID.
"""
return cast(
"PaymentMethod",
await self._request_async(
"post",
"/v1/payment_methods/{payment_method}/attach".format(
payment_method=sanitize_id(payment_method),
),
base_address="api",
params=params,
options=options,
),
)
def detach(
self,
payment_method: str,
params: Optional["PaymentMethodDetachParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "PaymentMethod":
"""
Detaches a PaymentMethod object from a Customer. After a PaymentMethod is detached, it can no longer be used for a payment or re-attached to a Customer.
"""
return cast(
"PaymentMethod",
self._request(
"post",
"/v1/payment_methods/{payment_method}/detach".format(
payment_method=sanitize_id(payment_method),
),
base_address="api",
params=params,
options=options,
),
)
async def detach_async(
self,
payment_method: str,
params: Optional["PaymentMethodDetachParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "PaymentMethod":
"""
Detaches a PaymentMethod object from a Customer. After a PaymentMethod is detached, it can no longer be used for a payment or re-attached to a Customer.
"""
return cast(
"PaymentMethod",
await self._request_async(
"post",
"/v1/payment_methods/{payment_method}/detach".format(
payment_method=sanitize_id(payment_method),
),
base_address="api",
params=params,
options=options,
),
)
|