From 220d511c81bd684593a8fffd72d6f5ed4f1ce7b8 Mon Sep 17 00:00:00 2001 From: mubbsharanwar Date: Tue, 10 Dec 2024 14:18:49 +0500 Subject: [PATCH 1/2] fix: handle paypal payment recipt handle paypal payment recipt url SONIC-784 --- .../commercetools/catalog_info/constants.py | 2 + .../commercetools/catalog_info/edx_utils.py | 6 +++ .../apps/commercetools/pipeline.py | 15 +++++--- commerce_coordinator/apps/paypal/__init__.py | 0 commerce_coordinator/apps/paypal/apps.py | 8 ++++ .../apps/paypal/migrations/__init__.py | 0 commerce_coordinator/apps/paypal/pipeline.py | 31 +++++++++++++++ .../apps/paypal/tests/__init__.py | 1 + .../apps/paypal/tests/test_pipeline.py | 27 +++++++++++++ commerce_coordinator/apps/stripe/pipeline.py | 32 +++++++++------- commerce_coordinator/settings/base.py | 8 +++- ...rce_coordinator.apps.paypal.migrations.rst | 10 +++++ docs/commerce_coordinator.apps.paypal.rst | 38 +++++++++++++++++++ ...commerce_coordinator.apps.paypal.tests.rst | 21 ++++++++++ docs/commerce_coordinator.apps.rst | 1 + 15 files changed, 180 insertions(+), 20 deletions(-) create mode 100644 commerce_coordinator/apps/paypal/__init__.py create mode 100644 commerce_coordinator/apps/paypal/apps.py create mode 100644 commerce_coordinator/apps/paypal/migrations/__init__.py create mode 100644 commerce_coordinator/apps/paypal/pipeline.py create mode 100644 commerce_coordinator/apps/paypal/tests/__init__.py create mode 100644 commerce_coordinator/apps/paypal/tests/test_pipeline.py create mode 100644 docs/commerce_coordinator.apps.paypal.migrations.rst create mode 100644 docs/commerce_coordinator.apps.paypal.rst create mode 100644 docs/commerce_coordinator.apps.paypal.tests.rst diff --git a/commerce_coordinator/apps/commercetools/catalog_info/constants.py b/commerce_coordinator/apps/commercetools/catalog_info/constants.py index 62b86e56..d49190ec 100644 --- a/commerce_coordinator/apps/commercetools/catalog_info/constants.py +++ b/commerce_coordinator/apps/commercetools/catalog_info/constants.py @@ -81,3 +81,5 @@ class Languages: STRIPE_PAYMENT_STATUS_INTERFACE_CODE_SUCCEEDED = "succeeded" EDX_STRIPE_PAYMENT_INTERFACE_NAME = "stripe_edx" + +EDX_PAYPAL_PAYMENT_INTERFACE_NAME = "paypal_edx" diff --git a/commerce_coordinator/apps/commercetools/catalog_info/edx_utils.py b/commerce_coordinator/apps/commercetools/catalog_info/edx_utils.py index 78a32931..3987f375 100644 --- a/commerce_coordinator/apps/commercetools/catalog_info/edx_utils.py +++ b/commerce_coordinator/apps/commercetools/catalog_info/edx_utils.py @@ -65,6 +65,12 @@ def get_edx_payment_intent_id(order: CTOrder) -> Union[str, None]: return None +def get_edx_payment_service_provider(order: CTOrder) -> Union[str, None]: + for pr in order.payment_info.payments: + return pr.obj.payment_method_info.payment_interface + return None + + def get_edx_order_workflow_state_key(order: CTOrder) -> Optional[str]: order_workflow_state = None if order.state and order.state.obj: # it should never be that we have one and not the other. # pragma no cover diff --git a/commerce_coordinator/apps/commercetools/pipeline.py b/commerce_coordinator/apps/commercetools/pipeline.py index 9a13d90c..30876f6b 100644 --- a/commerce_coordinator/apps/commercetools/pipeline.py +++ b/commerce_coordinator/apps/commercetools/pipeline.py @@ -12,8 +12,10 @@ from openedx_filters.exceptions import OpenEdxFilterException from requests import HTTPError +from commerce_coordinator.apps.commercetools.catalog_info.constants import EDX_STRIPE_PAYMENT_INTERFACE_NAME from commerce_coordinator.apps.commercetools.catalog_info.edx_utils import ( get_edx_payment_intent_id, + get_edx_payment_service_provider, get_edx_refund_amount ) from commerce_coordinator.apps.commercetools.clients import CommercetoolsAPIClient @@ -108,20 +110,23 @@ def run_filter(self, active_order_management_system, order_number, **kwargs): # duration = (datetime.now() - start_time).total_seconds() log.info(f"[Performance Check] get_order_by_number call took {duration} seconds") + psp = get_edx_payment_service_provider(ct_order) + + intent_id = None + if psp == EDX_STRIPE_PAYMENT_INTERFACE_NAME: + intent_id = get_edx_payment_intent_id(ct_order) + ret_val = { "order_data": ct_order, + "psp": psp, + "payment_intent_id": intent_id } - - intent_id = get_edx_payment_intent_id(ct_order) - if intent_id: ct_payment = ct_api_client.get_payment_by_key(intent_id) - ret_val['payment_intent_id'] = intent_id ret_val['amount_in_cents'] = get_edx_refund_amount(ct_order) ret_val['has_been_refunded'] = has_refund_transaction(ct_payment) ret_val['payment_data'] = ct_payment else: - ret_val['payment_intent_id'] = None ret_val['amount_in_cents'] = decimal.Decimal(0.00) ret_val['has_been_refunded'] = False ret_val['payment_data'] = None diff --git a/commerce_coordinator/apps/paypal/__init__.py b/commerce_coordinator/apps/paypal/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/commerce_coordinator/apps/paypal/apps.py b/commerce_coordinator/apps/paypal/apps.py new file mode 100644 index 00000000..02594da0 --- /dev/null +++ b/commerce_coordinator/apps/paypal/apps.py @@ -0,0 +1,8 @@ +""" +App configuration for the Commerce Coordinator stripe app. +""" +from django.apps import AppConfig + + +class PaypalConfig(AppConfig): + name = 'commerce_coordinator.apps.paypal' diff --git a/commerce_coordinator/apps/paypal/migrations/__init__.py b/commerce_coordinator/apps/paypal/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/commerce_coordinator/apps/paypal/pipeline.py b/commerce_coordinator/apps/paypal/pipeline.py new file mode 100644 index 00000000..27d04907 --- /dev/null +++ b/commerce_coordinator/apps/paypal/pipeline.py @@ -0,0 +1,31 @@ +""" +Pipelines for paypal app +""" + +import logging +from urllib.parse import urlencode, urljoin + +from django.conf import settings +from openedx_filters import PipelineStep + +from commerce_coordinator.apps.commercetools.catalog_info.constants import EDX_PAYPAL_PAYMENT_INTERFACE_NAME + +logger = logging.getLogger(__name__) + + +class GetPayPalPaymentReceipt(PipelineStep): + """ Purpare PayPal payment recipt """ + + def run_filter(self, psp=None, **params): + if psp == EDX_PAYPAL_PAYMENT_INTERFACE_NAME: + base_url = settings.PAYPAL_BASE_URL + activities_url = settings.PAYPAL_USER_ACTIVITES_URL + query_params = {'free_text_search': params.get('order_number')} + + redirect_url = urljoin(base_url, activities_url) + '?' + urlencode(query_params) + + return { + 'redirect_url': redirect_url, + } + + return None diff --git a/commerce_coordinator/apps/paypal/tests/__init__.py b/commerce_coordinator/apps/paypal/tests/__init__.py new file mode 100644 index 00000000..2e06d004 --- /dev/null +++ b/commerce_coordinator/apps/paypal/tests/__init__.py @@ -0,0 +1 @@ +"""Constants for PayPal app tests.""" diff --git a/commerce_coordinator/apps/paypal/tests/test_pipeline.py b/commerce_coordinator/apps/paypal/tests/test_pipeline.py new file mode 100644 index 00000000..36ed5da2 --- /dev/null +++ b/commerce_coordinator/apps/paypal/tests/test_pipeline.py @@ -0,0 +1,27 @@ +""" PayPal Pipeline Tests""" +from unittest import TestCase + +from django.conf import settings +from django.test import override_settings + +from commerce_coordinator.apps.paypal.pipeline import GetPayPalPaymentReceipt + + +class TestGetPayPalPaymentReceipt(TestCase): + """A pytest Test case for the GetPayPalPaymentReceipt Pipeline Step""" + + @override_settings( + PAYPAL_BASE_URL="https://paypal.com/", + PAYPAL_USER_ACTIVITES_URL="myaccount/activities/" + ) + def test_pipeline_step(self): + order_number = '123' + paypal_payment_pipe = GetPayPalPaymentReceipt("test_pipe", None) + + result: dict = paypal_payment_pipe.run_filter( + edx_lms_user_id=1, + psp='paypal_edx', + order_number=order_number + ) + redirect_url = f"{settings.PAYPAL_BASE_URL}{settings.PAYPAL_USER_ACTIVITES_URL}?free_text_search={order_number}" + self.assertEqual(redirect_url, result['redirect_url']) diff --git a/commerce_coordinator/apps/stripe/pipeline.py b/commerce_coordinator/apps/stripe/pipeline.py index 740acbc9..ebfd74bc 100644 --- a/commerce_coordinator/apps/stripe/pipeline.py +++ b/commerce_coordinator/apps/stripe/pipeline.py @@ -7,6 +7,7 @@ from openedx_filters import PipelineStep from stripe.error import StripeError +from commerce_coordinator.apps.commercetools.catalog_info.constants import EDX_STRIPE_PAYMENT_INTERFACE_NAME from commerce_coordinator.apps.core.constants import PaymentMethod, PipelineCommand from commerce_coordinator.apps.stripe.clients import StripeAPIClient from commerce_coordinator.apps.stripe.constants import Currency @@ -214,26 +215,29 @@ class GetPaymentIntentReceipt(PipelineStep): """ Pull the receipt if the payment_intent is set """ # pylint: disable=unused-argument - def run_filter(self, payment_intent_id=None, **params): + def run_filter(self, payment_intent_id=None, psp=None, **params): tag = type(self).__name__ - if payment_intent_id is None: + if psp == EDX_STRIPE_PAYMENT_INTERFACE_NAME and payment_intent_id is None: logger.debug(f'[{tag}] payment_intent_id not set, skipping.') return PipelineCommand.CONTINUE.value - stripe_api_client = StripeAPIClient() - - payment_intent = stripe_api_client.retrieve_payment_intent( - payment_intent_id, - ["latest_charge"] - ) - - receipt_url = payment_intent.latest_charge.receipt_url + elif psp == EDX_STRIPE_PAYMENT_INTERFACE_NAME: + stripe_api_client = StripeAPIClient() + payment_intent = stripe_api_client.retrieve_payment_intent( + payment_intent_id, + ["latest_charge"] + ) + receipt_url = payment_intent.latest_charge.receipt_url - return { - 'payment_intent': payment_intent, - 'redirect_url': receipt_url - } + return { + 'payment_intent': payment_intent, + 'redirect_url': receipt_url + } + else: + return { + 'psp': psp + } class RefundPaymentIntent(PipelineStep): diff --git a/commerce_coordinator/settings/base.py b/commerce_coordinator/settings/base.py index de5d3b0f..9a7dc2e2 100644 --- a/commerce_coordinator/settings/base.py +++ b/commerce_coordinator/settings/base.py @@ -53,6 +53,7 @@ def root(*path_fragments): 'commerce_coordinator.apps.frontend_app_payment.apps.FrontendAppPaymentConfig', 'commerce_coordinator.apps.lms.apps.LmsConfig', 'commerce_coordinator.apps.stripe.apps.StripeConfig', + 'commerce_coordinator.apps.paypal.apps.PaypalConfig', 'commerce_coordinator.apps.titan.apps.TitanConfig', 'commerce_coordinator.apps.commercetools', ) @@ -374,7 +375,8 @@ def root(*path_fragments): 'commerce_coordinator.apps.ecommerce.pipeline.GetLegacyEcommerceReceiptRedirectUrl', 'commerce_coordinator.apps.rollout.pipeline.HaltIfRedirectUrlProvided', 'commerce_coordinator.apps.commercetools.pipeline.FetchOrderDetailsByOrderNumber', - 'commerce_coordinator.apps.stripe.pipeline.GetPaymentIntentReceipt' + 'commerce_coordinator.apps.stripe.pipeline.GetPaymentIntentReceipt', + 'commerce_coordinator.apps.paypal.pipeline.GetPayPalPaymentReceipt' ] }, "org.edx.coordinator.lms.order.refund.requested.v1": { @@ -474,3 +476,7 @@ def root(*path_fragments): SEGMENT_KEY = None FAVICON_URL = "https://edx-cdn.org/v3/prod/favicon.ico" + +# PAYPAL SETTINIS +PAYPAL_BASE_URL = "" +PAYPAL_USER_ACTIVITES_URL = "" diff --git a/docs/commerce_coordinator.apps.paypal.migrations.rst b/docs/commerce_coordinator.apps.paypal.migrations.rst new file mode 100644 index 00000000..87363cfe --- /dev/null +++ b/docs/commerce_coordinator.apps.paypal.migrations.rst @@ -0,0 +1,10 @@ +commerce\_coordinator.apps.paypal.migrations package +==================================================== + +Module contents +--------------- + +.. automodule:: commerce_coordinator.apps.paypal.migrations + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/commerce_coordinator.apps.paypal.rst b/docs/commerce_coordinator.apps.paypal.rst new file mode 100644 index 00000000..52d670b1 --- /dev/null +++ b/docs/commerce_coordinator.apps.paypal.rst @@ -0,0 +1,38 @@ +commerce\_coordinator.apps.paypal package +========================================= + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + commerce_coordinator.apps.paypal.migrations + commerce_coordinator.apps.paypal.tests + +Submodules +---------- + +commerce\_coordinator.apps.paypal.apps module +--------------------------------------------- + +.. automodule:: commerce_coordinator.apps.paypal.apps + :members: + :undoc-members: + :show-inheritance: + +commerce\_coordinator.apps.paypal.pipeline module +------------------------------------------------- + +.. automodule:: commerce_coordinator.apps.paypal.pipeline + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: commerce_coordinator.apps.paypal + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/commerce_coordinator.apps.paypal.tests.rst b/docs/commerce_coordinator.apps.paypal.tests.rst new file mode 100644 index 00000000..c4ff9fb6 --- /dev/null +++ b/docs/commerce_coordinator.apps.paypal.tests.rst @@ -0,0 +1,21 @@ +commerce\_coordinator.apps.paypal.tests package +=============================================== + +Submodules +---------- + +commerce\_coordinator.apps.paypal.tests.test\_pipeline module +------------------------------------------------------------- + +.. automodule:: commerce_coordinator.apps.paypal.tests.test_pipeline + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: commerce_coordinator.apps.paypal.tests + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/commerce_coordinator.apps.rst b/docs/commerce_coordinator.apps.rst index 33adf27d..5cdaeba1 100644 --- a/docs/commerce_coordinator.apps.rst +++ b/docs/commerce_coordinator.apps.rst @@ -17,6 +17,7 @@ Subpackages commerce_coordinator.apps.lms commerce_coordinator.apps.rollout commerce_coordinator.apps.stripe + commerce_coordinator.apps.paypal commerce_coordinator.apps.titan Module contents From 2e533efc0fa28e0d2d0586c80cb89cfb48387761 Mon Sep 17 00:00:00 2001 From: mubbsharanwar Date: Fri, 13 Dec 2024 19:10:28 +0500 Subject: [PATCH 2/2] fix: address review comments --- .../commercetools/catalog_info/constants.py | 2 +- .../commercetools/catalog_info/edx_utils.py | 14 +++++++---- .../apps/commercetools/pipeline.py | 20 +++------------- commerce_coordinator/apps/paypal/apps.py | 4 ++-- commerce_coordinator/apps/paypal/pipeline.py | 23 ++++++++++--------- .../apps/paypal/tests/test_pipeline.py | 13 +++++++---- commerce_coordinator/apps/stripe/pipeline.py | 11 ++++----- commerce_coordinator/settings/base.py | 9 ++++---- commerce_coordinator/settings/local.py | 3 +++ commerce_coordinator/settings/test.py | 3 +++ 10 files changed, 49 insertions(+), 53 deletions(-) diff --git a/commerce_coordinator/apps/commercetools/catalog_info/constants.py b/commerce_coordinator/apps/commercetools/catalog_info/constants.py index d49190ec..f02d31ae 100644 --- a/commerce_coordinator/apps/commercetools/catalog_info/constants.py +++ b/commerce_coordinator/apps/commercetools/catalog_info/constants.py @@ -78,7 +78,7 @@ class Languages: "directDiscounts[*]" ) -STRIPE_PAYMENT_STATUS_INTERFACE_CODE_SUCCEEDED = "succeeded" +PAYMENT_STATUS_INTERFACE_CODE_SUCCEEDED = "succeeded" EDX_STRIPE_PAYMENT_INTERFACE_NAME = "stripe_edx" diff --git a/commerce_coordinator/apps/commercetools/catalog_info/edx_utils.py b/commerce_coordinator/apps/commercetools/catalog_info/edx_utils.py index 3987f375..ed7a5edc 100644 --- a/commerce_coordinator/apps/commercetools/catalog_info/edx_utils.py +++ b/commerce_coordinator/apps/commercetools/catalog_info/edx_utils.py @@ -11,7 +11,7 @@ from commerce_coordinator.apps.commercetools.catalog_info.constants import ( EDX_STRIPE_PAYMENT_INTERFACE_NAME, - STRIPE_PAYMENT_STATUS_INTERFACE_CODE_SUCCEEDED, + PAYMENT_STATUS_INTERFACE_CODE_SUCCEEDED, EdXFieldNames, TwoUKeys ) @@ -51,7 +51,7 @@ def get_edx_lms_user_name(customer: CTCustomer): def get_edx_successful_stripe_payment(order: CTOrder) -> Union[CTPayment, None]: for pr in order.payment_info.payments: pmt = pr.obj - if pmt.payment_status.interface_code == STRIPE_PAYMENT_STATUS_INTERFACE_CODE_SUCCEEDED \ + if pmt.payment_status.interface_code == PAYMENT_STATUS_INTERFACE_CODE_SUCCEEDED \ and pmt.payment_method_info.payment_interface == EDX_STRIPE_PAYMENT_INTERFACE_NAME and \ pmt.interface_id: return pmt @@ -65,10 +65,14 @@ def get_edx_payment_intent_id(order: CTOrder) -> Union[str, None]: return None -def get_edx_payment_service_provider(order: CTOrder) -> Union[str, None]: +# TODO update get_edx_successful_stripe_payment to accommodate this util logic +# and replace it with that. +def get_edx_successful_payment_info(order: CTOrder): for pr in order.payment_info.payments: - return pr.obj.payment_method_info.payment_interface - return None + pmt = pr.obj + if pmt.payment_status.interface_code == PAYMENT_STATUS_INTERFACE_CODE_SUCCEEDED and pmt.interface_id: + return pmt.interface_id, pmt.payment_method_info.payment_interface + return None, None def get_edx_order_workflow_state_key(order: CTOrder) -> Optional[str]: diff --git a/commerce_coordinator/apps/commercetools/pipeline.py b/commerce_coordinator/apps/commercetools/pipeline.py index 30876f6b..f5e4a368 100644 --- a/commerce_coordinator/apps/commercetools/pipeline.py +++ b/commerce_coordinator/apps/commercetools/pipeline.py @@ -12,11 +12,10 @@ from openedx_filters.exceptions import OpenEdxFilterException from requests import HTTPError -from commerce_coordinator.apps.commercetools.catalog_info.constants import EDX_STRIPE_PAYMENT_INTERFACE_NAME from commerce_coordinator.apps.commercetools.catalog_info.edx_utils import ( get_edx_payment_intent_id, - get_edx_payment_service_provider, - get_edx_refund_amount + get_edx_refund_amount, + get_edx_successful_payment_info ) from commerce_coordinator.apps.commercetools.clients import CommercetoolsAPIClient from commerce_coordinator.apps.commercetools.constants import COMMERCETOOLS_ORDER_MANAGEMENT_SYSTEM @@ -110,26 +109,13 @@ def run_filter(self, active_order_management_system, order_number, **kwargs): # duration = (datetime.now() - start_time).total_seconds() log.info(f"[Performance Check] get_order_by_number call took {duration} seconds") - psp = get_edx_payment_service_provider(ct_order) - - intent_id = None - if psp == EDX_STRIPE_PAYMENT_INTERFACE_NAME: - intent_id = get_edx_payment_intent_id(ct_order) + intent_id, psp = get_edx_successful_payment_info(ct_order) ret_val = { "order_data": ct_order, "psp": psp, "payment_intent_id": intent_id } - if intent_id: - ct_payment = ct_api_client.get_payment_by_key(intent_id) - ret_val['amount_in_cents'] = get_edx_refund_amount(ct_order) - ret_val['has_been_refunded'] = has_refund_transaction(ct_payment) - ret_val['payment_data'] = ct_payment - else: - ret_val['amount_in_cents'] = decimal.Decimal(0.00) - ret_val['has_been_refunded'] = False - ret_val['payment_data'] = None return ret_val except CommercetoolsError as err: # pragma no cover diff --git a/commerce_coordinator/apps/paypal/apps.py b/commerce_coordinator/apps/paypal/apps.py index 02594da0..1a28f8a2 100644 --- a/commerce_coordinator/apps/paypal/apps.py +++ b/commerce_coordinator/apps/paypal/apps.py @@ -1,8 +1,8 @@ """ -App configuration for the Commerce Coordinator stripe app. +App configuration for the Commerce Coordinator paypal app. """ from django.apps import AppConfig -class PaypalConfig(AppConfig): +class PayPalConfig(AppConfig): name = 'commerce_coordinator.apps.paypal' diff --git a/commerce_coordinator/apps/paypal/pipeline.py b/commerce_coordinator/apps/paypal/pipeline.py index 27d04907..9d4841d9 100644 --- a/commerce_coordinator/apps/paypal/pipeline.py +++ b/commerce_coordinator/apps/paypal/pipeline.py @@ -3,12 +3,13 @@ """ import logging -from urllib.parse import urlencode, urljoin +from urllib.parse import urlencode from django.conf import settings from openedx_filters import PipelineStep from commerce_coordinator.apps.commercetools.catalog_info.constants import EDX_PAYPAL_PAYMENT_INTERFACE_NAME +from commerce_coordinator.apps.core.constants import PipelineCommand logger = logging.getLogger(__name__) @@ -16,16 +17,16 @@ class GetPayPalPaymentReceipt(PipelineStep): """ Purpare PayPal payment recipt """ - def run_filter(self, psp=None, **params): - if psp == EDX_PAYPAL_PAYMENT_INTERFACE_NAME: - base_url = settings.PAYPAL_BASE_URL - activities_url = settings.PAYPAL_USER_ACTIVITES_URL - query_params = {'free_text_search': params.get('order_number')} + def run_filter(self, psp=None, payment_intent_id=None, **params): - redirect_url = urljoin(base_url, activities_url) + '?' + urlencode(query_params) + if payment_intent_id is None or psp != EDX_PAYPAL_PAYMENT_INTERFACE_NAME: + return PipelineCommand.CONTINUE.value - return { - 'redirect_url': redirect_url, - } + activity_page_url = settings.PAYMENT_PROCESSOR_CONFIG['edx']['paypal']['user_activity_page_url'] + query_params = {'free_text_search': params.get('order_number')} - return None + redirect_url = activity_page_url + '?' + urlencode(query_params) + + return { + 'redirect_url': redirect_url, + } diff --git a/commerce_coordinator/apps/paypal/tests/test_pipeline.py b/commerce_coordinator/apps/paypal/tests/test_pipeline.py index 36ed5da2..25d81383 100644 --- a/commerce_coordinator/apps/paypal/tests/test_pipeline.py +++ b/commerce_coordinator/apps/paypal/tests/test_pipeline.py @@ -6,14 +6,15 @@ from commerce_coordinator.apps.paypal.pipeline import GetPayPalPaymentReceipt +TEST_PAYMENT_PROCESSOR_CONFIG = settings.PAYMENT_PROCESSOR_CONFIG +ACTIVITY_URL = "https://test.paypal.com/myaccount/activities/" +TEST_PAYMENT_PROCESSOR_CONFIG['edx']['paypal']['user_activity_page_url'] = ACTIVITY_URL + class TestGetPayPalPaymentReceipt(TestCase): """A pytest Test case for the GetPayPalPaymentReceipt Pipeline Step""" - @override_settings( - PAYPAL_BASE_URL="https://paypal.com/", - PAYPAL_USER_ACTIVITES_URL="myaccount/activities/" - ) + @override_settings(PAYMENT_PROCESSOR_CONFIG=TEST_PAYMENT_PROCESSOR_CONFIG) def test_pipeline_step(self): order_number = '123' paypal_payment_pipe = GetPayPalPaymentReceipt("test_pipe", None) @@ -21,7 +22,9 @@ def test_pipeline_step(self): result: dict = paypal_payment_pipe.run_filter( edx_lms_user_id=1, psp='paypal_edx', + payment_intent_id="00001", order_number=order_number ) - redirect_url = f"{settings.PAYPAL_BASE_URL}{settings.PAYPAL_USER_ACTIVITES_URL}?free_text_search={order_number}" + url = settings.PAYMENT_PROCESSOR_CONFIG['edx']['paypal']['user_activity_page_url'] + redirect_url = f"{url}?free_text_search={order_number}" self.assertEqual(redirect_url, result['redirect_url']) diff --git a/commerce_coordinator/apps/stripe/pipeline.py b/commerce_coordinator/apps/stripe/pipeline.py index ebfd74bc..22583dd3 100644 --- a/commerce_coordinator/apps/stripe/pipeline.py +++ b/commerce_coordinator/apps/stripe/pipeline.py @@ -215,14 +215,14 @@ class GetPaymentIntentReceipt(PipelineStep): """ Pull the receipt if the payment_intent is set """ # pylint: disable=unused-argument - def run_filter(self, payment_intent_id=None, psp=None, **params): + def run_filter(self, psp=None, payment_intent_id=None, **params): tag = type(self).__name__ - if psp == EDX_STRIPE_PAYMENT_INTERFACE_NAME and payment_intent_id is None: + if payment_intent_id is None: logger.debug(f'[{tag}] payment_intent_id not set, skipping.') return PipelineCommand.CONTINUE.value - elif psp == EDX_STRIPE_PAYMENT_INTERFACE_NAME: + if psp == EDX_STRIPE_PAYMENT_INTERFACE_NAME: stripe_api_client = StripeAPIClient() payment_intent = stripe_api_client.retrieve_payment_intent( payment_intent_id, @@ -234,10 +234,7 @@ def run_filter(self, payment_intent_id=None, psp=None, **params): 'payment_intent': payment_intent, 'redirect_url': receipt_url } - else: - return { - 'psp': psp - } + return None class RefundPaymentIntent(PipelineStep): diff --git a/commerce_coordinator/settings/base.py b/commerce_coordinator/settings/base.py index 9a7dc2e2..33f16926 100644 --- a/commerce_coordinator/settings/base.py +++ b/commerce_coordinator/settings/base.py @@ -53,7 +53,7 @@ def root(*path_fragments): 'commerce_coordinator.apps.frontend_app_payment.apps.FrontendAppPaymentConfig', 'commerce_coordinator.apps.lms.apps.LmsConfig', 'commerce_coordinator.apps.stripe.apps.StripeConfig', - 'commerce_coordinator.apps.paypal.apps.PaypalConfig', + 'commerce_coordinator.apps.paypal.apps.PayPalConfig', 'commerce_coordinator.apps.titan.apps.TitanConfig', 'commerce_coordinator.apps.commercetools', ) @@ -431,6 +431,9 @@ def root(*path_fragments): 'source_system_identifier': 'edx/commerce_coordinator?v=1', 'webhook_endpoint_secret': STRIPE_WEBHOOK_ENDPOINT_SECRET, }, + 'paypal': { + 'user_activity_page_url': '', + }, }, } # END PAYMENT PROCESSING @@ -476,7 +479,3 @@ def root(*path_fragments): SEGMENT_KEY = None FAVICON_URL = "https://edx-cdn.org/v3/prod/favicon.ico" - -# PAYPAL SETTINIS -PAYPAL_BASE_URL = "" -PAYPAL_USER_ACTIVITES_URL = "" diff --git a/commerce_coordinator/settings/local.py b/commerce_coordinator/settings/local.py index 6d7803d6..6fbc5911 100644 --- a/commerce_coordinator/settings/local.py +++ b/commerce_coordinator/settings/local.py @@ -144,6 +144,9 @@ 'source_system_identifier': 'edx/commerce_coordinator?v=1', 'webhook_endpoint_secret': 'SET-ME-PLEASE', }, + 'paypal': { + 'user_activity_page_url': 'https://sandbox.paypal.com/myaccount/activities/', + }, }, } diff --git a/commerce_coordinator/settings/test.py b/commerce_coordinator/settings/test.py index 36178042..0d0b3f93 100644 --- a/commerce_coordinator/settings/test.py +++ b/commerce_coordinator/settings/test.py @@ -15,6 +15,9 @@ 'source_system_identifier': 'edx/commerce_coordinator?v=1', 'webhook_endpoint_secret': 'SET-ME-PLEASE', }, + 'paypal': { + 'user_activity_page_url': 'https://test.paypal.com/myaccount/activities/', + }, }, } # END PAYMENT PROCESSING