Repository navigation
fix(payment): consolidate duplicate refund method and support flexible payloads - #345
Open
tushar-hub wants to merge 1 commit into
Open
tushar-hub wants to merge 1 commit into
tushar-hub wants to merge 1 commit into
Conversation
…e payloads Consolidate the two conflicting Payment.refund definitions into a single backward-compatible method. Supports positional amount (int/float/str), options dictionary, keyword amount, and parameter combinations without mutating caller arguments or failing with TypeErrors. Fixes razorpay#289.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
razorpay/resources/payment.py, thePaymentclass previously contained two conflicting definitions of therefundmethod:def refund(self, payment_id, amount, data={}, **kwargs)def refund(self, payment_id, data={}, **kwargs)refundmethod:client.payment.refund(payment_id, 2000)).client.payment.refund(payment_id, {"amount": 2000, "speed": "normal"})).client.payment.refund(payment_id, 2000, {"speed": "normal"})).amount(client.payment.refund(payment_id, amount=2000)).client.payment.refund(payment_id)).data={}withNoneand non-mutating payload construction.fetch_refund_id.Motivation & Impact
refund()serialized the raw integer instead of an object with"amount", while passingamountas a keyword argument threwTypeError: refund() got an unexpected keyword argument 'amount'.data={}persists across calls.Testing Done
python -m unitteston the full suite: 162 tests passed, 0 failures, 1 skipped.test_refund_createandtest_payment_refund.tests/test_client_payment.py:test_payment_refund_with_amount_and_options: verifiesrefund(payment_id, 2000, {'speed': 'normal', 'receipt': '#rec_1'})sends{"amount": 2000, "speed": "normal", "receipt": "#rec_1"}and does not mutate caller dictionary.test_payment_refund_with_keyword_amount: verifiesrefund(payment_id, amount=3000)sends{"amount": 3000}.test_payment_refund_with_keyword_amount_and_data: verifiesrefund(payment_id, amount=3000, data={'speed': 'optimum'})sends{"amount": 3000, "speed": "optimum"}.test_payment_refund_without_arguments: verifiesrefund(payment_id)sends{}.git diff --check.