-
-
Notifications
You must be signed in to change notification settings - Fork 538
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_payment_stripe module #1151
Open
mjavint
wants to merge
45
commits into
OCA:16.0
Choose a base branch
from
BinhexTeam:16.0-add-recurring_payments_stripe
base: 16.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,549
−6
Open
Changes from 11 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
e97eaf9
[ADD] Add recurring payments with stripe
mjavint e47bd6c
[FIX] Fixed recurring payments
mjavint e72ee4b
[FIX] Resolved all suggestion
mjavint ea7a9b2
[ADD] Add precommit rules
mjavint fa09388
Merge pull request #2 from BinhexTeam/16.0-dev
mjavint 6007122
[ADD] Add stripe library
mjavint d21d398
[ADD] Add stripe library
mjavint 02b0b61
Merge pull request #4 from BinhexTeam/16.0-dev
mjavint ea94dbd
[FIX] Fixed precommit error
mjavint b87b473
[FIX] Fixed precommit error
mjavint e0d75a0
[FIX] Fixed precommit flake error
mjavint ec6d741
[FIX] Fixed translation error in account_move.py and spaces inside su…
mjavint d359985
[FIX] Fixed translation error in account_move.py and spaces inside su…
mjavint 75ac6af
[FIX] Fixed payment transaction and design modular
mjavint ea45267
[FIX] Fixed payment transaction and design modular (#6)
mjavint deb9ee4
[FIX] Fixed test implementation
mjavint 02fa75e
[FIX] Fixed test implementation
mjavint a386028
16.0 dev (#7)
mjavint 2c48daa
[FIX] Fixed test implementation
mjavint 988f4b7
Merge remote-tracking branch 'origin/16.0-add-recurring_payments_stri…
mjavint 71175d7
16.0 dev (#8)
mjavint 5024bfa
Merge remote-tracking branch 'origin/16.0-add-recurring_payments_stri…
mjavint 94b7070
[FIX] Fixed test implementation
mjavint 1f8580c
16.0 dev (#9)
mjavint 2e59f9b
[FIX] Fixed test implementation
mjavint d466972
Merge remote-tracking branch 'origin/16.0-add-recurring_payments_stri…
mjavint eee35fd
16.0 dev (#10)
mjavint 4616bf8
[FIX] Fixed precommit
mjavint a3016a5
Merge remote-tracking branch 'origin/16.0-add-recurring_payments_stri…
mjavint db73567
16.0 dev (#11)
mjavint 917df24
[FIX] Fixed implementation
mjavint dec7546
Merge remote-tracking branch 'origin/16.0-add-recurring_payments_stri…
mjavint 81d188b
16.0 dev (#12)
mjavint b438fcb
16.0 dev (#13)
mjavint 64530b6
Merge remote-tracking branch 'origin/16.0-add-recurring_payments_stri…
mjavint 6042cd0
[FIX] Fixed implementation tests
mjavint 866ef26
Merge branch '16.0-dev' into 16.0-add-recurring_payments_stripe
mjavint 5329d7c
[FIX] Fixed implementation tests branch
mjavint 0b8a36e
# This is a combination of 12 commits.
mjavint 4a83366
[FIX] Fixed and squash old commit
mjavint 8cc3e3d
[FIX] Implementations used payment.token stripe
mjavint 8f9012a
[FIX] Fixed precommit
mjavint e284c64
[FIX] Fixed test
mjavint 501c0d3
[FIX] Fixed test
mjavint 60fda87
[FIX] Fixed test create payment
mjavint File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,11 @@ | |
|
||
/* | ||
:Author: David Goodger ([email protected]) | ||
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ | ||
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ | ||
:Copyright: This stylesheet has been placed in the public domain. | ||
|
||
Default cascading style sheet for the HTML output of Docutils. | ||
Despite the name, some widely supported CSS2 features are used. | ||
|
||
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to | ||
customize this style sheet. | ||
|
@@ -274,7 +275,7 @@ | |
margin-left: 2em ; | ||
margin-right: 2em } | ||
|
||
pre.code .ln { color: grey; } /* line numbers */ | ||
pre.code .ln { color: gray; } /* line numbers */ | ||
pre.code, code { background-color: #eeeeee } | ||
pre.code .comment, code .comment { color: #5C6576 } | ||
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } | ||
|
@@ -300,7 +301,7 @@ | |
span.pre { | ||
white-space: pre } | ||
|
||
span.problematic { | ||
span.problematic, pre.problematic { | ||
color: red } | ||
|
||
span.section-subtitle { | ||
|
@@ -366,7 +367,7 @@ <h1 class="title">Contract from Sale</h1> | |
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:00fb3cdc565442ffcd3351e97d0516ce6f4ceb55402981b183f7e717a1e23173 | ||
!! source digest: sha256:c2e49dd78cebc553bbe7e5bfa2c8658e29e120878e688512e9599b43144815dd | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> | ||
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/contract/tree/16.0/contract_sale"><img alt="OCA/contract" src="https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/contract-16-0/contract-16-0-contract_sale"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/contract&target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p> | ||
<p>This module allows access to contracts for sale employees without account | ||
|
@@ -428,7 +429,9 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2> | |
<div class="section" id="maintainers"> | ||
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2> | ||
<p>This module is maintained by the OCA.</p> | ||
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a> | ||
<a class="reference external image-reference" href="https://odoo-community.org"> | ||
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /> | ||
</a> | ||
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use.</p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
============================== | ||
Recurring Payments with Stripe | ||
============================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:7aacc5b46917b14e43404143f0ccd1519d1411d580330b8eb8a8ef608fe3a5a1 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github | ||
:target: https://github.com/OCA/contract/tree/16.0/recurring_payments_stripe | ||
:alt: OCA/contract | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/contract-16-0/contract-16-0-recurring_payments_stripe | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/contract&target_branch=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/contract/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/contract/issues/new?body=module:%20recurring_payments_stripe%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Binhex | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
.. |maintainer-mjavint| image:: https://github.com/mjavint.png?size=40px | ||
:target: https://github.com/mjavint | ||
:alt: mjavint | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-mjavint| | ||
|
||
This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/16.0/recurring_payments_stripe>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "Recurring Payments with Stripe", | ||
"version": "16.0.1.0.0", | ||
"summary": """ Recurring Payments with Stripe """, | ||
"author": "Binhex, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/contract", | ||
"license": "AGPL-3", | ||
"category": "Subscription Management", | ||
"depends": ["subscription_oca", "payment_stripe", "payment"], | ||
"data": [ | ||
"views/sale_subscription_views.xml", | ||
"data/ir_cron.xml", | ||
], | ||
"installable": True, | ||
"auto_install": False, | ||
"external_dependencies": {"python": ["stripe"]}, | ||
"maintainers": ["mjavint"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<odoo noupdate="1"> | ||
<!-- Cron Job para Procesar Facturas Vencidas Diariamente --> | ||
<record id="ir_cron_process_due_invoices" model="ir.cron"> | ||
<field name="name">Process Overdue Invoices for Subscriptions</field> | ||
<field name="model_id" ref="recurring_payments_stripe.model_account_move" /> | ||
<field name="state">code</field> | ||
<field name="code">model.cron_process_due_invoices()</field> | ||
<field name="interval_number">1</field> | ||
<field name="interval_type">days</field> | ||
<field name="numbercall">-1</field> | ||
<field name="active">True</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import sale_subscription | ||
from . import account_move |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import logging | ||
|
||
import stripe | ||
|
||
from odoo import _, api, models | ||
from odoo.exceptions import UserError | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class AccountMove(models.Model): | ||
_inherit = "account.move" | ||
|
||
def action_register_payment(self): | ||
""" | ||
Override `action_register_payment` to automatically process Stripe | ||
payment on subscriptions. | ||
""" | ||
for invoice in self: | ||
# Find the subscription associated with the invoice, if it exists | ||
subscription = invoice.subscription_id | ||
|
||
# Check if the subscription is recurring and has a payment method | ||
if subscription and subscription.charge_automatically: | ||
provider = subscription.provider_id | ||
stripe.api_key = provider.stripe_secret_key | ||
token = self.env["payment.token"].search( | ||
[("provider_id", "=", provider.id)] | ||
) | ||
try: | ||
# Create the PaymentIntent and confirm it immediately | ||
payment_intent = stripe.PaymentIntent.create( | ||
# Stripe usa centavos | ||
amount=int(invoice.amount_total * 100), | ||
currency=invoice.currency_id.name.lower(), | ||
customer=token.provider_ref, | ||
payment_method=token.stripe_payment_method, | ||
# Para pagos automáticos sin intervención del usuario | ||
off_session=True, | ||
# Confirmar el PaymentIntent inmediatamente | ||
confirm=True, | ||
metadata={"odoo_invoice_id": str(invoice.id)}, | ||
) | ||
|
||
# Manejar el resultado del PaymentIntent | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments should be in English. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed translation problem in the comment |
||
if payment_intent["status"] == "succeeded": | ||
# If the payment is successful, record the payment on the invoice | ||
Payment = self.env["account.payment"].sudo() | ||
payment_vals = { | ||
"journal_id": self.env["account.journal"] | ||
.search([("type", "=", "bank")], limit=1) | ||
.id, | ||
"amount": invoice.amount_total, | ||
"payment_type": "inbound", | ||
"partner_type": "customer", | ||
"partner_id": invoice.partner_id.id, | ||
"payment_method_id": self.env.ref( | ||
"account.account_payment_method_manual_in" | ||
).id, | ||
"ref": f"Stripe PaymentIntent {payment_intent['id']}", | ||
} | ||
payment = Payment.create(payment_vals) | ||
payment.action_post() | ||
invoice.payment_state = "paid" | ||
elif payment_intent["status"] == "requires_action": | ||
raise UserError( | ||
_("Payment requires additional authentication (3D Secure).") | ||
) | ||
else: | ||
raise UserError( | ||
f"Stripe payment error: {payment_intent['status']}" | ||
) | ||
|
||
except stripe.StripeError as e: | ||
raise UserError(f"Stripe error: {e}") from e | ||
|
||
else: | ||
return super(AccountMove, self).action_register_payment() | ||
|
||
@api.model | ||
def cron_process_due_invoices(self): | ||
"""Process payment of overdue invoices for recurring subscriptions.""" | ||
|
||
for invoice in self: | ||
# Find the subscription associated with the invoice | ||
subscription = invoice.subscription_id | ||
|
||
# Check if it's a recurring subscription with Stripe | ||
if subscription and subscription.charge_automatically: | ||
try: | ||
# Register the payment | ||
invoice.action_register_payment() | ||
except Exception as e: | ||
_logger.error(f"Error Processing Due Invoices: {str(e)}") | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import stripe | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class SaleSubscription(models.Model): | ||
_inherit = "sale.subscription" | ||
|
||
charge_automatically = fields.Boolean() | ||
stripe_customer = fields.Char("Stripe Customer ID") | ||
provider_id = fields.Many2one( | ||
string="Provider_id", | ||
domain=[("code", "=", "stripe")], | ||
comodel_name="payment.provider", | ||
) | ||
|
||
def create_stripe_customer(self): | ||
provider = self.provider_id | ||
if provider: | ||
stripe.api_key = provider.stripe_secret_key | ||
|
||
if not self.stripe_customer: | ||
customer = stripe.Customer.create( | ||
email=self.env.user.email, | ||
name=self.env.user.name, | ||
metadata={"odoo_subscription": str(self.id)}, | ||
) | ||
self.stripe_customer = customer["id"] | ||
return self.stripe_customer | ||
|
||
@api.onchange("charge_automatically") | ||
def _onchange_charge_automatically(self): | ||
for record in self: | ||
if record.charge_automatically: | ||
record.create_stripe_customer() | ||
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the spacing before and after the
"""
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed spaces before and after within summary content