Skip to content

Commit

Permalink
fix backward compatibility by making PayuProvider's get_refund_descri…
Browse files Browse the repository at this point in the history
…ption argument optional
  • Loading branch information
radekholy24 committed Apr 7, 2024
1 parent 1f61405 commit 838e06c
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 89 deletions.
2 changes: 1 addition & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Development Lead
Contributors
------------

* Radek Holý
* BlenderKit <[email protected]>
8 changes: 8 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@
History
-------

Unreleased
**********
* fix backward compatibility by making PayuProvider's get_refund_description argument optional
* make PayuProvider.refund fail if get_refund_description is not provided
* deprecate the default value of get_refund_description; set it to a callable instead

1.3.1 (2024-03-19)
******************
* Fix description on PyPI

1.3.0 (2024-03-19)
******************
* add get_refund_description and get_refund_ext_id arguments to PayuProvider
* add PayuProvider.refund
* update payment.captured_amount only when order is completed
* subtract refunds from payment.captured_amount rather than from payment.total
* rename PayuProvider.payu_api_order_url to payu_api_orders_url
* tests for Django 2.2-5.0 Python 3.7-3.12

1.2.4 (2022-03-17)
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Here are valid parameters for the provider:
:express_payments: use PayU express form
:widget_branding: tell express form to show PayU branding
:store_card: (default: False) whether PayU should store the card
:get_refund_description: A mandatory callable that is called with two keyword arguments `payment` and `amount` in order to get the string description of the particular refund whenever ``provider.refund(payment, amount)`` is called.
:get_refund_description: An optional callable that is called with two keyword arguments `payment` and `amount` in order to get the string description of the particular refund whenever ``provider.refund(payment, amount)`` is called. The callable is optional because of backwards compatibility. However, if it is not set, an attempt to refund raises an exception. A default value of `get_refund_description` is deprecated.
:get_refund_ext_id: An optional callable that is called with two keyword arguments `payment` and `amount` in order to get the External string refund ID of the particular refund whenever ``provider.refund(payment, amount)`` is called. If ``None`` is returned, no External refund ID is set. An External refund ID is not necessary if partial refunds won't be performed more than once per second. Otherwise, a unique ID is recommended since `PayuProvider.refund` is idempotent and if exactly same data will be provided, it will return the result of the already previously performed refund instead of performing a new refund. Defaults to a random UUID version 4 in the standard form.


Expand Down
15 changes: 14 additions & 1 deletion payments_payu/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import logging
import uuid
import warnings
from decimal import ROUND_HALF_UP, Decimal
from urllib.parse import urljoin

Expand Down Expand Up @@ -185,7 +186,16 @@ def __init__(self, *args, **kwargs):
self.payu_shop_name = kwargs.pop("shop_name", "")
self.grant_type = kwargs.pop("grant_type", "client_credentials")
self.recurring_payments = kwargs.pop("recurring_payments", False)
self.get_refund_description = kwargs.pop("get_refund_description")
self.get_refund_description = kwargs.pop(
"get_refund_description",
# TODO: The default is deprecated. Remove in the next major release.
None,
)
if self.get_refund_description is None:
warnings.warn(
"A default value of get_refund_description is deprecated. Set it to a callable instead.",
DeprecationWarning,
)
self.get_refund_ext_id = kwargs.pop(
"get_refund_ext_id", lambda payment, amount: str(uuid.uuid4())
)
Expand Down Expand Up @@ -604,6 +614,9 @@ def process_data(self, payment, request, *args, **kwargs):
)

def refund(self, payment, amount=None):
if self.get_refund_description is None:
raise ValueError("get_refund_description not set")

request_url = self._get_payu_api_order_url(payment.transaction_id) + "/refunds"

request_data = {
Expand Down
Loading

0 comments on commit 838e06c

Please sign in to comment.