Skip to content

Commit

Permalink
[MIG] payment_cielo: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
corredato committed Oct 9, 2024
1 parent 6325545 commit 350994e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 107 deletions.
16 changes: 8 additions & 8 deletions payment_cielo/README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
============
Payent Cielo
============
=============
Payment Cielo
=============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Expand All @@ -17,13 +17,13 @@ Payent Cielo
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--brazil-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-brazil/tree/12.0/payment_cielo
:target: https://github.com/OCA/l10n-brazil/tree/14.0/payment_cielo
:alt: OCA/l10n-brazil
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-brazil-12-0/l10n-brazil-12-0-payment_cielo
:target: https://translation.odoo-community.org/projects/l10n-brazil-14-0/l10n-brazil-14-0-payment_cielo
: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/l10n-brazil&target_branch=12.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-brazil&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -67,7 +67,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-brazil/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/l10n-brazil/issues/new?body=module:%20payment_cielo%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/l10n-brazil/issues/new?body=module:%20payment_cielo%0Aversion:%2014.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.

Expand Down Expand Up @@ -112,6 +112,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-DiegoParadeda|

This module is part of the `OCA/l10n-brazil <https://github.com/OCA/l10n-brazil/tree/12.0/payment_cielo>`_ project on GitHub.
This module is part of the `OCA/l10n-brazil <https://github.com/OCA/l10n-brazil/tree/14.0/payment_cielo>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 2 additions & 2 deletions payment_cielo/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Payent Cielo",
"name": "Payment Cielo",
"summary": """
Payment Acquirer: Cielo Implementation""",
"version": "12.0.3.2.1",
"version": "14.0.1.0.0",
"development_status": "Alpha",
"license": "AGPL-3",
"author": "KMEE INFORMATICA LTDA,Odoo Community Association (OCA)",
Expand Down
55 changes: 0 additions & 55 deletions payment_cielo/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,60 +31,6 @@ def cielo_s2s_create_json_3ds(self, verify_validity=False, **kwargs):
.s2s_process(kwargs)
)

if not token:
res = {
"result": False,
}
return res

res = {
"result": True,
"short_name": token.short_name,
"3d_secure": False,
"verified": False,
}

return res

@http.route(["/payment/cielo/s2s/create_json"], type="json", auth="public")
def cielo_s2s_create_json(self, **kwargs):
acquirer_id = int(kwargs.get("acquirer_id"))
acquirer = request.env["payment.acquirer"].browse(acquirer_id)
if not kwargs.get("partner_id"):
kwargs["partner_id"] = request.env.user.partner_id.id
return acquirer.s2s_process(kwargs).id

@http.route(["/payment/cielo/s2s/create"], type="http", auth="public")
def cielo_s2s_create(self, **post):
acquirer_id = int(post.get("acquirer_id"))
acquirer = request.env["payment.acquirer"].browse(acquirer_id)
error = None
try:
acquirer.s2s_process(post)
except Exception as e:
error = str(e)

return_url = post.get("return_url", "/")
if error:
separator = "?" if werkzeug.urls.url_parse(return_url).query == "" else "&"
return_url += "{}{}".format(
separator, werkzeug.urls.url_encode({"error": error})
)

return werkzeug.utils.redirect(return_url)

@http.route(
["/payment/cielo/s2s/create_json_3ds"], type="json", auth="public", csrf=False
)
def cielo_s2s_create_json_3ds(self, verify_validity=False, **kwargs):
if not kwargs.get("partner_id"):
kwargs["partner_id"] = request.env.user.partner_id.id
token = (
request.env["payment.acquirer"]
.browse(int(kwargs.get("acquirer_id")))
.s2s_process(kwargs)
)

if not token:
res = {

Check warning on line 35 in payment_cielo/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

payment_cielo/controllers/main.py#L35

Added line #L35 was not covered by tests
"result": False,
Expand All @@ -108,7 +54,6 @@ def cielo_s2s_create_json_3ds(self, verify_validity=False, **kwargs):
@http.route(["/payment/cielo/create_charge"], type="json", auth="public")
def cielo_create_charge(self, **post):
"""Create a payment transaction
Expects the result from the user input from checkout.js popup"""
TX = request.env["payment.transaction"]
tx = None

Check warning on line 59 in payment_cielo/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

payment_cielo/controllers/main.py#L58-L59

Added lines #L58 - L59 were not covered by tests
Expand Down
4 changes: 2 additions & 2 deletions payment_cielo/data/payment_acquirer_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<record id="payment_acquirer_cielo" model="payment.acquirer">
<field name="name">Cielo</field>
<field
name="image"
name="image_128"
type="base64"
file="payment_cielo/static/src/img/cielo_icon.png"
/>
Expand All @@ -13,7 +13,7 @@
<field name="company_id" ref="base.main_company" />
<field name="view_template_id" ref="cielo_form" />
<field name="registration_view_template_id" ref="cielo_s2s_form" />
<field name="environment">test</field>
<field name="state">test</field>
<field
name="pre_msg"
><![CDATA[
Expand Down
18 changes: 9 additions & 9 deletions payment_cielo/models/payment_acquirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
class PaymentAcquirerCielo(models.Model):
_inherit = "payment.acquirer"

provider = fields.Selection(selection_add=[("cielo", "Cielo")])
provider = fields.Selection(
selection_add=[("cielo", "Cielo")], ondelete={"cielo": "set default"}
)
cielo_merchant_key = fields.Char(
required_if_provider="cielo", groups="base.group_user"
)
Expand All @@ -22,7 +24,6 @@ class PaymentAcquirerCielo(models.Model):
)
cielo_image_url = fields.Char("Checkout Image URL", groups="base.group_user")

@api.multi
def cielo_s2s_form_validate(self, data):
"""Validates user input"""
self.ensure_one()

Check warning on line 29 in payment_cielo/models/payment_acquirer.py

View check run for this annotation

Codecov / codecov/patch

payment_cielo/models/payment_acquirer.py#L29

Added line #L29 was not covered by tests
Expand Down Expand Up @@ -66,29 +67,28 @@ def cielo_s2s_form_process(self, data):
def _get_cielo_api_url(self):
"""Get cielo API URLs used in all s2s communication
Takes environment in consideration.
Takes state in consideration.
"""
if self.environment == "test":
if self.state == "test":
return "apisandbox.cieloecommerce.cielo.com.br"
if self.environment == "prod":
if self.state == "prod":
return "api.cieloecommerce.cielo.com.br"

Check warning on line 76 in payment_cielo/models/payment_acquirer.py

View check run for this annotation

Codecov / codecov/patch

payment_cielo/models/payment_acquirer.py#L76

Added line #L76 was not covered by tests

@api.multi
def _get_cielo_api_headers(self):
"""Get cielo API headers used in all s2s communication
Takes environment in consideration. If environment is production
Takes state in consideration. If state is production
merchant_id and merchant_key need to be defined.
"""
if self.environment == "test":
if self.state == "test":
CIELO_HEADERS = {
"MerchantId": "be87a4be-a40d-4a2d-b2c8-b8b6cc19cddd",
"MerchantKey": "POHAWRXFBSIXTMTFVBCYSKNWZBMOATDNYUQDGBUE",
"Content-Type": "application/json",
}
if self.environment == "prod":
if self.state == "prod":
CIELO_HEADERS = {

Check warning on line 92 in payment_cielo/models/payment_acquirer.py

View check run for this annotation

Codecov / codecov/patch

payment_cielo/models/payment_acquirer.py#L92

Added line #L92 was not covered by tests
"MerchantId": self.cielo_merchant_id,
"MerchantKey": self.cielo_merchant_key,
Expand Down
18 changes: 5 additions & 13 deletions payment_cielo/models/payment_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import requests

from odoo import api, fields, models
from odoo import fields, models

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -49,9 +49,7 @@ class PaymentTransactionCielo(models.Model):

def _create_cielo_charge(self, acquirer_ref=None, tokenid=None, email=None):
"""Creates the s2s payment.
Uses credit card token instead of secret info.
"""
api_url_charge = "https://%s/1/sales" % (self.acquirer_id._get_cielo_api_url())

Expand Down Expand Up @@ -88,15 +86,13 @@ def _create_cielo_charge(self, acquirer_ref=None, tokenid=None, email=None):
_logger.info("_create_cielo_charge: Values received:\n%s", pprint.pformat(res))
return res

@api.multi
def cielo_s2s_do_transaction(self, **kwargs):
self.ensure_one()
result = self._create_cielo_charge(
acquirer_ref=self.payment_token_id.acquirer_ref, email=self.partner_email
)
return self._cielo_s2s_validate_tree(result)

@api.multi
def cielo_s2s_capture_transaction(self):
"""Captures an authorized transaction."""
_logger.info(
Expand All @@ -113,7 +109,7 @@ def cielo_s2s_capture_transaction(self):
)
# analyse result
if (
type(res) == dict
isinstance(res, dict)
and res.get("ProviderReturnMessage")
and res.get("ProviderReturnMessage") == "Operation Successful"
):
Expand All @@ -135,7 +131,6 @@ def cielo_s2s_capture_transaction(self):
}
)

@api.multi
def cielo_s2s_void_transaction(self):
"""Voids an authorized transaction."""
_logger.info(
Expand All @@ -151,7 +146,7 @@ def cielo_s2s_void_transaction(self):
)
# analyse result
if (
type(res) == dict
isinstance(res, dict)
and res.get("ProviderReturnMessage")
and res.get("ProviderReturnMessage") == "Operation Successful"
):
Expand All @@ -172,15 +167,12 @@ def cielo_s2s_void_transaction(self):
}
)

@api.multi
def _cielo_s2s_validate_tree(self, tree):
"""Validates the transaction.
This method updates the payment.transaction object describing the
actual transaction outcome.
Also saves get/capture/void links sent by cielo to make it easier to
perform the operations.
"""
self.ensure_one()
if self.state != "draft":
Expand All @@ -190,7 +182,7 @@ def _cielo_s2s_validate_tree(self, tree):
)
return True

Check warning on line 183 in payment_cielo/models/payment_transaction.py

View check run for this annotation

Codecov / codecov/patch

payment_cielo/models/payment_transaction.py#L183

Added line #L183 was not covered by tests

if type(tree) != list:
if isinstance(tree, dict):
status = tree.get("Payment").get("Status")
if status == 1:
self.write(
Expand Down Expand Up @@ -229,7 +221,7 @@ def _cielo_s2s_validate_tree(self, tree):
self._set_transaction_cancel()
return False

Check warning on line 222 in payment_cielo/models/payment_transaction.py

View check run for this annotation

Codecov / codecov/patch

payment_cielo/models/payment_transaction.py#L221-L222

Added lines #L221 - L222 were not covered by tests

elif type(tree) == list:
elif isinstance(tree, list):
error = tree[0].get("Message")
_logger.warn(error)
self.sudo().write(

Check warning on line 227 in payment_cielo/models/payment_transaction.py

View check run for this annotation

Codecov / codecov/patch

payment_cielo/models/payment_transaction.py#L225-L227

Added lines #L225 - L227 were not covered by tests
Expand Down
24 changes: 13 additions & 11 deletions payment_cielo/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>Payent Cielo</title>
<title>Payment Cielo</title>
<style type="text/css">

/*
: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.
Expand Down Expand Up @@ -275,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 }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -360,16 +360,16 @@
</style>
</head>
<body>
<div class="document" id="payent-cielo">
<h1 class="title">Payent Cielo</h1>
<div class="document" id="payment-cielo">
<h1 class="title">Payment Cielo</h1>

<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:503ec16d8edb4f6914c0f58fd1b78ed0f162e867eb689ae399979c3fe81dffe5
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.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/l10n-brazil/tree/12.0/payment_cielo"><img alt="OCA/l10n-brazil" src="https://img.shields.io/badge/github-OCA%2Fl10n--brazil-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/l10n-brazil-12-0/l10n-brazil-12-0-payment_cielo"><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/l10n-brazil&amp;target_branch=12.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.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/l10n-brazil/tree/14.0/payment_cielo"><img alt="OCA/l10n-brazil" src="https://img.shields.io/badge/github-OCA%2Fl10n--brazil-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/l10n-brazil-14-0/l10n-brazil-14-0-payment_cielo"><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/l10n-brazil&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Payment Acquirer: Cielo Implementation</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
Expand Down Expand Up @@ -414,7 +414,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/l10n-brazil/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/l10n-brazil/issues/new?body=module:%20payment_cielo%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/l10n-brazil/issues/new?body=module:%20payment_cielo%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -439,13 +439,15 @@ <h2><a class="toc-backref" href="#toc-entry-7">Other credits</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-8">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>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/DiegoParadeda"><img alt="DiegoParadeda" src="https://github.com/DiegoParadeda.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/l10n-brazil/tree/12.0/payment_cielo">OCA/l10n-brazil</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/l10n-brazil/tree/14.0/payment_cielo">OCA/l10n-brazil</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Loading

0 comments on commit 350994e

Please sign in to comment.