Debian Codegraph @

stripe/issuing/_transaction.py

raw
1 # -*- coding: utf-8 -*-
2 # File generated from our OpenAPI spec
3 from stripe._expandable_field import ExpandableField
4 from stripe._list_object import ListObject
5 from stripe._listable_api_resource import ListableAPIResource
6 from stripe._stripe_object import StripeObject
7 from stripe._test_helpers import APIResourceTestHelpers
8 from stripe._updateable_api_resource import UpdateableAPIResource
9 from stripe._util import class_method_variant, sanitize_id
10 from typing import ClassVar, Dict, List, Optional, cast, overload
11 from typing_extensions import Literal, Type, Unpack, TYPE_CHECKING
12
13 if TYPE_CHECKING:
14 from stripe._balance_transaction import BalanceTransaction
15 from stripe.issuing._authorization import Authorization
16 from stripe.issuing._card import Card
17 from stripe.issuing._cardholder import Cardholder
18 from stripe.issuing._dispute import Dispute
19 from stripe.issuing._token import Token
20 from stripe.params.issuing._transaction_create_force_capture_params import (
21 TransactionCreateForceCaptureParams,
22 )
23 from stripe.params.issuing._transaction_create_unlinked_refund_params import (
24 TransactionCreateUnlinkedRefundParams,
25 )
26 from stripe.params.issuing._transaction_list_params import (
27 TransactionListParams,
28 )
29 from stripe.params.issuing._transaction_modify_params import (
30 TransactionModifyParams,
31 )
32 from stripe.params.issuing._transaction_refund_params import (
33 TransactionRefundParams,
34 )
35 from stripe.params.issuing._transaction_retrieve_params import (
36 TransactionRetrieveParams,
37 )
38
39
40 class Transaction(
41 ListableAPIResource["Transaction"],
42 UpdateableAPIResource["Transaction"],
43 ):
44 """
45 Any use of an [issued card](https://docs.stripe.com/issuing) that results in funds entering or leaving
46 your Stripe account, such as a completed purchase or refund, is represented by an Issuing
47 `Transaction` object.
48
49 Related guide: [Issued card transactions](https://docs.stripe.com/issuing/purchases/transactions)
50 """
51
52 OBJECT_NAME: ClassVar[Literal["issuing.transaction"]] = (
53 "issuing.transaction"
54 )
55
56 class AmountDetails(StripeObject):
57 atm_fee: Optional[int]
58 """
59 The fee charged by the ATM for the cash withdrawal.
60 """
61 cashback_amount: Optional[int]
62 """
63 The amount of cash requested by the cardholder.
64 """
65
66 class MerchantData(StripeObject):
67 category: str
68 """
69 A categorization of the seller's type of business. See our [merchant categories guide](https://docs.stripe.com/issuing/merchant-categories) for a list of possible values.
70 """
71 category_code: str
72 """
73 The merchant category code for the seller's business
74 """
75 city: Optional[str]
76 """
77 City where the seller is located
78 """
79 country: Optional[str]
80 """
81 Country where the seller is located
82 """
83 name: Optional[str]
84 """
85 Name of the seller
86 """
87 network_id: str
88 """
89 Identifier assigned to the seller by the card network. Different card networks may assign different network_id fields to the same merchant.
90 """
91 postal_code: Optional[str]
92 """
93 Postal code where the seller is located
94 """
95 state: Optional[str]
96 """
97 State where the seller is located
98 """
99 tax_id: Optional[str]
100 """
101 The seller's tax identification number. Currently populated for French merchants only.
102 """
103 terminal_id: Optional[str]
104 """
105 An ID assigned by the seller to the location of the sale.
106 """
107 url: Optional[str]
108 """
109 URL provided by the merchant on a 3DS request
110 """
111
112 class NetworkData(StripeObject):
113 authorization_code: Optional[str]
114 """
115 A code created by Stripe which is shared with the merchant to validate the authorization. This field will be populated if the authorization message was approved. The code typically starts with the letter "S", followed by a six-digit number. For example, "S498162". Please note that the code is not guaranteed to be unique across authorizations.
116 """
117 processing_date: Optional[str]
118 """
119 The date the transaction was processed by the card network. This can be different from the date the seller recorded the transaction depending on when the acquirer submits the transaction to the network.
120 """
121 transaction_id: Optional[str]
122 """
123 Unique identifier for the authorization assigned by the card network used to match subsequent messages, disputes, and transactions.
124 """
125
126 class PurchaseDetails(StripeObject):
127 class Fleet(StripeObject):
128 class CardholderPromptData(StripeObject):
129 driver_id: Optional[str]
130 """
131 Driver ID.
132 """
133 odometer: Optional[int]
134 """
135 Odometer reading.
136 """
137 unspecified_id: Optional[str]
138 """
139 An alphanumeric ID. This field is used when a vehicle ID, driver ID, or generic ID is entered by the cardholder, but the merchant or card network did not specify the prompt type.
140 """
141 user_id: Optional[str]
142 """
143 User ID.
144 """
145 vehicle_number: Optional[str]
146 """
147 Vehicle number.
148 """
149
150 class ReportedBreakdown(StripeObject):
151 class Fuel(StripeObject):
152 gross_amount_decimal: Optional[str]
153 """
154 Gross fuel amount that should equal Fuel Volume multipled by Fuel Unit Cost, inclusive of taxes.
155 """
156
157 class NonFuel(StripeObject):
158 gross_amount_decimal: Optional[str]
159 """
160 Gross non-fuel amount that should equal the sum of the line items, inclusive of taxes.
161 """
162
163 class Tax(StripeObject):
164 local_amount_decimal: Optional[str]
165 """
166 Amount of state or provincial Sales Tax included in the transaction amount. Null if not reported by merchant or not subject to tax.
167 """
168 national_amount_decimal: Optional[str]
169 """
170 Amount of national Sales Tax or VAT included in the transaction amount. Null if not reported by merchant or not subject to tax.
171 """
172
173 fuel: Optional[Fuel]
174 """
175 Breakdown of fuel portion of the purchase.
176 """
177 non_fuel: Optional[NonFuel]
178 """
179 Breakdown of non-fuel portion of the purchase.
180 """
181 tax: Optional[Tax]
182 """
183 Information about tax included in this transaction.
184 """
185 _inner_class_types = {
186 "fuel": Fuel,
187 "non_fuel": NonFuel,
188 "tax": Tax,
189 }
190
191 cardholder_prompt_data: Optional[CardholderPromptData]
192 """
193 Answers to prompts presented to cardholder at point of sale.
194 """
195 purchase_type: Optional[str]
196 """
197 The type of purchase. One of `fuel_purchase`, `non_fuel_purchase`, or `fuel_and_non_fuel_purchase`.
198 """
199 reported_breakdown: Optional[ReportedBreakdown]
200 """
201 More information about the total amount. This information is not guaranteed to be accurate as some merchants may provide unreliable data.
202 """
203 service_type: Optional[str]
204 """
205 The type of fuel service. One of `non_fuel_transaction`, `full_service`, or `self_service`.
206 """
207 _inner_class_types = {
208 "cardholder_prompt_data": CardholderPromptData,
209 "reported_breakdown": ReportedBreakdown,
210 }
211
212 class Flight(StripeObject):
213 class Segment(StripeObject):
214 arrival_airport_code: Optional[str]
215 """
216 The three-letter IATA airport code of the flight's destination.
217 """
218 carrier: Optional[str]
219 """
220 The airline carrier code.
221 """
222 departure_airport_code: Optional[str]
223 """
224 The three-letter IATA airport code that the flight departed from.
225 """
226 flight_number: Optional[str]
227 """
228 The flight number.
229 """
230 service_class: Optional[str]
231 """
232 The flight's service class.
233 """
234 stopover_allowed: Optional[bool]
235 """
236 Whether a stopover is allowed on this flight.
237 """
238
239 departure_at: Optional[int]
240 """
241 The time that the flight departed.
242 """
243 passenger_name: Optional[str]
244 """
245 The name of the passenger.
246 """
247 refundable: Optional[bool]
248 """
249 Whether the ticket is refundable.
250 """
251 segments: Optional[List[Segment]]
252 """
253 The legs of the trip.
254 """
255 travel_agency: Optional[str]
256 """
257 The travel agency that issued the ticket.
258 """
259 _inner_class_types = {"segments": Segment}
260
261 class Fuel(StripeObject):
262 industry_product_code: Optional[str]
263 """
264 [Conexxus Payment System Product Code](https://www.conexxus.org/conexxus-payment-system-product-codes) identifying the primary fuel product purchased.
265 """
266 quantity_decimal: Optional[str]
267 """
268 The quantity of `unit`s of fuel that was dispensed, represented as a decimal string with at most 12 decimal places.
269 """
270 type: str
271 """
272 The type of fuel that was purchased. One of `diesel`, `unleaded_plus`, `unleaded_regular`, `unleaded_super`, or `other`.
273 """
274 unit: str
275 """
276 The units for `quantity_decimal`. One of `charging_minute`, `imperial_gallon`, `kilogram`, `kilowatt_hour`, `liter`, `pound`, `us_gallon`, or `other`.
277 """
278 unit_cost_decimal: str
279 """
280 The cost in cents per each unit of fuel, represented as a decimal string with at most 12 decimal places.
281 """
282
283 class Lodging(StripeObject):
284 check_in_at: Optional[int]
285 """
286 The time of checking into the lodging.
287 """
288 nights: Optional[int]
289 """
290 The number of nights stayed at the lodging.
291 """
292
293 class Receipt(StripeObject):
294 description: Optional[str]
295 """
296 The description of the item. The maximum length of this field is 26 characters.
297 """
298 quantity: Optional[float]
299 """
300 The quantity of the item.
301 """
302 total: Optional[int]
303 """
304 The total for this line item in cents.
305 """
306 unit_cost: Optional[int]
307 """
308 The unit cost of the item in cents.
309 """
310
311 fleet: Optional[Fleet]
312 """
313 Fleet-specific information for transactions using Fleet cards.
314 """
315 flight: Optional[Flight]
316 """
317 Information about the flight that was purchased with this transaction.
318 """
319 fuel: Optional[Fuel]
320 """
321 Information about fuel that was purchased with this transaction.
322 """
323 lodging: Optional[Lodging]
324 """
325 Information about lodging that was purchased with this transaction.
326 """
327 receipt: Optional[List[Receipt]]
328 """
329 The line items in the purchase.
330 """
331 reference: Optional[str]
332 """
333 A merchant-specific order number.
334 """
335 _inner_class_types = {
336 "fleet": Fleet,
337 "flight": Flight,
338 "fuel": Fuel,
339 "lodging": Lodging,
340 "receipt": Receipt,
341 }
342
343 class Treasury(StripeObject):
344 received_credit: Optional[str]
345 """
346 The Treasury [ReceivedCredit](https://docs.stripe.com/api/treasury/received_credits) representing this Issuing transaction if it is a refund
347 """
348 received_debit: Optional[str]
349 """
350 The Treasury [ReceivedDebit](https://docs.stripe.com/api/treasury/received_debits) representing this Issuing transaction if it is a capture
351 """
352
353 amount: int
354 """
355 The transaction amount, which will be reflected in your balance. This amount is in your currency and in the [smallest currency unit](https://docs.stripe.com/currencies#zero-decimal).
356 """
357 amount_details: Optional[AmountDetails]
358 """
359 Detailed breakdown of amount components. These amounts are denominated in `currency` and in the [smallest currency unit](https://docs.stripe.com/currencies#zero-decimal).
360 """
361 authorization: Optional[ExpandableField["Authorization"]]
362 """
363 The `Authorization` object that led to this transaction.
364 """
365 balance_transaction: Optional[ExpandableField["BalanceTransaction"]]
366 """
367 ID of the [balance transaction](https://docs.stripe.com/api/balance_transactions) associated with this transaction.
368 """
369 card: ExpandableField["Card"]
370 """
371 The card used to make this transaction.
372 """
373 cardholder: Optional[ExpandableField["Cardholder"]]
374 """
375 The cardholder to whom this transaction belongs.
376 """
377 created: int
378 """
379 Time at which the object was created. Measured in seconds since the Unix epoch.
380 """
381 currency: str
382 """
383 Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
384 """
385 dispute: Optional[ExpandableField["Dispute"]]
386 """
387 If you've disputed the transaction, the ID of the dispute.
388 """
389 id: str
390 """
391 Unique identifier for the object.
392 """
393 livemode: bool
394 """
395 Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
396 """
397 merchant_amount: int
398 """
399 The amount that the merchant will receive, denominated in `merchant_currency` and in the [smallest currency unit](https://docs.stripe.com/currencies#zero-decimal). It will be different from `amount` if the merchant is taking payment in a different currency.
400 """
401 merchant_currency: str
402 """
403 The currency with which the merchant is taking payment.
404 """
405 merchant_data: MerchantData
406 metadata: Dict[str, str]
407 """
408 Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
409 """
410 network_data: Optional[NetworkData]
411 """
412 Details about the transaction, such as processing dates, set by the card network.
413 """
414 object: Literal["issuing.transaction"]
415 """
416 String representing the object's type. Objects of the same type share the same value.
417 """
418 purchase_details: Optional[PurchaseDetails]
419 """
420 Additional purchase information that is optionally provided by the merchant.
421 """
422 token: Optional[ExpandableField["Token"]]
423 """
424 [Token](https://docs.stripe.com/api/issuing/tokens/object) object used for this transaction. If a network token was not used for this transaction, this field will be null.
425 """
426 treasury: Optional[Treasury]
427 """
428 [Treasury](https://docs.stripe.com/api/treasury) details related to this transaction if it was created on a [FinancialAccount](/docs/api/treasury/financial_accounts
429 """
430 type: Literal["capture", "refund"]
431 """
432 The nature of the transaction.
433 """
434 wallet: Optional[Literal["apple_pay", "google_pay", "samsung_pay"]]
435 """
436 The digital wallet used for this transaction. One of `apple_pay`, `google_pay`, or `samsung_pay`.
437 """
438
439 @classmethod
440 def list(
441 cls, **params: Unpack["TransactionListParams"]
442 ) -> ListObject["Transaction"]:
443 """
444 Returns a list of Issuing Transaction objects. The objects are sorted in descending order by creation date, with the most recently created object appearing first.
445 """
446 result = cls._static_request(
447 "get",
448 cls.class_url(),
449 params=params,
450 )
451 if not isinstance(result, ListObject):
452 raise TypeError(
453 "Expected list object from API, got %s"
454 % (type(result).__name__)
455 )
456
457 return result
458
459 @classmethod
460 async def list_async(
461 cls, **params: Unpack["TransactionListParams"]
462 ) -> ListObject["Transaction"]:
463 """
464 Returns a list of Issuing Transaction objects. The objects are sorted in descending order by creation date, with the most recently created object appearing first.
465 """
466 result = await cls._static_request_async(
467 "get",
468 cls.class_url(),
469 params=params,
470 )
471 if not isinstance(result, ListObject):
472 raise TypeError(
473 "Expected list object from API, got %s"
474 % (type(result).__name__)
475 )
476
477 return result
478
479 @classmethod
480 def modify(
481 cls, id: str, **params: Unpack["TransactionModifyParams"]
482 ) -> "Transaction":
483 """
484 Updates the specified Issuing Transaction object by setting the values of the parameters passed. Any parameters not provided will be left unchanged.
485 """
486 url = "%s/%s" % (cls.class_url(), sanitize_id(id))
487 return cast(
488 "Transaction",
489 cls._static_request(
490 "post",
491 url,
492 params=params,
493 ),
494 )
495
496 @classmethod
497 async def modify_async(
498 cls, id: str, **params: Unpack["TransactionModifyParams"]
499 ) -> "Transaction":
500 """
501 Updates the specified Issuing Transaction object by setting the values of the parameters passed. Any parameters not provided will be left unchanged.
502 """
503 url = "%s/%s" % (cls.class_url(), sanitize_id(id))
504 return cast(
505 "Transaction",
506 await cls._static_request_async(
507 "post",
508 url,
509 params=params,
510 ),
511 )
512
513 @classmethod
514 def retrieve(
515 cls, id: str, **params: Unpack["TransactionRetrieveParams"]
516 ) -> "Transaction":
517 """
518 Retrieves an Issuing Transaction object.
519 """
520 instance = cls(id, **params)
521 instance.refresh()
522 return instance
523
524 @classmethod
525 async def retrieve_async(
526 cls, id: str, **params: Unpack["TransactionRetrieveParams"]
527 ) -> "Transaction":
528 """
529 Retrieves an Issuing Transaction object.
530 """
531 instance = cls(id, **params)
532 await instance.refresh_async()
533 return instance
534
535 class TestHelpers(APIResourceTestHelpers["Transaction"]):
536 _resource_cls: Type["Transaction"]
537
538 @classmethod
539 def create_force_capture(
540 cls, **params: Unpack["TransactionCreateForceCaptureParams"]
541 ) -> "Transaction":
542 """
543 Allows the user to capture an arbitrary amount, also known as a forced capture.
544 """
545 return cast(
546 "Transaction",
547 cls._static_request(
548 "post",
549 "/v1/test_helpers/issuing/transactions/create_force_capture",
550 params=params,
551 ),
552 )
553
554 @classmethod
555 async def create_force_capture_async(
556 cls, **params: Unpack["TransactionCreateForceCaptureParams"]
557 ) -> "Transaction":
558 """
559 Allows the user to capture an arbitrary amount, also known as a forced capture.
560 """
561 return cast(
562 "Transaction",
563 await cls._static_request_async(
564 "post",
565 "/v1/test_helpers/issuing/transactions/create_force_capture",
566 params=params,
567 ),
568 )
569
570 @classmethod
571 def create_unlinked_refund(
572 cls, **params: Unpack["TransactionCreateUnlinkedRefundParams"]
573 ) -> "Transaction":
574 """
575 Allows the user to refund an arbitrary amount, also known as a unlinked refund.
576 """
577 return cast(
578 "Transaction",
579 cls._static_request(
580 "post",
581 "/v1/test_helpers/issuing/transactions/create_unlinked_refund",
582 params=params,
583 ),
584 )
585
586 @classmethod
587 async def create_unlinked_refund_async(
588 cls, **params: Unpack["TransactionCreateUnlinkedRefundParams"]
589 ) -> "Transaction":
590 """
591 Allows the user to refund an arbitrary amount, also known as a unlinked refund.
592 """
593 return cast(
594 "Transaction",
595 await cls._static_request_async(
596 "post",
597 "/v1/test_helpers/issuing/transactions/create_unlinked_refund",
598 params=params,
599 ),
600 )
601
602 @classmethod
603 def _cls_refund(
604 cls, transaction: str, **params: Unpack["TransactionRefundParams"]
605 ) -> "Transaction":
606 """
607 Refund a test-mode Transaction.
608 """
609 return cast(
610 "Transaction",
611 cls._static_request(
612 "post",
613 "/v1/test_helpers/issuing/transactions/{transaction}/refund".format(
614 transaction=sanitize_id(transaction)
615 ),
616 params=params,
617 ),
618 )
619
620 @overload
621 @staticmethod
622 def refund(
623 transaction: str, **params: Unpack["TransactionRefundParams"]
624 ) -> "Transaction":
625 """
626 Refund a test-mode Transaction.
627 """
628 ...
629
630 @overload
631 def refund(
632 self, **params: Unpack["TransactionRefundParams"]
633 ) -> "Transaction":
634 """
635 Refund a test-mode Transaction.
636 """
637 ...
638
639 @class_method_variant("_cls_refund")
640 def refund( # pyright: ignore[reportGeneralTypeIssues]
641 self, **params: Unpack["TransactionRefundParams"]
642 ) -> "Transaction":
643 """
644 Refund a test-mode Transaction.
645 """
646 return cast(
647 "Transaction",
648 self.resource._request(
649 "post",
650 "/v1/test_helpers/issuing/transactions/{transaction}/refund".format(
651 transaction=sanitize_id(self.resource.get("id"))
652 ),
653 params=params,
654 ),
655 )
656
657 @classmethod
658 async def _cls_refund_async(
659 cls, transaction: str, **params: Unpack["TransactionRefundParams"]
660 ) -> "Transaction":
661 """
662 Refund a test-mode Transaction.
663 """
664 return cast(
665 "Transaction",
666 await cls._static_request_async(
667 "post",
668 "/v1/test_helpers/issuing/transactions/{transaction}/refund".format(
669 transaction=sanitize_id(transaction)
670 ),
671 params=params,
672 ),
673 )
674
675 @overload
676 @staticmethod
677 async def refund_async(
678 transaction: str, **params: Unpack["TransactionRefundParams"]
679 ) -> "Transaction":
680 """
681 Refund a test-mode Transaction.
682 """
683 ...
684
685 @overload
686 async def refund_async(
687 self, **params: Unpack["TransactionRefundParams"]
688 ) -> "Transaction":
689 """
690 Refund a test-mode Transaction.
691 """
692 ...
693
694 @class_method_variant("_cls_refund_async")
695 async def refund_async( # pyright: ignore[reportGeneralTypeIssues]
696 self, **params: Unpack["TransactionRefundParams"]
697 ) -> "Transaction":
698 """
699 Refund a test-mode Transaction.
700 """
701 return cast(
702 "Transaction",
703 await self.resource._request_async(
704 "post",
705 "/v1/test_helpers/issuing/transactions/{transaction}/refund".format(
706 transaction=sanitize_id(self.resource.get("id"))
707 ),
708 params=params,
709 ),
710 )
711
712 @property
713 def test_helpers(self):
714 return self.TestHelpers(self)
715
716 _inner_class_types = {
717 "amount_details": AmountDetails,
718 "merchant_data": MerchantData,
719 "network_data": NetworkData,
720 "purchase_details": PurchaseDetails,
721 "treasury": Treasury,
722 }
723
724
725 Transaction.TestHelpers._resource_cls = Transaction