Skip to content

Commit 23d3bed

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent af7e40e commit 23d3bed

2 files changed

Lines changed: 40 additions & 31 deletions

File tree

payments/stripe/providers.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,20 @@ def create_session(self, payment):
155155
session_data.update({"customer_email": payment.billing_email})
156156

157157
# Patch session with billing address if available
158-
if any([
159-
payment.billing_address_1,
160-
payment.billing_city,
161-
payment.billing_postcode,
162-
payment.billing_country_code,
163-
]):
158+
if any(
159+
[
160+
payment.billing_address_1,
161+
payment.billing_city,
162+
payment.billing_postcode,
163+
payment.billing_country_code,
164+
]
165+
):
164166
billing_address_collection = "required"
165167
# Pre-fill address if we have it
166168
if payment.billing_country_code:
167-
session_data["billing_address_collection"] = billing_address_collection
169+
session_data["billing_address_collection"] = (
170+
billing_address_collection
171+
)
168172

169173
# Patch session with billing name and address in metadata
170174
metadata = {}
@@ -186,7 +190,7 @@ def create_session(self, payment):
186190
metadata["billing_country_area"] = payment.billing_country_area
187191
if payment.billing_phone:
188192
metadata["billing_phone"] = str(payment.billing_phone)
189-
193+
190194
if metadata:
191195
session_data["metadata"] = metadata
192196
try:
@@ -236,7 +240,7 @@ def status(self, payment):
236240
def get_line_items(self, payment) -> list:
237241
order_no = payment.token if self.use_token else payment.pk
238242
product_data = StripeProductData(name=f"Order #{order_no}")
239-
243+
240244
# Add description if available
241245
if payment.description:
242246
product_data.description = payment.description
@@ -341,11 +345,11 @@ def autocomplete_with_wallet(self, payment):
341345
"payment_id": payment.pk if not self.use_token else None,
342346
},
343347
}
344-
348+
345349
# Add description if available (visible in Stripe Dashboard)
346350
if payment.description:
347351
intent_params["description"] = payment.description
348-
352+
349353
intent = stripe.PaymentIntent.create(**intent_params)
350354

351355
payment.transaction_id = intent.id

payments/stripe/test_recurring.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from __future__ import annotations
66

77
from decimal import Decimal
8-
from unittest.mock import Mock
98
from unittest.mock import patch
109

1110
import pytest
@@ -25,12 +24,12 @@
2524
class MockStripeIntent(dict):
2625
"""
2726
JSON-serializable mock for Stripe PaymentIntent objects.
28-
27+
2928
Stripe objects are dict-like and JSON-serializable. This mock replicates
3029
that behavior so tests can store intents in payment.attrs without
3130
triggering "Object of type Mock is not JSON serializable" errors.
3231
"""
33-
32+
3433
def __getattr__(self, key):
3534
try:
3635
value = self[key]
@@ -68,10 +67,12 @@ def test_autocomplete_with_wallet_success(self, mock_pi_create):
6867
)
6968

7069
# Mock successful PaymentIntent
71-
mock_pi_create.return_value = MockStripeIntent({
72-
"id": "pi_test_123",
73-
"status": "succeeded",
74-
})
70+
mock_pi_create.return_value = MockStripeIntent(
71+
{
72+
"id": "pi_test_123",
73+
"status": "succeeded",
74+
}
75+
)
7576

7677
# Execute recurring charge
7778
self.provider.autocomplete_with_wallet(payment)
@@ -123,14 +124,16 @@ def test_autocomplete_with_wallet_requires_3ds(self, mock_pi_create):
123124
)
124125

125126
# Mock PaymentIntent requiring 3DS
126-
mock_pi_create.return_value = MockStripeIntent({
127-
"id": "pi_test_123",
128-
"status": "requires_action",
129-
"next_action": {
130-
"type": "redirect_to_url",
131-
"redirect_to_url": {"url": "https://stripe.com/3ds/authenticate"},
132-
},
133-
})
127+
mock_pi_create.return_value = MockStripeIntent(
128+
{
129+
"id": "pi_test_123",
130+
"status": "requires_action",
131+
"next_action": {
132+
"type": "redirect_to_url",
133+
"redirect_to_url": {"url": "https://stripe.com/3ds/authenticate"},
134+
},
135+
}
136+
)
134137

135138
# Should raise RedirectNeeded
136139
with pytest.raises(RedirectNeeded) as exc_info:
@@ -149,11 +152,13 @@ def test_autocomplete_with_wallet_card_declined(self, mock_pi_create):
149152
)
150153

151154
# Mock declined payment
152-
mock_pi_create.return_value = MockStripeIntent({
153-
"id": "pi_test_123",
154-
"status": "requires_payment_method",
155-
"last_payment_error": {"message": "Your card was declined"},
156-
})
155+
mock_pi_create.return_value = MockStripeIntent(
156+
{
157+
"id": "pi_test_123",
158+
"status": "requires_payment_method",
159+
"last_payment_error": {"message": "Your card was declined"},
160+
}
161+
)
157162

158163
# Execute - should not raise
159164
self.provider.autocomplete_with_wallet(payment)

0 commit comments

Comments
 (0)