Skip to content

Commit

Permalink
fix: PayPal refund bug on prod
Browse files Browse the repository at this point in the history
  • Loading branch information
syedsajjadkazmii committed Jan 8, 2025
1 parent 1772b10 commit bc9f89f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion commerce_coordinator/apps/commercetools/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions commerce_coordinator/apps/paypal/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.conf import settings
from paypalserversdk.api_helper import ApiHelper
from paypalserversdk.configuration import Environment
from paypalserversdk.controllers.payments_controller import PaymentsController
from paypalserversdk.http.auth.o_auth_2 import ClientCredentialsAuthCredentials
from paypalserversdk.paypalserversdk_client import PaypalserversdkClient
Expand All @@ -18,6 +19,11 @@ 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):
Expand Down
2 changes: 2 additions & 0 deletions commerce_coordinator/apps/paypal/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions commerce_coordinator/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ def root(*path_fragments):
'paypal_webhook_id': PAYPAL_WEBHOOK_ID,
'client_id': '',
'client_secret': '',
'env': 'sandbox',
},
},
}
Expand Down

0 comments on commit bc9f89f

Please sign in to comment.