Skip to content

Commit b0d8ba0

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

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

payments/stripe/providers.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def autocomplete_with_wallet(self, payment):
278278
279279
This method charges a stored payment method without user interaction.
280280
Uses get_renew_data() to retrieve both payment_method_id and customer_id.
281-
281+
282282
If 3D Secure or other authentication is required, raises RedirectNeeded.
283283
"""
284284
stripe.api_key = self.api_key
@@ -290,7 +290,7 @@ def autocomplete_with_wallet(self, payment):
290290

291291
payment_method_id = renew_data["token"]
292292
customer_id = renew_data.get("customer_id")
293-
293+
294294
if not customer_id:
295295
raise PaymentError(
296296
"No customer_id found for recurring payment. "
@@ -311,7 +311,7 @@ def autocomplete_with_wallet(self, payment):
311311
"payment_id": payment.pk if not self.use_token else None,
312312
},
313313
}
314-
314+
315315
intent = stripe.PaymentIntent.create(**intent_params)
316316

317317
payment.transaction_id = intent.id
@@ -329,8 +329,7 @@ def autocomplete_with_wallet(self, payment):
329329
if intent.next_action and intent.next_action.type == "redirect_to_url":
330330
redirect_url = intent.next_action.redirect_to_url.url
331331
raise RedirectNeeded(redirect_url)
332-
else:
333-
raise PaymentError(f"Payment requires action: {intent.next_action}")
332+
raise PaymentError(f"Payment requires action: {intent.next_action}")
334333

335334
elif intent.status in ["requires_payment_method", "canceled"]:
336335
# Payment failed
@@ -356,7 +355,7 @@ def autocomplete_with_wallet(self, payment):
356355
def _store_payment_method_from_session(self, payment, session_info):
357356
"""
358357
Extract and store PaymentMethod and Customer from successful Checkout Session.
359-
358+
360359
Called after payment is confirmed to store payment method for future recurring charges.
361360
Extracts customer_id from PaymentIntent (created by Stripe Checkout) and passes
362361
it to implementer via set_renew_token().
@@ -398,7 +397,9 @@ def _store_payment_method_from_session(self, payment, session_info):
398397
except stripe.error.StripeError as e:
399398
# Failed to retrieve payment method, but payment was successful
400399
# Don't fail the payment, just log the error
401-
logger.exception("Failed to store PaymentMethod for payment %s: %s", payment.id, e)
400+
logger.exception(
401+
"Failed to store PaymentMethod for payment %s: %s", payment.id, e
402+
)
402403

403404
def process_data(self, payment, request):
404405
"""Processes the event sent by stripe.

payments/stripe/test_recurring.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
"""
22
Tests for Stripe recurring payments (autocomplete_with_wallet).
33
"""
4+
5+
from __future__ import annotations
6+
47
from decimal import Decimal
5-
from unittest.mock import Mock, patch
8+
from unittest.mock import Mock
9+
from unittest.mock import patch
610

711
from django.test import TestCase
812

9-
from payments import PaymentError, PaymentStatus, RedirectNeeded
10-
from testapp.testmain.models import Payment, Wallet
13+
from payments import PaymentError
14+
from payments import PaymentStatus
15+
from payments import RedirectNeeded
16+
from testapp.testmain.models import Payment
17+
from testapp.testmain.models import Wallet
1118

1219
from .providers import StripeProviderV3
1320

@@ -173,4 +180,3 @@ def test_autocomplete_with_wallet_no_token(self):
173180
self.provider.autocomplete_with_wallet(payment)
174181

175182
self.assertIn("No payment method token", str(cm.exception))
176-

payments/test_wallet.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
These tests document the expected behavior of the wallet interface
55
for server-initiated recurring payments.
66
"""
7+
8+
from __future__ import annotations
9+
710
from decimal import Decimal
811
from unittest.mock import Mock
912

@@ -650,4 +653,3 @@ def test_erased_wallet_cannot_be_used(self):
650653
token = payment.get_renew_token()
651654

652655
self.assertIsNone(token) # Won't return token from erased wallet
653-

0 commit comments

Comments
 (0)