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 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
|
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._createable_api_resource import CreateableAPIResource
from stripe._expandable_field import ExpandableField
from stripe._list_object import ListObject
from stripe._listable_api_resource import ListableAPIResource
from stripe._request_options import RequestOptions
from stripe._stripe_object import StripeObject
from stripe._test_helpers import APIResourceTestHelpers
from stripe._updateable_api_resource import UpdateableAPIResource
from stripe._util import class_method_variant, sanitize_id
from typing import ClassVar, Dict, List, Optional, cast, overload
from typing_extensions import (
Literal,
NotRequired,
Type,
TypedDict,
Unpack,
TYPE_CHECKING,
)
if TYPE_CHECKING:
from stripe._balance_transaction import BalanceTransaction
from stripe._charge import Charge
from stripe._payment_intent import PaymentIntent
from stripe._reversal import Reversal
class Refund(
CreateableAPIResource["Refund"],
ListableAPIResource["Refund"],
UpdateableAPIResource["Refund"],
):
"""
Refund objects allow you to refund a previously created charge that isn't
refunded yet. Funds are refunded to the credit or debit card that's
initially charged.
Related guide: [Refunds](https://stripe.com/docs/refunds)
"""
OBJECT_NAME: ClassVar[Literal["refund"]] = "refund"
class DestinationDetails(StripeObject):
class Affirm(StripeObject):
pass
class AfterpayClearpay(StripeObject):
pass
class Alipay(StripeObject):
pass
class Alma(StripeObject):
pass
class AmazonPay(StripeObject):
pass
class AuBankTransfer(StripeObject):
pass
class Blik(StripeObject):
network_decline_code: Optional[str]
"""
For refunds declined by the network, a decline code provided by the network which indicates the reason the refund failed.
"""
reference: Optional[str]
"""
The reference assigned to the refund.
"""
reference_status: Optional[str]
"""
Status of the reference on the refund. This can be `pending`, `available` or `unavailable`.
"""
class BrBankTransfer(StripeObject):
reference: Optional[str]
"""
The reference assigned to the refund.
"""
reference_status: Optional[str]
"""
Status of the reference on the refund. This can be `pending`, `available` or `unavailable`.
"""
class Card(StripeObject):
reference: Optional[str]
"""
Value of the reference number assigned to the refund.
"""
reference_status: Optional[str]
"""
Status of the reference number on the refund. This can be `pending`, `available` or `unavailable`.
"""
reference_type: Optional[str]
"""
Type of the reference number assigned to the refund.
"""
type: Literal["pending", "refund", "reversal"]
"""
The type of refund. This can be `refund`, `reversal`, or `pending`.
"""
class Cashapp(StripeObject):
pass
class CustomerCashBalance(StripeObject):
pass
class Eps(StripeObject):
pass
class EuBankTransfer(StripeObject):
reference: Optional[str]
"""
The reference assigned to the refund.
"""
reference_status: Optional[str]
"""
Status of the reference on the refund. This can be `pending`, `available` or `unavailable`.
"""
class GbBankTransfer(StripeObject):
reference: Optional[str]
"""
The reference assigned to the refund.
"""
reference_status: Optional[str]
"""
Status of the reference on the refund. This can be `pending`, `available` or `unavailable`.
"""
class Giropay(StripeObject):
pass
class Grabpay(StripeObject):
pass
class JpBankTransfer(StripeObject):
reference: Optional[str]
"""
The reference assigned to the refund.
"""
reference_status: Optional[str]
"""
Status of the reference on the refund. This can be `pending`, `available` or `unavailable`.
"""
class Klarna(StripeObject):
pass
class Multibanco(StripeObject):
reference: Optional[str]
"""
The reference assigned to the refund.
"""
reference_status: Optional[str]
"""
Status of the reference on the refund. This can be `pending`, `available` or `unavailable`.
"""
class MxBankTransfer(StripeObject):
reference: Optional[str]
"""
The reference assigned to the refund.
"""
reference_status: Optional[str]
"""
Status of the reference on the refund. This can be `pending`, `available` or `unavailable`.
"""
class NzBankTransfer(StripeObject):
pass
class P24(StripeObject):
reference: Optional[str]
"""
The reference assigned to the refund.
"""
reference_status: Optional[str]
"""
Status of the reference on the refund. This can be `pending`, `available` or `unavailable`.
"""
class Paynow(StripeObject):
pass
class Paypal(StripeObject):
pass
class Pix(StripeObject):
pass
class Revolut(StripeObject):
pass
class Sofort(StripeObject):
pass
class Swish(StripeObject):
network_decline_code: Optional[str]
"""
For refunds declined by the network, a decline code provided by the network which indicates the reason the refund failed.
"""
reference: Optional[str]
"""
The reference assigned to the refund.
"""
reference_status: Optional[str]
"""
Status of the reference on the refund. This can be `pending`, `available` or `unavailable`.
"""
class ThBankTransfer(StripeObject):
reference: Optional[str]
"""
The reference assigned to the refund.
"""
reference_status: Optional[str]
"""
Status of the reference on the refund. This can be `pending`, `available` or `unavailable`.
"""
class UsBankTransfer(StripeObject):
reference: Optional[str]
"""
The reference assigned to the refund.
"""
reference_status: Optional[str]
"""
Status of the reference on the refund. This can be `pending`, `available` or `unavailable`.
"""
class WechatPay(StripeObject):
pass
class Zip(StripeObject):
pass
affirm: Optional[Affirm]
afterpay_clearpay: Optional[AfterpayClearpay]
alipay: Optional[Alipay]
alma: Optional[Alma]
amazon_pay: Optional[AmazonPay]
au_bank_transfer: Optional[AuBankTransfer]
blik: Optional[Blik]
br_bank_transfer: Optional[BrBankTransfer]
card: Optional[Card]
cashapp: Optional[Cashapp]
customer_cash_balance: Optional[CustomerCashBalance]
eps: Optional[Eps]
eu_bank_transfer: Optional[EuBankTransfer]
gb_bank_transfer: Optional[GbBankTransfer]
giropay: Optional[Giropay]
grabpay: Optional[Grabpay]
jp_bank_transfer: Optional[JpBankTransfer]
klarna: Optional[Klarna]
multibanco: Optional[Multibanco]
mx_bank_transfer: Optional[MxBankTransfer]
nz_bank_transfer: Optional[NzBankTransfer]
p24: Optional[P24]
paynow: Optional[Paynow]
paypal: Optional[Paypal]
pix: Optional[Pix]
revolut: Optional[Revolut]
sofort: Optional[Sofort]
swish: Optional[Swish]
th_bank_transfer: Optional[ThBankTransfer]
type: str
"""
The type of transaction-specific details of the payment method used in the refund (e.g., `card`). An additional hash is included on `destination_details` with a name matching this value. It contains information specific to the refund transaction.
"""
us_bank_transfer: Optional[UsBankTransfer]
wechat_pay: Optional[WechatPay]
zip: Optional[Zip]
_inner_class_types = {
"affirm": Affirm,
"afterpay_clearpay": AfterpayClearpay,
"alipay": Alipay,
"alma": Alma,
"amazon_pay": AmazonPay,
"au_bank_transfer": AuBankTransfer,
"blik": Blik,
"br_bank_transfer": BrBankTransfer,
"card": Card,
"cashapp": Cashapp,
"customer_cash_balance": CustomerCashBalance,
"eps": Eps,
"eu_bank_transfer": EuBankTransfer,
"gb_bank_transfer": GbBankTransfer,
"giropay": Giropay,
"grabpay": Grabpay,
"jp_bank_transfer": JpBankTransfer,
"klarna": Klarna,
"multibanco": Multibanco,
"mx_bank_transfer": MxBankTransfer,
"nz_bank_transfer": NzBankTransfer,
"p24": P24,
"paynow": Paynow,
"paypal": Paypal,
"pix": Pix,
"revolut": Revolut,
"sofort": Sofort,
"swish": Swish,
"th_bank_transfer": ThBankTransfer,
"us_bank_transfer": UsBankTransfer,
"wechat_pay": WechatPay,
"zip": Zip,
}
class NextAction(StripeObject):
class DisplayDetails(StripeObject):
class EmailSent(StripeObject):
email_sent_at: int
"""
The timestamp when the email was sent.
"""
email_sent_to: str
"""
The recipient's email address.
"""
email_sent: EmailSent
expires_at: int
"""
The expiry timestamp.
"""
_inner_class_types = {"email_sent": EmailSent}
display_details: Optional[DisplayDetails]
type: str
"""
Type of the next action to perform.
"""
_inner_class_types = {"display_details": DisplayDetails}
class PresentmentDetails(StripeObject):
presentment_amount: int
"""
Amount intended to be collected by this payment, denominated in presentment_currency.
"""
presentment_currency: str
"""
Currency presented to the customer during payment.
"""
class CancelParams(RequestOptions):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
class CreateParams(RequestOptions):
amount: NotRequired[int]
charge: NotRequired[str]
"""
The identifier of the charge to refund.
"""
currency: NotRequired[str]
"""
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).
"""
customer: NotRequired[str]
"""
Customer whose customer balance to refund from.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
instructions_email: NotRequired[str]
"""
For payment methods without native refund support (e.g., Konbini, PromptPay), use this email from the customer to receive refund instructions.
"""
metadata: NotRequired["Literal['']|Dict[str, str]"]
"""
Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`.
"""
origin: NotRequired[Literal["customer_balance"]]
"""
Origin of the refund
"""
payment_intent: NotRequired[str]
"""
The identifier of the PaymentIntent to refund.
"""
reason: NotRequired[
Literal["duplicate", "fraudulent", "requested_by_customer"]
]
"""
String indicating the reason for the refund. If set, possible values are `duplicate`, `fraudulent`, and `requested_by_customer`. If you believe the charge to be fraudulent, specifying `fraudulent` as the reason will add the associated card and email to your [block lists](https://stripe.com/docs/radar/lists), and will also help us improve our fraud detection algorithms.
"""
refund_application_fee: NotRequired[bool]
"""
Boolean indicating whether the application fee should be refunded when refunding this charge. If a full charge refund is given, the full application fee will be refunded. Otherwise, the application fee will be refunded in an amount proportional to the amount of the charge refunded. An application fee can be refunded only by the application that created the charge.
"""
reverse_transfer: NotRequired[bool]
"""
Boolean indicating whether the transfer should be reversed when refunding this charge. The transfer will be reversed proportionally to the amount being refunded (either the entire or partial amount).
A transfer can be reversed only by the application that created the charge.
"""
class ExpireParams(RequestOptions):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
class ListParams(RequestOptions):
charge: NotRequired[str]
"""
Only return refunds for the charge specified by this charge ID.
"""
created: NotRequired["Refund.ListParamsCreated|int"]
"""
Only return refunds that were created during the given date interval.
"""
ending_before: NotRequired[str]
"""
A cursor for use in pagination. `ending_before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
limit: NotRequired[int]
"""
A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
"""
payment_intent: NotRequired[str]
"""
Only return refunds for the PaymentIntent specified by this ID.
"""
starting_after: NotRequired[str]
"""
A cursor for use in pagination. `starting_after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
"""
class ListParamsCreated(TypedDict):
gt: NotRequired[int]
"""
Minimum value to filter by (exclusive)
"""
gte: NotRequired[int]
"""
Minimum value to filter by (inclusive)
"""
lt: NotRequired[int]
"""
Maximum value to filter by (exclusive)
"""
lte: NotRequired[int]
"""
Maximum value to filter by (inclusive)
"""
class ModifyParams(RequestOptions):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
metadata: NotRequired["Literal['']|Dict[str, str]"]
"""
Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`.
"""
class RetrieveParams(RequestOptions):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
amount: int
"""
Amount, in cents (or local equivalent).
"""
balance_transaction: Optional[ExpandableField["BalanceTransaction"]]
"""
Balance transaction that describes the impact on your account balance.
"""
charge: Optional[ExpandableField["Charge"]]
"""
ID of the charge that's refunded.
"""
created: int
"""
Time at which the object was created. Measured in seconds since the Unix epoch.
"""
currency: str
"""
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).
"""
description: Optional[str]
"""
An arbitrary string attached to the object. You can use this for displaying to users (available on non-card refunds only).
"""
destination_details: Optional[DestinationDetails]
failure_balance_transaction: Optional[
ExpandableField["BalanceTransaction"]
]
"""
After the refund fails, this balance transaction describes the adjustment made on your account balance that reverses the initial balance transaction.
"""
failure_reason: Optional[str]
"""
Provides the reason for the refund failure. Possible values are: `lost_or_stolen_card`, `expired_or_canceled_card`, `charge_for_pending_refund_disputed`, `insufficient_funds`, `declined`, `merchant_request`, or `unknown`.
"""
id: str
"""
Unique identifier for the object.
"""
instructions_email: Optional[str]
"""
For payment methods without native refund support (for example, Konbini, PromptPay), provide an email address for the customer to receive refund instructions.
"""
metadata: Optional[Dict[str, str]]
"""
Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
"""
next_action: Optional[NextAction]
object: Literal["refund"]
"""
String representing the object's type. Objects of the same type share the same value.
"""
payment_intent: Optional[ExpandableField["PaymentIntent"]]
"""
ID of the PaymentIntent that's refunded.
"""
presentment_details: Optional[PresentmentDetails]
reason: Optional[
Literal[
"duplicate",
"expired_uncaptured_charge",
"fraudulent",
"requested_by_customer",
]
]
"""
Reason for the refund, which is either user-provided (`duplicate`, `fraudulent`, or `requested_by_customer`) or generated by Stripe internally (`expired_uncaptured_charge`).
"""
receipt_number: Optional[str]
"""
This is the transaction number that appears on email receipts sent for this refund.
"""
source_transfer_reversal: Optional[ExpandableField["Reversal"]]
"""
The transfer reversal that's associated with the refund. Only present if the charge came from another Stripe account.
"""
status: Optional[str]
"""
Status of the refund. This can be `pending`, `requires_action`, `succeeded`, `failed`, or `canceled`. Learn more about [failed refunds](https://stripe.com/docs/refunds#failed-refunds).
"""
transfer_reversal: Optional[ExpandableField["Reversal"]]
"""
This refers to the transfer reversal object if the accompanying transfer reverses. This is only applicable if the charge was created using the destination parameter.
"""
@classmethod
def _cls_cancel(
cls, refund: str, **params: Unpack["Refund.CancelParams"]
) -> "Refund":
"""
Cancels a refund with a status of requires_action.
You can't cancel refunds in other states. Only refunds for payment methods that require customer action can enter the requires_action state.
"""
return cast(
"Refund",
cls._static_request(
"post",
"/v1/refunds/{refund}/cancel".format(
refund=sanitize_id(refund)
),
params=params,
),
)
@overload
@staticmethod
def cancel(
refund: str, **params: Unpack["Refund.CancelParams"]
) -> "Refund":
"""
Cancels a refund with a status of requires_action.
You can't cancel refunds in other states. Only refunds for payment methods that require customer action can enter the requires_action state.
"""
...
@overload
def cancel(self, **params: Unpack["Refund.CancelParams"]) -> "Refund":
"""
Cancels a refund with a status of requires_action.
You can't cancel refunds in other states. Only refunds for payment methods that require customer action can enter the requires_action state.
"""
...
@class_method_variant("_cls_cancel")
def cancel( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["Refund.CancelParams"]
) -> "Refund":
"""
Cancels a refund with a status of requires_action.
You can't cancel refunds in other states. Only refunds for payment methods that require customer action can enter the requires_action state.
"""
return cast(
"Refund",
self._request(
"post",
"/v1/refunds/{refund}/cancel".format(
refund=sanitize_id(self.get("id"))
),
params=params,
),
)
@classmethod
async def _cls_cancel_async(
cls, refund: str, **params: Unpack["Refund.CancelParams"]
) -> "Refund":
"""
Cancels a refund with a status of requires_action.
You can't cancel refunds in other states. Only refunds for payment methods that require customer action can enter the requires_action state.
"""
return cast(
"Refund",
await cls._static_request_async(
"post",
"/v1/refunds/{refund}/cancel".format(
refund=sanitize_id(refund)
),
params=params,
),
)
@overload
@staticmethod
async def cancel_async(
refund: str, **params: Unpack["Refund.CancelParams"]
) -> "Refund":
"""
Cancels a refund with a status of requires_action.
You can't cancel refunds in other states. Only refunds for payment methods that require customer action can enter the requires_action state.
"""
...
@overload
async def cancel_async(
self, **params: Unpack["Refund.CancelParams"]
) -> "Refund":
"""
Cancels a refund with a status of requires_action.
You can't cancel refunds in other states. Only refunds for payment methods that require customer action can enter the requires_action state.
"""
...
@class_method_variant("_cls_cancel_async")
async def cancel_async( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["Refund.CancelParams"]
) -> "Refund":
"""
Cancels a refund with a status of requires_action.
You can't cancel refunds in other states. Only refunds for payment methods that require customer action can enter the requires_action state.
"""
return cast(
"Refund",
await self._request_async(
"post",
"/v1/refunds/{refund}/cancel".format(
refund=sanitize_id(self.get("id"))
),
params=params,
),
)
@classmethod
def create(cls, **params: Unpack["Refund.CreateParams"]) -> "Refund":
"""
When you create a new refund, you must specify a Charge or a PaymentIntent object on which to create it.
Creating a new refund will refund a charge that has previously been created but not yet refunded.
Funds will be refunded to the credit or debit card that was originally charged.
You can optionally refund only part of a charge.
You can do so multiple times, until the entire charge has been refunded.
Once entirely refunded, a charge can't be refunded again.
This method will raise an error when called on an already-refunded charge,
or when trying to refund more money than is left on a charge.
"""
return cast(
"Refund",
cls._static_request(
"post",
cls.class_url(),
params=params,
),
)
@classmethod
async def create_async(
cls, **params: Unpack["Refund.CreateParams"]
) -> "Refund":
"""
When you create a new refund, you must specify a Charge or a PaymentIntent object on which to create it.
Creating a new refund will refund a charge that has previously been created but not yet refunded.
Funds will be refunded to the credit or debit card that was originally charged.
You can optionally refund only part of a charge.
You can do so multiple times, until the entire charge has been refunded.
Once entirely refunded, a charge can't be refunded again.
This method will raise an error when called on an already-refunded charge,
or when trying to refund more money than is left on a charge.
"""
return cast(
"Refund",
await cls._static_request_async(
"post",
cls.class_url(),
params=params,
),
)
@classmethod
def list(
cls, **params: Unpack["Refund.ListParams"]
) -> ListObject["Refund"]:
"""
Returns a list of all refunds you created. We return the refunds in sorted order, with the most recent refunds appearing first. The 10 most recent refunds are always available by default on the Charge object.
"""
result = cls._static_request(
"get",
cls.class_url(),
params=params,
)
if not isinstance(result, ListObject):
raise TypeError(
"Expected list object from API, got %s"
% (type(result).__name__)
)
return result
@classmethod
async def list_async(
cls, **params: Unpack["Refund.ListParams"]
) -> ListObject["Refund"]:
"""
Returns a list of all refunds you created. We return the refunds in sorted order, with the most recent refunds appearing first. The 10 most recent refunds are always available by default on the Charge object.
"""
result = await cls._static_request_async(
"get",
cls.class_url(),
params=params,
)
if not isinstance(result, ListObject):
raise TypeError(
"Expected list object from API, got %s"
% (type(result).__name__)
)
return result
@classmethod
def modify(
cls, id: str, **params: Unpack["Refund.ModifyParams"]
) -> "Refund":
"""
Updates the refund that you specify by setting the values of the passed parameters. Any parameters that you don't provide remain unchanged.
This request only accepts metadata as an argument.
"""
url = "%s/%s" % (cls.class_url(), sanitize_id(id))
return cast(
"Refund",
cls._static_request(
"post",
url,
params=params,
),
)
@classmethod
async def modify_async(
cls, id: str, **params: Unpack["Refund.ModifyParams"]
) -> "Refund":
"""
Updates the refund that you specify by setting the values of the passed parameters. Any parameters that you don't provide remain unchanged.
This request only accepts metadata as an argument.
"""
url = "%s/%s" % (cls.class_url(), sanitize_id(id))
return cast(
"Refund",
await cls._static_request_async(
"post",
url,
params=params,
),
)
@classmethod
def retrieve(
cls, id: str, **params: Unpack["Refund.RetrieveParams"]
) -> "Refund":
"""
Retrieves the details of an existing refund.
"""
instance = cls(id, **params)
instance.refresh()
return instance
@classmethod
async def retrieve_async(
cls, id: str, **params: Unpack["Refund.RetrieveParams"]
) -> "Refund":
"""
Retrieves the details of an existing refund.
"""
instance = cls(id, **params)
await instance.refresh_async()
return instance
class TestHelpers(APIResourceTestHelpers["Refund"]):
_resource_cls: Type["Refund"]
@classmethod
def _cls_expire(
cls, refund: str, **params: Unpack["Refund.ExpireParams"]
) -> "Refund":
"""
Expire a refund with a status of requires_action.
"""
return cast(
"Refund",
cls._static_request(
"post",
"/v1/test_helpers/refunds/{refund}/expire".format(
refund=sanitize_id(refund)
),
params=params,
),
)
@overload
@staticmethod
def expire(
refund: str, **params: Unpack["Refund.ExpireParams"]
) -> "Refund":
"""
Expire a refund with a status of requires_action.
"""
...
@overload
def expire(self, **params: Unpack["Refund.ExpireParams"]) -> "Refund":
"""
Expire a refund with a status of requires_action.
"""
...
@class_method_variant("_cls_expire")
def expire( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["Refund.ExpireParams"]
) -> "Refund":
"""
Expire a refund with a status of requires_action.
"""
return cast(
"Refund",
self.resource._request(
"post",
"/v1/test_helpers/refunds/{refund}/expire".format(
refund=sanitize_id(self.resource.get("id"))
),
params=params,
),
)
@classmethod
async def _cls_expire_async(
cls, refund: str, **params: Unpack["Refund.ExpireParams"]
) -> "Refund":
"""
Expire a refund with a status of requires_action.
"""
return cast(
"Refund",
await cls._static_request_async(
"post",
"/v1/test_helpers/refunds/{refund}/expire".format(
refund=sanitize_id(refund)
),
params=params,
),
)
@overload
@staticmethod
async def expire_async(
refund: str, **params: Unpack["Refund.ExpireParams"]
) -> "Refund":
"""
Expire a refund with a status of requires_action.
"""
...
@overload
async def expire_async(
self, **params: Unpack["Refund.ExpireParams"]
) -> "Refund":
"""
Expire a refund with a status of requires_action.
"""
...
@class_method_variant("_cls_expire_async")
async def expire_async( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["Refund.ExpireParams"]
) -> "Refund":
"""
Expire a refund with a status of requires_action.
"""
return cast(
"Refund",
await self.resource._request_async(
"post",
"/v1/test_helpers/refunds/{refund}/expire".format(
refund=sanitize_id(self.resource.get("id"))
),
params=params,
),
)
@property
def test_helpers(self):
return self.TestHelpers(self)
_inner_class_types = {
"destination_details": DestinationDetails,
"next_action": NextAction,
"presentment_details": PresentmentDetails,
}
Refund.TestHelpers._resource_cls = Refund
|