Skip to content

Commit

Permalink
[FIX] Fixed implementation tests branch
Browse files Browse the repository at this point in the history
  • Loading branch information
mjavint committed Jan 6, 2025
1 parent 866ef26 commit 5329d7c
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions recurring_payment_stripe/tests/test_payment_stripe_recurring.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import stripe

from odoo import fields
from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase


Expand Down Expand Up @@ -152,11 +151,8 @@ def test_action_register_payment(self):
f"Invoice {self.invoice.id} should be in draft state",
)

with self.assertRaises(UserError) as context:
self.invoice.cron_process_due_invoices()
self.assertIn("Payment failed with status", str(context.exception))

self.invoice.cron_process_due_invoices()

self.assertTrue(
self.invoice.state == "posted",
f"Invoice {self.invoice.id} should be posted",
Expand All @@ -171,22 +167,20 @@ def test_stripe_payment_intent(self):
provider = self.sub8.provider_id
stripe.api_key = provider.stripe_secret_key
token = self.invoice._create_token(self.sub8)
payment_intent: stripe.PaymentIntent = None
with self.assertRaises(UserError) as context:
payment_intent = stripe.PaymentIntent.create(
# Stripe uses cents
amount=int(self.invoice.amount_total * 100),
currency=self.invoice.currency_id.name.lower(),
customer=token.provider_ref,
payment_method=token.stripe_payment_method,
automatic_payment_methods={"enabled": True},
# For automatic payments without user intervention
off_session=True,
# Confirm the PaymentIntent immediately
confirm=True,
metadata={"odoo_invoice_id": str(self.invoice.id)},
)
self.assertIn("Payment failed with status", str(context.exception))

payment_intent = stripe.PaymentIntent.create(
# Stripe uses cents
amount=int(self.invoice.amount_total * 100),
currency=self.invoice.currency_id.name.lower(),
customer=token.provider_ref,
payment_method=token.stripe_payment_method,
automatic_payment_methods={"enabled": True},
# For automatic payments without user intervention
off_session=True,
# Confirm the PaymentIntent immediately
confirm=True,
metadata={"odoo_invoice_id": str(self.invoice.id)},
)

# Check if the payment was successful
self.assertEqual(payment_intent.status, "succeeded")

0 comments on commit 5329d7c

Please sign in to comment.