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

Commit

Permalink
test: Update test to reflect retrieve first on capture-context
Browse files Browse the repository at this point in the history
  • Loading branch information
julianajlk committed Mar 29, 2024
1 parent c130e86 commit b9e948b
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -335,93 +335,6 @@
"transfer_data": null,
"transfer_group": null
},
"create_resp_in_progress": {
"id": "pi_3OqcQ5H4caH7G0X11y8NKNa4",
"object": "payment_intent",
"amount": 14900,
"amount_capturable": 0,
"amount_details": {
"tip": {
}
},
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"automatic_payment_methods": {
"allow_redirects": "always",
"enabled": true
},
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic",
"charges": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/charges?payment_intent=pi_3OqcQ5H4caH7G0X11y8NKNa4"
},
"client_secret": "pi_3OqcQ5H4caH7G0X11y8NKNa4_secret_kbBQP5DZGLccIESMInIq5GECO",
"confirmation_method": "automatic",
"created": 1709562189,
"currency": "usd",
"customer": null,
"description": "EDX-100011",
"invoice": null,
"last_payment_error": null,
"latest_charge": null,
"livemode": false,
"metadata": {
"order_number": "EDX-100011",
"courses": "[{'course_id': 'course-v1:edX+DemoX+Demo_Course', 'course_name': 'edX Demonstration Course'}]"
},
"next_action": null,
"on_behalf_of": null,
"payment_method": null,
"payment_method_configuration_details": {
"id": "pmc_1LspDWH4caH7G0X1LXrN8QMJ",
"parent": null
},
"payment_method_options": {
"affirm": {
},
"afterpay_clearpay": {
"reference": null
},
"card": {
"installments": null,
"mandate_options": null,
"network": null,
"request_three_d_secure": "automatic"
},
"klarna": {
"preferred_locale": null
},
"link": {
"persistent_token": null
}
},
"payment_method_types": [
"card",
"afterpay_clearpay",
"klarna",
"link",
"affirm"
],
"processing": null,
"receipt_email": null,
"review": null,
"secret_key_confirmation": "required",
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "requires_action",
"transfer_data": null,
"transfer_group": null
},
"modify_resp": {
"id": "pi_3LsftNIadiFyUl1x2TWxaADZ",
"object": "payment_intent",
Expand Down Expand Up @@ -693,6 +606,93 @@
"status": "requires_confirmation",
"transfer_data": null,
"transfer_group": null
},
"retrieve_resp_in_progress": {
"id": "pi_3OqcQ5H4caH7G0X11y8NKNa4",
"object": "payment_intent",
"amount": 14900,
"amount_capturable": 0,
"amount_details": {
"tip": {
}
},
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"automatic_payment_methods": {
"allow_redirects": "always",
"enabled": true
},
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic",
"charges": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/charges?payment_intent=pi_3OqcQ5H4caH7G0X11y8NKNa4"
},
"client_secret": "pi_3OqcQ5H4caH7G0X11y8NKNa4_secret_kbBQP5DZGLccIESMInIq5GECO",
"confirmation_method": "automatic",
"created": 1709562189,
"currency": "usd",
"customer": null,
"description": "EDX-100011",
"invoice": null,
"last_payment_error": null,
"latest_charge": null,
"livemode": false,
"metadata": {
"order_number": "EDX-100011",
"courses": "[{'course_id': 'course-v1:edX+DemoX+Demo_Course', 'course_name': 'edX Demonstration Course'}]"
},
"next_action": null,
"on_behalf_of": null,
"payment_method": null,
"payment_method_configuration_details": {
"id": "pmc_1LspDWH4caH7G0X1LXrN8QMJ",
"parent": null
},
"payment_method_options": {
"affirm": {
},
"afterpay_clearpay": {
"reference": null
},
"card": {
"installments": null,
"mandate_options": null,
"network": null,
"request_three_d_secure": "automatic"
},
"klarna": {
"preferred_locale": null
},
"link": {
"persistent_token": null
}
},
"payment_method_types": [
"card",
"afterpay_clearpay",
"klarna",
"link",
"affirm"
],
"processing": null,
"receipt_email": null,
"review": null,
"secret_key_confirmation": "required",
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "requires_action",
"transfer_data": null,
"transfer_group": null
}
}
}
26 changes: 15 additions & 11 deletions ecommerce/extensions/payment/tests/views/test_stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ecommerce.courses.tests.factories import CourseFactory
from ecommerce.entitlements.utils import create_or_update_course_entitlement
from ecommerce.extensions.basket.constants import PAYMENT_INTENT_ID_ATTRIBUTE
from ecommerce.extensions.basket.utils import basket_add_payment_intent_id_attribute
from ecommerce.extensions.checkout.utils import get_receipt_page_url
from ecommerce.extensions.order.constants import PaymentEventTypeName
from ecommerce.extensions.payment.constants import STRIPE_CARD_TYPE_MAP
Expand Down Expand Up @@ -163,11 +164,11 @@ def test_payment_flow(
confirm_resp,
confirm_resp_in_progress, # pylint: disable=unused-argument
create_resp,
create_resp_in_progress, # pylint: disable=unused-argument
modify_resp,
cancel_resp, # pylint: disable=unused-argument
refund_resp, # pylint: disable=unused-argument
retrieve_addr_resp):
retrieve_addr_resp,
retrieve_resp_in_progress): # pylint: disable=unused-argument
"""
Verify that the stripe payment flow, hitting capture-context and
stripe-checkout urls, results in a basket associated with the correct
Expand Down Expand Up @@ -384,39 +385,42 @@ def test_capture_context_in_progress_payment(
confirm_resp, # pylint: disable=unused-argument
confirm_resp_in_progress, # pylint: disable=unused-argument
create_resp,
create_resp_in_progress,
modify_resp, # pylint: disable=unused-argument
cancel_resp,
refund_resp, # pylint: disable=unused-argument
retrieve_addr_resp): # pylint: disable=unused-argument
retrieve_addr_resp, # pylint: disable=unused-argument
retrieve_resp_in_progress):
"""
Verify that hitting capture-context with a Payment Intent that already exists but it's
in 'requires_action' state, that a new Payment Intent is created and associated to the basket.
"""
basket = self.create_basket(product_class=SEAT_PRODUCT_CLASS_NAME)
payment_intent_id = retrieve_resp_in_progress['id']
basket_add_payment_intent_id_attribute(basket, payment_intent_id)

with mock.patch('stripe.PaymentIntent.create') as mock_create:
mock_create.return_value = create_resp_in_progress
with mock.patch('stripe.PaymentIntent.retrieve') as mock_retrieve:
mock_retrieve.return_value = retrieve_resp_in_progress
# If Payment Intent gets into 'requires_action' status without confirmation from the BNPL,
# we create a new Payment Intent for retry payment in the MFE
with mock.patch('stripe.PaymentIntent.cancel') as mock_cancel:
mock_cancel.return_value = cancel_resp
with mock.patch('stripe.PaymentIntent.create') as mock_create_new:
mock_create_new.return_value = create_resp
with mock.patch('stripe.PaymentIntent.create') as mock_create:
mock_create.return_value = create_resp
response = self.client.get(self.capture_context_url)

# Basket should have the new Payment Intent ID
mock_create_new.assert_called_once()
mock_create.assert_called_once()
mock_cancel.assert_called_once()
payment_intent_id = BasketAttribute.objects.get(
basket=basket,
attribute_type__name=PAYMENT_INTENT_ID_ATTRIBUTE
).value_text
assert payment_intent_id == mock_create_new.return_value['id']
assert payment_intent_id == mock_create.return_value['id']

# Response should have the same order_number and new client secret
assert response.json() == {
'capture_context': {
'key_id': mock_create_new.return_value['client_secret'],
'key_id': mock_create.return_value['client_secret'],
'order_id': basket.order_number,
}
}
Expand Down

0 comments on commit b9e948b

Please sign in to comment.