Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PayPal auto refund #310

Merged
merged 11 commits into from
Dec 19, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@
for pr in order.payment_info.payments:
pmt = pr.obj
if pmt.payment_status.interface_code == PAYMENT_STATUS_INTERFACE_CODE_SUCCEEDED and pmt.interface_id:
return pmt, pmt.payment_method_info.payment_interface
ct_payment_provider_id = pmt.payment_method_info.payment_interface
return pmt, ct_payment_provider_id
return None, None


# TODO update function and its return value name
# the return value could be either stripe payment intent id or PayPal order ID
mubbsharanwar marked this conversation as resolved.
Show resolved Hide resolved
def get_edx_payment_intent_id(order: CTOrder) -> Union[str, None]:
mubbsharanwar marked this conversation as resolved.
Show resolved Hide resolved
pmt, _ = get_edx_successful_payment_info(order)
if pmt:
Expand Down Expand Up @@ -82,4 +85,4 @@
interaction_id = transaction.interaction_id
return refund_amount, interaction_id

return refund_amount, interaction_id

Check failure on line 88 in commerce_coordinator/apps/commercetools/catalog_info/edx_utils.py

View workflow job for this annotation

GitHub Actions / tests (ubuntu-20.04, 3.12, django42)

Missing coverage

Missing coverage on line 88
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Commercetools Task Tests"""
import logging
from unittest import TestCase, skip
from unittest import TestCase
from unittest.mock import MagicMock, call, patch

from commercetools.platform.models import MoneyType as CTMoneyType
from commercetools.platform.models import Order as CTOrder
from commercetools.platform.models import ReturnInfo as CTReturnInfo
from commercetools.platform.models import ReturnPaymentState as CTReturnPaymentState
from commercetools.platform.models import TypedMoney as CTTypedMoney
from edx_django_utils.cache import TieredCache

from commerce_coordinator.apps.commercetools.clients import CommercetoolsAPIClient
Expand Down Expand Up @@ -252,6 +254,18 @@ def setUp(self):
self.mock.update_return_payment_state_after_successful_refund
}
)
# TODO: Properly mock the Payment object.
mubbsharanwar marked this conversation as resolved.
Show resolved Hide resolved
payment = self.mock.get_payment_by_key.return_value
amount = CTTypedMoney(
currency_code='USD',
cent_amount=1000,
type=CTMoneyType.CENT_PRECISION,
fraction_digits=2,
)
for transaction in payment.transactions:
transaction.amount = amount

self.payment_mock = payment

def tearDown(self):
MonkeyPatch.unmonkey(CommercetoolsAPIClient)
Expand All @@ -270,35 +284,23 @@ def unpack_for_uut(values):
def get_uut():
return fulfill_order_returned_uut

# TODO: Fix this test. It is failing because of the way the mock is set up.
@patch('commerce_coordinator.apps.commercetools.sub_messages.tasks.is_edx_lms_order')
@patch('commerce_coordinator.apps.stripe.pipeline.StripeAPIClient')
@patch.object(CommercetoolsAPIClientMock, 'payment_mock', new_callable=MagicMock)
@skip(reason="It is failing because of the way the mock is set up.")
def test_correct_arguments_passed_already_refunded_doest_break(
self,
_stripe_api_mock,
_lms_signal,
custom_payment_mock
):
def test_correct_arguments_passed_already_refunded_doest_break(self, _stripe_api_mock, _lms_signal):
"""
Check calling uut with mock_parameters yields call to client with
expected_data.
"""
mock_values = self.mock
custom_payment_mock.return_value = CTPaymentByKey()

ret_val = self.get_uut()(*self.unpack_for_uut(self.mock.example_payload))

self.assertTrue(ret_val)
mock_values.order_mock.assert_has_calls([call(mock_values.order_id), call(order_id=mock_values.order_id)])
mock_values.customer_mock.assert_called_once_with(mock_values.customer_id)

# TODO: Fix this test. It is failing because of the way the mock is set up.
@patch('commerce_coordinator.apps.commercetools.sub_messages.tasks.is_edx_lms_order')
@patch('commerce_coordinator.apps.stripe.pipeline.StripeAPIClient')
@patch('commerce_coordinator.apps.commercetools.clients.CommercetoolsAPIClient.create_return_for_order')
@skip(reason="It is failing because of the way the mock is set up.")
def test_correct_arguments_passed_valid_stripe_refund(
self,
_return_order_mock: MagicMock,
Expand Down
Loading