Skip to content

Commit

Permalink
[MIG] payment_pagseguro: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelsavegnago committed Jun 21, 2022
1 parent 1bf10e7 commit fca5db2
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 34 deletions.
1 change: 1 addition & 0 deletions payment_pagseguro/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"depends": [
"sale", # Used sale order in currency validation
"web_tour",
"website_sale",
],
"data": [
"views/payment_pagseguro_templates.xml",
Expand Down
3 changes: 1 addition & 2 deletions payment_pagseguro/data/payment_acquirer_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
<record id="payment_acquirer_pagseguro" model="payment.acquirer">
<field name="name">Pagseguro</field>
<field
name="image"
name="image_128"
type="base64"
file="payment_pagseguro/static/src/img/pag_seguro_icon.jpg"
/>
<field name="provider">pagseguro</field>
<field name="company_id" ref="base.main_company" />
<field name="view_template_id" ref="pagseguro_form" />
<field name="registration_view_template_id" ref="pagseguro_s2s_form" />
<field name="environment">test</field>
<field name="save_token">none</field>
<field name="payment_flow">s2s</field>
<field name="capture_manually">True</field>
Expand Down
13 changes: 7 additions & 6 deletions payment_pagseguro/models/payment_acquirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
class PaymentAcquirerPagseguro(models.Model):
_inherit = "payment.acquirer"

provider = fields.Selection(selection_add=[("pagseguro", "Pagseguro")])
provider = fields.Selection(
selection_add=[("pagseguro", "Pagseguro")],
ondelete={"pagseguro": "set default"},
)
pagseguro_token = fields.Char(
string="Pagseguro Token",
required_if_provider="pagseguro",
groups="base.group_user",
)

@api.multi
def pagseguro_s2s_form_validate(self, data):
"""Validates user input"""
self.ensure_one()
Expand Down Expand Up @@ -51,12 +53,11 @@ def _get_pagseguro_api_url(self):
Takes environment in consideration.
"""
if self.environment == "test":
return "sandbox.api.pagseguro.com"
if self.environment == "prod":
if self.state == "enabled":
return "api.pagseguro.com"
else:
return "sandbox.api.pagseguro.com"

@api.multi
def _get_pagseguro_api_headers(self):
"""Get pagseguro API headers used in all s2s communication
Expand Down
8 changes: 1 addition & 7 deletions payment_pagseguro/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
from odoo.exceptions import ValidationError

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -54,14 +54,12 @@ def _create_pagseguro_charge(self):
)
return res

@api.multi
def pagseguro_s2s_do_transaction(self, **kwargs):
self.ensure_one()
result = self._create_pagseguro_charge()

return self._pagseguro_s2s_validate_tree(result)

@api.multi
def pagseguro_s2s_capture_transaction(self):
"""Captures an authorized transaction."""
currencies = self.sale_order_ids.currency_id.mapped(
Expand Down Expand Up @@ -108,7 +106,6 @@ def pagseguro_s2s_capture_transaction(self):
message=res["error_messages"][0]["message"],
)

@api.multi
def pagseguro_s2s_void_transaction(self):
"""Voids an authorized transaction."""
_logger.info(
Expand Down Expand Up @@ -152,7 +149,6 @@ def pagseguro_s2s_void_transaction(self):
message=res["error_messages"][0]["message"],
)

@api.multi
def _pagseguro_s2s_validate_tree(self, tree):
"""Validates the transaction.
Expand Down Expand Up @@ -200,7 +196,6 @@ def _pagseguro_s2s_validate_tree(self, tree):

return False

@api.multi
def _validate_tree_message(self, tree):
if tree.get("message"):
error = tree.get("message")
Expand All @@ -214,7 +209,6 @@ def _validate_tree_message(self, tree):
)
self._set_transaction_cancel()

@api.multi
def _get_pagseguro_charge_params(self):
"""
Returns dict containing the required body information to create a
Expand Down
6 changes: 4 additions & 2 deletions payment_pagseguro/static/src/js/pagseguro_tokenize_card.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ odoo.define("payment_pagseguro.pagseguro_tokenize_card", function (require) {
holder: formData.cc_holder_name,
number: formData.cc_number.replace(/\s+/g, ""),
expMonth: formData.cc_expiry.split("/")[0],
expYear: formData.cc_expiry.split("/")[1],
expYear: ""
.concat("20", formData.cc_expiry.split("/")[1])
.replace(/\s/g, ""),
securityCode: formData.cc_cvc,
});
})
Expand Down Expand Up @@ -92,7 +94,7 @@ odoo.define("payment_pagseguro.pagseguro_tokenize_card", function (require) {
self.el.submit();
}
})
.fail(function (error) {
.catch(function (error) {
// If the public key rpc fails
self.enableButton(button);

Expand Down
24 changes: 12 additions & 12 deletions payment_pagseguro/static/src/js/pagseguro_tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
odoo.define("payment_pagseguro.tour", function (require) {
"use strict";

var ajax = require("web.ajax");
var session = require("web.session");
var tour = require("web_tour.tour");
var base = require("web_editor.base");
var rpc = require("web.rpc");

var domReady = new Promise(function (resolve) {
$(resolve);
});
var ready = Promise.all([domReady, session.is_bound, ajax.loadXML()]);

tour.register(
"shop_buy_pagseguro",
{
url: "/shop",
test: true,
wait_for: base.ready(),
debug: true,
wait_for: ready,
},
[
{
Expand All @@ -34,8 +39,7 @@ odoo.define("payment_pagseguro.tour", function (require) {
acquirer,
{
pagseguro_token: "8EC2714B10DC42DE882BC341A5366899",
environment: "test",
website_published: true,
state: "test",
journal_id: 1,
capture_manually: true,
payment_flow: "s2s",
Expand Down Expand Up @@ -69,10 +73,6 @@ odoo.define("payment_pagseguro.tour", function (require) {
trigger:
'#product_detail form[action^="/shop/cart/update"] .btn-primary',
},
{
content: "click in modal on 'Proceed to checkout' button",
trigger: 'button:contains("Proceed to Checkout")',
},
{
content: "go to checkout",
trigger: 'a[href*="/shop/checkout"]',
Expand All @@ -94,7 +94,7 @@ odoo.define("payment_pagseguro.tour", function (require) {
{
content: "insert expiration date",
trigger: "input[name='cc_expiry']",
run: "text 12/2030",
run: "text 12/99",
},
{
content: "insert security code",
Expand All @@ -110,9 +110,9 @@ odoo.define("payment_pagseguro.tour", function (require) {
},
{
content: "payment authorized",
extra_trigger: ".bg-success",
extra_trigger: ".alert-success",
trigger:
'.bg-success span:contains("Your payment has been authorized.")',
'.alert-success span:contains("Your payment has been authorized.")',
timeout: 20000,
},
{
Expand Down
6 changes: 2 additions & 4 deletions payment_pagseguro/tests/test_pagseguro.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ def setUp(self):
self.brl_currency = self.env["res.currency"].search([("name", "=", "BRL")])

def test_buy_pagseguro(self):
self.browser_js(
self.start_tour(
"/shop",
"odoo.__DEBUG__.services['web_tour.tour'].run('shop_buy_pagseguro')",
"odoo.__DEBUG__.services['web_tour.tour'].tours.shop_buy_pagseguro.ready",
"shop_buy_pagseguro",
login="admin",
timeout=40000,
)

tx = self.env["payment.transaction"].search([], limit=1, order="id desc")
Expand Down
2 changes: 1 addition & 1 deletion payment_pagseguro/views/payment_pagseguro_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
id="cc_expiry"
class="form-control"
maxlength="9"
placeholder="Expires (MM/YYYY)"
placeholder="Expires (MM/YY)"
data-is-required="true"
/>
</div>
Expand Down

0 comments on commit fca5db2

Please sign in to comment.