diff --git a/ecommerce/extensions/basket/constants.py b/ecommerce/extensions/basket/constants.py index 04715ca7eca..436071f33da 100644 --- a/ecommerce/extensions/basket/constants.py +++ b/ecommerce/extensions/basket/constants.py @@ -2,7 +2,6 @@ EMAIL_OPT_IN_ATTRIBUTE = "email_opt_in" PURCHASER_BEHALF_ATTRIBUTE = "purchased_for_organization" PAYMENT_INTENT_ID_ATTRIBUTE = "payment_intent_id" -PAYMENT_INTENT_STATUS_ATTRIBUTE = "payment_intent_status" DYNAMIC_PAYMENT_METHODS_ENABLED = "dynamic_payment_methods_enabled" # .. toggle_name: enable_stripe_payment_processor diff --git a/ecommerce/extensions/basket/tests/test_views.py b/ecommerce/extensions/basket/tests/test_views.py index 1b6bb5faea9..52a56f7306e 100644 --- a/ecommerce/extensions/basket/tests/test_views.py +++ b/ecommerce/extensions/basket/tests/test_views.py @@ -40,8 +40,7 @@ _set_basket_bundle_status, apply_voucher_on_basket_and_check_discount, basket_add_dynamic_payment_methods_enabled, - basket_add_payment_intent_id_attribute, - basket_add_payment_intent_status + basket_add_payment_intent_id_attribute ) from ecommerce.extensions.catalogue.tests.mixins import DiscoveryTestMixin from ecommerce.extensions.offer.constants import DYNAMIC_DISCOUNT_FLAG @@ -331,12 +330,11 @@ def create_basket_and_add_product(self, product): basket.add_product(product, 1) return basket - def create_basket_and_add_product_stripe(self, product, payment_intent_status, payment_intent_id, payment_intent): + def create_basket_and_add_product_stripe(self, product, payment_intent_id, payment_intent): basket = self.create_empty_basket() basket.add_product(product, 1) basket_add_dynamic_payment_methods_enabled(basket, payment_intent) basket_add_payment_intent_id_attribute(basket, payment_intent_id) - basket_add_payment_intent_status(basket, payment_intent_status) return basket def create_seat(self, course, seat_price=100, cert_type='verified'): @@ -437,7 +435,6 @@ def assert_expected_response( messages=None, summary_discounts=None, payment_intent_id=None, - payment_intent_status=None, **kwargs ): if response is None: @@ -485,7 +482,6 @@ def assert_expected_response( 'summary_price': summary_price, 'order_total': order_total, 'payment_intent_id': payment_intent_id, - 'payment_intent_status': payment_intent_status, 'products': [ { 'product_type': product_type, @@ -735,9 +731,8 @@ def test_enable_stripe_payment_processor_flag(self, enable_stripe_payment_proces def test_cart_with_stripe_data(self): """ For Dynamic Payment Methods, the basket will contain Payment Intent information. - Verify that the basket contains Payment Intent ID, Payment Intent status, and if DPM is enabled. + Verify that the basket contains Payment Intent ID and if DPM is enabled. """ - payment_intent_status = 'requires_payment_method' payment_intent_id = 'pi_3OqcQ5H4caH7G0X11y8NKNa4' payment_intent = { 'payment_method_types': [ @@ -747,14 +742,13 @@ def test_cart_with_stripe_data(self): } seat = self.create_seat(self.course) basket = self.create_basket_and_add_product_stripe( - seat, payment_intent_status, payment_intent_id, payment_intent + seat, payment_intent_id, payment_intent ) response = self.client.get(self.path) self.assert_expected_response( basket, response=response, is_dynamic_payment_methods_enabled=len(payment_intent['payment_method_types']) > 1, - payment_intent_status=payment_intent_status, payment_intent_id=payment_intent_id ) diff --git a/ecommerce/extensions/basket/utils.py b/ecommerce/extensions/basket/utils.py index 1108ced84ef..cd7669e05e1 100644 --- a/ecommerce/extensions/basket/utils.py +++ b/ecommerce/extensions/basket/utils.py @@ -23,7 +23,6 @@ EMAIL_OPT_IN_ATTRIBUTE, ENABLE_STRIPE_PAYMENT_PROCESSOR, PAYMENT_INTENT_ID_ATTRIBUTE, - PAYMENT_INTENT_STATUS_ATTRIBUTE, PURCHASER_BEHALF_ATTRIBUTE, REDIRECT_WITH_WAFFLE_TESTING_QUERYSTRING ) @@ -396,20 +395,6 @@ def basket_add_organization_attribute(basket, request_data): ) -@newrelic.agent.function_trace() -def basket_add_payment_intent_status(basket, payment_intent_status): - payment_intent_status_attribute, __ = BasketAttributeType.objects.get_or_create( - name=PAYMENT_INTENT_STATUS_ATTRIBUTE) - # Do a get_or_create and update value_text after (instead of update_or_create) - # to prevent a particularly slow full table scan that uses a LIKE - basket_attribute, __ = BasketAttribute.objects.get_or_create( - attribute_type=payment_intent_status_attribute, - basket=basket, - ) - basket_attribute.value_text = payment_intent_status - basket_attribute.save() - - @newrelic.agent.function_trace() def basket_add_dynamic_payment_methods_enabled(basket, payment_intent): """ diff --git a/ecommerce/extensions/basket/views.py b/ecommerce/extensions/basket/views.py index 0ce60aff07a..241655e789d 100644 --- a/ecommerce/extensions/basket/views.py +++ b/ecommerce/extensions/basket/views.py @@ -50,8 +50,7 @@ from ecommerce.extensions.basket.constants import ( DYNAMIC_PAYMENT_METHODS_ENABLED, ENABLE_STRIPE_PAYMENT_PROCESSOR, - PAYMENT_INTENT_ID_ATTRIBUTE, - PAYMENT_INTENT_STATUS_ATTRIBUTE + PAYMENT_INTENT_ID_ATTRIBUTE ) from ecommerce.extensions.basket.exceptions import BadRequestException, RedirectException, VoucherException from ecommerce.extensions.basket.utils import ( @@ -683,7 +682,6 @@ def _serialize_context(self, context, lines_data): self._add_coupons(response, context) self._add_enable_stripe_payment_processor(response) self._add_payment_intent_id(response, self.request.basket) - self._add_payment_intent_status(response, self.request.basket) self._add_is_dynamic_payment_methods(response, self.request.basket) return response @@ -758,17 +756,6 @@ def _add_payment_intent_id(self, response, basket): except (BasketAttribute.DoesNotExist, BasketAttributeType.DoesNotExist): response['payment_intent_id'] = None - def _add_payment_intent_status(self, response, basket): - try: - payment_intent_status_attribute = BasketAttributeType.objects.get(name=PAYMENT_INTENT_STATUS_ATTRIBUTE) - payment_intent_attr = BasketAttribute.objects.get( - basket=basket, - attribute_type=payment_intent_status_attribute - ) - response['payment_intent_status'] = payment_intent_attr.value_text.strip() - except (BasketAttribute.DoesNotExist, BasketAttributeType.DoesNotExist): - response['payment_intent_status'] = None - def _add_is_dynamic_payment_methods(self, response, basket): try: dynamic_payment_methods_enabled_attribute = BasketAttributeType.objects.get( diff --git a/ecommerce/extensions/payment/processors/stripe.py b/ecommerce/extensions/payment/processors/stripe.py index d786577bd22..745733f01b0 100644 --- a/ecommerce/extensions/payment/processors/stripe.py +++ b/ecommerce/extensions/payment/processors/stripe.py @@ -14,7 +14,6 @@ from ecommerce.extensions.basket.utils import ( basket_add_dynamic_payment_methods_enabled, basket_add_payment_intent_id_attribute, - basket_add_payment_intent_status, get_basket_courses_list, get_billing_address_from_payment_intent_data ) @@ -113,7 +112,7 @@ def create_new_payment_intent_for_basket(self, basket, payment_intent_id): This is used as a reset of the payment to allow payment retries when the intent gets into unexpected states. """ # Cancel existing Payment Intent - stripe.PaymentIntent.cancel(payment_intent_id) + cancelled_payment_intent = stripe.PaymentIntent.cancel(payment_intent_id) # Create a new Payment Intent and add to Basket new_payment_intent = stripe.PaymentIntent.create( @@ -128,13 +127,11 @@ def create_new_payment_intent_for_basket(self, basket, payment_intent_id): new_payment_intent_id = new_payment_intent['id'] logger.info( 'Canceled Payment Intent [%s] and created new Payment Intent [%s] for basket [%d]', - payment_intent_id, + cancelled_payment_intent['id'], new_payment_intent_id, basket.id, ) - new_payment_intent_status = new_payment_intent['status'] basket_add_payment_intent_id_attribute(basket, new_payment_intent_id) - basket_add_payment_intent_status(basket, new_payment_intent_status) basket_add_dynamic_payment_methods_enabled(basket, new_payment_intent) return new_payment_intent @@ -185,7 +182,6 @@ def get_capture_context(self, request): ) basket_add_payment_intent_id_attribute(basket, transaction_id) - basket_add_payment_intent_status(basket, stripe_response['status']) basket_add_dynamic_payment_methods_enabled(basket, stripe_response) # Check if payment intent is in unexpected state, ie. 'requires_action'