diff --git a/commerce_coordinator/apps/commercetools/clients.py b/commerce_coordinator/apps/commercetools/clients.py index 786fc143..99e96b5c 100644 --- a/commerce_coordinator/apps/commercetools/clients.py +++ b/commerce_coordinator/apps/commercetools/clients.py @@ -531,7 +531,7 @@ def create_return_payment_transaction( try: logger.info( f"[CommercetoolsAPIClient] - Creating refund transaction for payment with ID {payment_id} " - f"following successful refund {refund['id']} in PSP: {psp}" + f"following successful refund {refund.get('id')} in PSP: {psp}" ) refund = self._preprocess_refund_object(refund, psp) diff --git a/commerce_coordinator/apps/paypal/clients.py b/commerce_coordinator/apps/paypal/clients.py index 1ef2bc99..6db9daa5 100644 --- a/commerce_coordinator/apps/paypal/clients.py +++ b/commerce_coordinator/apps/paypal/clients.py @@ -6,6 +6,7 @@ from paypalserversdk.controllers.payments_controller import PaymentsController from paypalserversdk.http.auth.o_auth_2 import ClientCredentialsAuthCredentials from paypalserversdk.paypalserversdk_client import PaypalserversdkClient +from paypalserversdk.configuration import Environment class PayPalClient: @@ -18,6 +19,9 @@ def __init__(self): o_auth_client_id=settings.PAYMENT_PROCESSOR_CONFIG['edx']['paypal']['client_id'], o_auth_client_secret=settings.PAYMENT_PROCESSOR_CONFIG['edx']['paypal']['client_secret'], ), + environment=(Environment.SANDBOX + if settings.PAYMENT_PROCESSOR_CONFIG['edx']['paypal']['env'] == 'sandbox' + else Environment.PRODUCTION), ) def refund_order(self, capture_id): diff --git a/commerce_coordinator/apps/paypal/pipeline.py b/commerce_coordinator/apps/paypal/pipeline.py index 955bd4c6..5cb85385 100644 --- a/commerce_coordinator/apps/paypal/pipeline.py +++ b/commerce_coordinator/apps/paypal/pipeline.py @@ -60,6 +60,8 @@ def run_filter( tag = type(self).__name__ if psp != EDX_PAYPAL_PAYMENT_INTERFACE_NAME or not amount_in_cents or not ct_transaction_interaction_id: + logger.info(f'[{tag}] capture_id or amount_in_cents not set, ' + f'skipping refund for order: {order_id} with psp: {psp}') return PipelineCommand.CONTINUE.value if has_been_refunded: diff --git a/commerce_coordinator/settings/base.py b/commerce_coordinator/settings/base.py index 3d183c00..792c1708 100644 --- a/commerce_coordinator/settings/base.py +++ b/commerce_coordinator/settings/base.py @@ -441,6 +441,7 @@ def root(*path_fragments): 'paypal_webhook_id': PAYPAL_WEBHOOK_ID, 'client_id': '', 'client_secret': '', + 'env': 'sandbox', }, }, }