Browse Source

Improve refund support

pull/10109/head
dolfies 5 months ago
parent
commit
20a7ce5e18
  1. 7
      discord/flags.py
  2. 5
      discord/http.py
  3. 13
      discord/payments.py

7
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."""

5
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

13
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):

Loading…
Cancel
Save