Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][ADD] recurring_payments_stripe: Add recurring payments with stripe #2

Merged
merged 4 commits into from
Nov 28, 2024

Conversation

mjavint
Copy link
Collaborator

@mjavint mjavint commented Nov 14, 2024

No description provided.

Copy link
Member

@Christian-RB Christian-RB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should take a look to the next file:
https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#review
Initial comments:

  • README generator missing
  • Squash your commits into just one
  • Install pre-commit and run it on your module files (here you will need to fix some of the next items in order to run it successfully)
  • the commit msg should be: "[ADD] recurring_payments_stripe: Add recurring payments with stripe"
  • the PR name: "[16.0][ADD] recurring_payments_stripe: Add recurring payments with stripe"
  • No code comented "Unless is documentation"
  • All the code should be in English

recurring_payments_stripe/__manifest__.py Outdated Show resolved Hide resolved
recurring_payments_stripe/data/ir_cron.xml Outdated Show resolved Hide resolved
Comment on lines 15 to 70
# def stripe_pay_invoice(self):
# """Paga la factura en Stripe si `is_recurrent` está activado en la suscripción."""
# for invoice in self:
# subscription = invoice.invoice_date and self.env[
# "sale.subscription"
# ].search([("code", "=", invoice.invoice_date)], limit=1)
# if (
# subscription
# and subscription.is_recurrent
# and subscription.stripe_customer
# ):
# provider = self.env["payment.provider"].search(
# [("code", "=", "stripe")],
# )
# stripe.api_key = provider.stripe_secret_key
# token = self.env["payment.token"].search(
# [("provider_id", "=", provider.id)]
# )
# try:
# # Crea un PaymentIntent en Stripe para el monto de la factura
# payment_intent = stripe.PaymentIntent.create(
# # Stripe maneja montos en centavos
# amount=int(invoice.amount_total * 100),
# currency=invoice.currency_id.name.lower(),
# customer=token.provider_ref,
# payment_method=token.stripe_payment_method,
# payment_method_types=["card"],
# # Para pagos automáticos sin intervención del usuario
# off_session=True,
# # Confirmar el PaymentIntent inmediatamente
# confirm=True,
# metadata={"odoo_invoice_id": invoice.id},
# )

# # Confirmar el pago y actualizar el estado de la factura en Odoo
# if payment_intent["status"] == "succeeded":
# invoice.action_post()
# invoice.payment_state = "paid"
# else:
# raise Exception(
# f"Error en el pago de Stripe: {payment_intent['status']}"
# )

# except stripe.StripeError as e:
# raise UserError(f"Stripe error: {e.user_message or str(e)}")

# def action_post(self):
# """Sobreescribe el método `action_post` para procesar el pago automático si `is_recurrent` está activo."""
# res = super(AccountMove, self).action_post()
# for invoice in self:
# subscription = self.env["sale.subscription"].search(
# [("code", "=", invoice.invoice_date)], limit=1
# )
# if subscription and subscription.is_recurrent:
# invoice.stripe_pay_invoice()
# return res
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

Suggested change
# def stripe_pay_invoice(self):
# """Paga la factura en Stripe si `is_recurrent` está activado en la suscripción."""
# for invoice in self:
# subscription = invoice.invoice_date and self.env[
# "sale.subscription"
# ].search([("code", "=", invoice.invoice_date)], limit=1)
# if (
# subscription
# and subscription.is_recurrent
# and subscription.stripe_customer
# ):
# provider = self.env["payment.provider"].search(
# [("code", "=", "stripe")],
# )
# stripe.api_key = provider.stripe_secret_key
# token = self.env["payment.token"].search(
# [("provider_id", "=", provider.id)]
# )
# try:
# # Crea un PaymentIntent en Stripe para el monto de la factura
# payment_intent = stripe.PaymentIntent.create(
# # Stripe maneja montos en centavos
# amount=int(invoice.amount_total * 100),
# currency=invoice.currency_id.name.lower(),
# customer=token.provider_ref,
# payment_method=token.stripe_payment_method,
# payment_method_types=["card"],
# # Para pagos automáticos sin intervención del usuario
# off_session=True,
# # Confirmar el PaymentIntent inmediatamente
# confirm=True,
# metadata={"odoo_invoice_id": invoice.id},
# )
# # Confirmar el pago y actualizar el estado de la factura en Odoo
# if payment_intent["status"] == "succeeded":
# invoice.action_post()
# invoice.payment_state = "paid"
# else:
# raise Exception(
# f"Error en el pago de Stripe: {payment_intent['status']}"
# )
# except stripe.StripeError as e:
# raise UserError(f"Stripe error: {e.user_message or str(e)}")
# def action_post(self):
# """Sobreescribe el método `action_post` para procesar el pago automático si `is_recurrent` está activo."""
# res = super(AccountMove, self).action_post()
# for invoice in self:
# subscription = self.env["sale.subscription"].search(
# [("code", "=", invoice.invoice_date)], limit=1
# )
# if subscription and subscription.is_recurrent:
# invoice.stripe_pay_invoice()
# return res

recurring_payments_stripe/models/sale_subscription.py Outdated Show resolved Hide resolved
recurring_payments_stripe/models/sale_subscription.py Outdated Show resolved Hide resolved
recurring_payments_stripe/models/account_move.py Outdated Show resolved Hide resolved
recurring_payments_stripe/models/account_move.py Outdated Show resolved Hide resolved
recurring_payments_stripe/models/account_move.py Outdated Show resolved Hide resolved
@Christian-RB Christian-RB changed the title [IMP] Implement recurring payment [16.0][ADD] recurring_payments_stripe: Add recurring payments with stripe Nov 15, 2024
@mjavint mjavint requested a review from Christian-RB November 28, 2024 20:54
@mjavint mjavint merged commit fa09388 into 16.0-pre Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants