Skip to content

Commit

Permalink
fix: Handled cancelled payment case for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
jawad-khan committed Jul 29, 2024
1 parent 5418b39 commit 06bc657
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ecommerce/extensions/iap/processors/base_iap.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ def handle_processor_response(self, response, basket=None):
if not original_transaction_id:
raise PaymentError(response)

if 'cancellation_reason' in validation_response['receipt']['in_app'][0]:
error = 'iOS payment is cancelled for [%s] in basket [%d]'
logger.error(error, original_transaction_id, basket.id)
raise UserCancelled(response)

# In case of Android transaction_id is required to identify payment
elif not transaction_id:
logger.error('Unable to find transaction id for basket [%d]', basket.id)
Expand Down
15 changes: 14 additions & 1 deletion ecommerce/extensions/iap/tests/processors/test_ios_iap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import mock
from django.test import RequestFactory
from django.urls import reverse
from oscar.apps.payment.exceptions import GatewayError, PaymentError
from oscar.apps.payment.exceptions import GatewayError, PaymentError, UserCancelled
from oscar.core.loading import get_model
from testfixtures import LogCapture

Expand Down Expand Up @@ -185,6 +185,19 @@ def test_handle_processor_response_payment_error(self, mock_ios_validator):

self.processor.handle_processor_response(modified_return_data, basket=self.basket)

@mock.patch.object(IOSValidator, 'validate')
def test_handle_cancelled_payment_error(self, mock_ios_validator):
"""
Verify that User cancelled exception is raised in presence of cancellation_reason parameter.
"""
modified_validation_response = self.mock_validation_response
modified_validation_response['receipt']['in_app'][2]['cancellation_reason'] = 0
mock_ios_validator.return_value = modified_validation_response
with self.assertRaises(UserCancelled):
modified_return_data = self.RETURN_DATA

self.processor.handle_processor_response(modified_return_data, basket=self.basket)

@mock.patch.object(IOSIAP, 'is_payment_redundant')
@mock.patch.object(IOSValidator, 'validate')
def test_handle_processor_response_redundant_error(self, mock_ios_validator, mock_payment_redundant):
Expand Down

0 comments on commit 06bc657

Please sign in to comment.