diff --git a/discord/flags.py b/discord/flags.py index 9d754db4b..ab168e4d1 100644 --- a/discord/flags.py +++ b/discord/flags.py @@ -1678,6 +1678,13 @@ class PaymentFlags(BaseFlags): """:class:`bool`: Returns ``True`` if the payment is for a gift.""" return 1 << 0 + # TODO: Assumption + + @flag_value + def user_refunded(self): + """:class:`bool`: Returns ``True`` if the payment has been self-refunded""" + return 1 << 2 + @flag_value def preorder(self): """:class:`bool`: Returns ``True`` if the payment is a preorder.""" diff --git a/discord/http.py b/discord/http.py index fec553afc..efec0091f 100644 --- a/discord/http.py +++ b/discord/http.py @@ -636,10 +636,9 @@ class HTTPClient: ) ) - proxy = self.proxy proxy_auth = self.proxy_auth - + self.super_properties, self.encoded_super_properties = sp, _ = await utils._get_info(session, proxy, proxy_auth) _log.info('Found user agent %s, build number %s.', sp.get('browser_user_agent'), sp.get('client_build_number')) @@ -4219,7 +4218,7 @@ class HTTPClient: def void_payment(self, payment_id: Snowflake) -> Response[None]: return self.request(Route('POST', '/users/@me/billing/payments/{payment_id}/void', payment_id=payment_id)) - def refund_payment(self, payment_id: Snowflake, reason: Optional[int] = None) -> Response[None]: + def refund_payment(self, payment_id: Snowflake, reason: Optional[int] = None) -> Response[payments.Payment]: payload = {'reason': reason} return self.request( Route('POST', '/users/@me/billing/payments/{payment_id}/refund', payment_id=payment_id), json=payload diff --git a/discord/payments.py b/discord/payments.py index a9a7a8364..505429b8f 100644 --- a/discord/payments.py +++ b/discord/payments.py @@ -144,6 +144,7 @@ class Payment(Hashable): 'invoice_url', 'refund_invoices_urls', 'refund_disqualification_reasons', + '_refundable', '_flags', '_state', ) @@ -177,6 +178,7 @@ class Payment(Hashable): self.refund_disqualification_reasons: List[RefundDisqualificationReason] = [ try_enum(RefundDisqualificationReason, r) for r in data.get('premium_refund_disqualification_reasons', []) ] + self._refundable = data.get('premium_refund_disqualification_reasons') == [] # Hack for better DUX self._flags: int = data.get('flags', 0) # The subscription object does not include the payment source ID @@ -211,6 +213,13 @@ class Payment(Hashable): """:class:`bool`: Whether the payment was made externally.""" return self.payment_gateway in (PaymentGateway.apple, PaymentGateway.google) + def is_refundable(self) -> bool: + """:class:`bool`: Whether the payment is refundable. + + .. versionadded:: 2.1 + """ + return self.status == PaymentStatus.completed and self._refundable + @property def flags(self) -> PaymentFlags: """:class:`PaymentFlags`: Returns the payment's flags.""" @@ -246,8 +255,8 @@ class Payment(Hashable): HTTPException Refunding the payment failed. """ - await self._state.http.refund_payment(self.id, int(reason)) - self.status = PaymentStatus.refunded + data = await self._state.http.refund_payment(self.id, int(reason)) + self._update(data) class EntitlementPayment(Hashable):