Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
fix: Passing paypal variable through to checkout if set (#4169)
Browse files Browse the repository at this point in the history
* fix: Passing paypal variable through to checkout if set

SONIC-501

* fix: semi-temp fix to pin pip/pip-tools versions to prevent pip install failures (#4170)

---------

Co-authored-by: Chris Pappas <[email protected]>
  • Loading branch information
grmartin and christopappas authored Jul 5, 2024
1 parent c211842 commit cf1966b
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/migrations-mysql8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
mysql -V
- name: Install Python dependencies
run: |
pip install pip==21.2.1 --upgrade # set pip version to be compatible with deprecated pip version syntax
pip install -r requirements/pip_tools.txt
pip install -r requirements/production.txt
pip uninstall -y mysqlclient
Expand Down
29 changes: 24 additions & 5 deletions ecommerce/coupons/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,16 @@ def tearDown(self):
super().tearDown()
responses.reset()

def redeem_url_with_params(self, code=COUPON_CODE, consent_token=None):
def redeem_url_with_params(self, code=COUPON_CODE, consent_token=None, other_qs_params=None):
""" Constructs the coupon redemption URL with the proper string query parameters. """
params = {
'code': code,
'sku': self.stock_record.partner_sku,
}
if consent_token is not None:
params['consent_token'] = consent_token
if other_qs_params is not None:
params.update(other_qs_params)
return format_url(base=self.redeem_url, params=params)

def create_coupon_and_get_code(
Expand Down Expand Up @@ -387,9 +389,12 @@ def create_coupon_and_get_code(
self.assertEqual(Voucher.objects.filter(code=coupon_code).count(), 1)
return coupon_code, coupon

def redeem_coupon(self, code=COUPON_CODE, consent_token=None):
def redeem_coupon(self, code=COUPON_CODE, consent_token=None, other_qs_params=None):
self.request.user = self.user
return self.client.get(self.redeem_url_with_params(code=code, consent_token=consent_token))
return self.client.get(self.redeem_url_with_params(
code=code,
consent_token=consent_token,
other_qs_params=other_qs_params))

def assert_redirects_to_receipt_page(self, code=COUPON_CODE, consent_token=None):
response = self.redeem_coupon(code=code, consent_token=consent_token)
Expand All @@ -406,9 +411,10 @@ def assert_redirects_to_receipt_page(self, code=COUPON_CODE, consent_token=None)

self.assertRedirects(response, expected_url, status_code=302, fetch_redirect_response=False)

def assert_redemption_page_redirects(self, expected_url, target=200, code=COUPON_CODE, consent_token=None):
def assert_redemption_page_redirects(self, expected_url, target=200, code=COUPON_CODE,
consent_token=None, other_qs_params=None):
""" Verify redirect from redeem page to expected page. """
response = self.redeem_coupon(code=code, consent_token=consent_token)
response = self.redeem_coupon(code=code, consent_token=consent_token, other_qs_params=other_qs_params)
self.assertRedirects(
response, expected_url, status_code=302, target_status_code=target, fetch_redirect_response=False
)
Expand Down Expand Up @@ -495,6 +501,19 @@ def test_basket_redirect_discount_code(self):
self.create_coupon(catalog=self.catalog, code=COUPON_CODE, benefit_value=5)
self.assert_redemption_page_redirects(self.get_coupon_redeem_success_expected_redirect_url())

@responses.activate
def test_basket_redirect_discount_code_with_paypal(self):
""" Verify the view redirects to the basket view when a discount code is provided with a paypal qs param. """
self.mock_course_api_response(course=self.course)
self.mock_account_api(self.request, self.user.username, data={'is_active': True})
self.mock_access_token_response()

self.create_coupon(catalog=self.catalog, code=COUPON_CODE, benefit_value=5)
self.assert_redemption_page_redirects(
self.get_coupon_redeem_success_expected_redirect_url() + '&paypal_redirect=1',
other_qs_params={'paypal_redirect': '1'}
)

@override_flag(REDIRECT_WITH_WAFFLE_TESTING_QUERYSTRING, active=True)
@responses.activate
def test_basket_redirect_discount_code_with_waffle(self):
Expand Down
9 changes: 9 additions & 0 deletions ecommerce/coupons/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,16 @@ def get(self, request): # pylint: disable=too-many-statements
# and should not display the payment form before making that determination.
# TODO: It would be cleaner if the user could be redirected to their final destination up front.
redirect_url = get_payment_microfrontend_or_basket_url(self.request) + "?coupon_redeem_redirect=1"

# Check for the paypal_redirect=1 parameter from the ecommerce checkout and add it to the
# redirect URL if present
paypal_redirect = request.GET.get('paypal_redirect')

if paypal_redirect:
redirect_url += "&paypal_redirect=1"

redirect_url = add_stripe_flag_to_url(redirect_url, self.request)

return HttpResponseRedirect(redirect_url)


Expand Down
10 changes: 10 additions & 0 deletions ecommerce/extensions/basket/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ def test_basket_with_utm_params(self):
expected_url = self.get_full_url(reverse('basket:summary')) + '?utm_source=test'
self.assertEqual(response.url, expected_url)

def test_basket_with_paypal_param(self):
""" Verify the basket includes paypal param after redirect. """
products = ProductFactory.create_batch(3, stockrecords__partner=self.partner)
response = self._get_response(
[product.stockrecords.first().partner_sku for product in products],
paypal_redirect='1',
)
expected_url = self.get_full_url(reverse('basket:summary')) + '?paypal_redirect=1'
self.assertEqual(response.url, expected_url)

@responses.activate
def test_redirect_to_basket_summary(self):
"""
Expand Down
9 changes: 9 additions & 0 deletions ecommerce/extensions/basket/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,15 @@ def _redirect_response_to_basket_or_payment(self, request, invalid_code=None):
redirect_url = get_payment_microfrontend_or_basket_url(request)
redirect_url = add_utm_params_to_url(redirect_url, list(self.request.GET.items()))
redirect_url = add_invalid_code_message_to_url(redirect_url, invalid_code)

# Check for the paypal_redirect=1 parameter from the ecommerce checkout and add it to the
# redirect URL if present
paypal_redirect = request.GET.get('paypal_redirect')

if paypal_redirect:
redirect_url += '&' if '?' in redirect_url else '?'
redirect_url += 'paypal_redirect=1'

redirect_url = add_stripe_flag_to_url(redirect_url, request)

return HttpResponseRedirect(redirect_url, status=303)
Expand Down
2 changes: 1 addition & 1 deletion requirements/pip_tools.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-c constraints.txt

# Dependencies to run compile tools
pip-tools # Contains pip-compile, used to generate pip requirements files
pip-tools==6.0 # Contains pip-compile, used to generate pip requirements files
2 changes: 1 addition & 1 deletion requirements/pip_tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ click==8.1.3
# via pip-tools
packaging==23.1
# via build
pip-tools==6.13.0
pip-tools==6.0
# via -r requirements/pip_tools.in
pyproject-hooks==1.0.0
# via build
Expand Down

0 comments on commit cf1966b

Please sign in to comment.