Skip to content

Commit

Permalink
Merge pull request #1 from yibudak/12.0
Browse files Browse the repository at this point in the history
12.0
  • Loading branch information
aaltinisik authored Aug 14, 2023
2 parents 63edb59 + 8c056fc commit e1dc8dd
Show file tree
Hide file tree
Showing 21 changed files with 1,478 additions and 0 deletions.
Binary file added payment_garanti/GVP.zip
Binary file not shown.
38 changes: 38 additions & 0 deletions payment_garanti/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Payment Garanti
![Garanti](./static/description/icon.png)

Odoo 16 için Garanti sanal pos entegrasyonu. Sadece 3D secure ile çalışır.



![Payment Form](./static/img/demo.png)


### Kurulum:

- `Faturalama/Yapılandırma/Payment Providers` menüsünden Garanti ödeme yöntemini aktif ediniz.
- `Kimlik Bilgileri` kısmından Garanti tarafından tanımlanan API bilgilerinizi giriniz.

### Gerekli Modüller:

- Bu modülü kullanabilmek için `payment` modülü kurulu olmalıdır.
### Python bağımlılıkları:
- lxml
- beautifulsoup4

### Notlar:

Bu modül henüz geliştirilme aşamasındadır. Odoo 16.0 temel alınarak tasarlanmıştır.

### Geliştirici:

- [Yiğit Budak](https://github.com/yibudak)


### Odoo Türkiye yerelleştirme projemize katkılarınızı bekliyoruz.

* Proje LGPL lisansı ile lisanslanmıştır. Katkılarınızda bu lisans koşullarını kabul etmiş sayılırsınız.
* Projemizdeki modüllerin ve içeriğin **OCA kalite standartları**nı sağlamasını amaçlıyoruz.
* [Contribute to OCA](https://odoo-community.org/page/Contribute) sayfasında genel bilgiler mevcut.
* Eklenecek modüller için genel kurallara https://github.com/OCA/maintainer-tools/blob/master/CONTRIBUTING.md adresinden erişebilirsiniz.
* Modülleri geliştirirken [OCA tarafından hazırlanan kalite kontrol programları](https://github.com/OCA/maintainer-quality-tools) ile kalite kontrol işinizi kolaylaştırabilirsiniz.
13 changes: 13 additions & 0 deletions payment_garanti/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2022 Yiğit Budak (https://github.com/yibudak)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
from . import controllers
from odoo.addons.payment.models.payment_acquirer import (
create_missing_journal_for_acquirers,
)
from odoo.addons.payment import reset_payment_provider


def uninstall_hook(cr, registry):
reset_payment_provider(cr, registry, "garanti")
25 changes: 25 additions & 0 deletions payment_garanti/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2022 Yiğit Budak (https://github.com/yibudak)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Garanti Payment Acquirer",
"version": "12.0.0.1.0",
"category": "Accounting",
"license": "LGPL-3",
"website": "https://github.com/odoo-turkey",
"author": "Yigit Budak",
"sequence": 350,
"summary": "Garanti BBVA Sanal POS, internet üzerinden yapılan satışlarda"
" kredi kartı ile ödeme alınabilmesi için oluşturulan güvenli"
" bir ödeme çözümüdür.",
"depends": ["payment"],
"external_dependencies": {"python": ["lxml", "bs4"]},
"data": [
"views/payment_garanti_templates.xml",
"views/payment_views.xml",
"templates/result_page.xml",
"data/payment_acquirer_data.xml",
],
"application": True,
"post_init_hook": "create_missing_journal_for_acquirers",
"uninstall_hook": "uninstall_hook",
}
13 changes: 13 additions & 0 deletions payment_garanti/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2023 Samet Altuntaş (https://github.com/samettal)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

PROD_URL = "https://sanalposprov.garanti.com.tr/servlet/gt3dengine"
TEST_URL = "https://sanalposprovtest.garanti.com.tr/servlet/gt3dengine"
PROVISION_URL = "https://sanalposprov.garanti.com.tr/VPServlet"

CURRENCY_CODES = {
"TRY": "949",
"USD": "840",
"EUR": "978",
"GBP": "826",
}
4 changes: 4 additions & 0 deletions payment_garanti/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2022 Yiğit Budak (https://github.com/yibudak)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import main
129 changes: 129 additions & 0 deletions payment_garanti/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Copyright 2022 Yiğit Budak (https://github.com/yibudak)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
import pprint
from odoo import _, http, fields
from odoo.exceptions import ValidationError
from odoo.addons.payment.controllers.portal import PaymentProcessing
from odoo.tools import float_compare
from odoo.http import request
from datetime import datetime


_logger = logging.getLogger(__name__)


class GarantiController(http.Controller):
_payment_url = "/payment/garanti/s2s/create_json_3ds"
_return_url = "/payment/garanti/return"

@http.route(_payment_url, type="json", auth="public")
def garanti_s2s_create_json_3ds(self, **kwargs):
# !!! Printing the card data for debugging purposes is a security risk !!!
# _logger.debug(
# "Garanti payment request received: s2s_create_json_3ds: kwargs=%s",
# pprint.pformat(kwargs),
# )
acq = (
request.env["payment.acquirer"]
.sudo()
.browse(int(kwargs.get("acquirer_id")))
)
# Validate the card data
card_args = dict()
card_args["card_number"] = kwargs.get("cc_number")
card_args["card_cvv"] = kwargs.get("cc_cvc")
card_args["card_name"] = kwargs.get("cc_holder_name")
card_args["card_valid_month"] = kwargs.get("cc_expiry")[0:2]
card_args["card_valid_year"] = kwargs.get("cc_expiry")[5:]

card_error = acq._garanti_validate_card_args(card_args)
if card_error:
raise ValidationError(card_error)

# Get the order
order_sudo = (
request.env["sale.order"].sudo().browse(int(kwargs.get("order_id")))
)
if not order_sudo:
raise ValidationError(_("Sale order not found"))

# Validate the amount
try:
amount = float(kwargs.get("amount_total"))
except (ValueError, TypeError):
raise ValidationError(_("Invalid amount"))

precision = request.env["decimal.precision"].precision_get("account")
if float_compare(amount, order_sudo.amount_total, precision) != 0:
raise ValidationError(_("Invalid amount"))

# Create the transaction
tx_sudo = (
request.env["payment.transaction"]
.sudo()
.create(
{
"amount": order_sudo.amount_total,
"acquirer_id": acq.id,
"acquirer_reference": order_sudo.name,
"partner_id": order_sudo.partner_id.id,
"sale_order_ids": [(4, order_sudo.id, False)],
"currency_id": order_sudo.currency_id.id,
"date": datetime.now(),
"state": "draft",
}
)
)

# Get client IP
client_ip = request.httprequest.environ.get("REMOTE_ADDR")

# Get the payment response, it can be a redirect or a form
response_content = acq.sudo()._garanti_make_payment_request(
tx_sudo, amount, order_sudo.currency_id.id, card_args, client_ip
)
# Save the transaction in the session
PaymentProcessing.add_payment_transaction(tx_sudo)
return response_content

@http.route(
_return_url,
type="http",
auth="public",
csrf=False,
save_session=False,
methods=["GET"],
)
def garanti_return_from_3ds_auth(self, **kwargs):
"""
Handle the return from the 3DS authentication.
notification_data is a dict coming from Garanti.
"""
# handle the response
# Careful about the log here, it can contain sensitive information
_logger.debug(
"Garanti 3DS auth return received: return_from_3ds_auth: kwargs=%s",
pprint.pformat(kwargs),
)
try:
tx = (
request.env["payment.transaction"]
.sudo()
.form_feedback(data=kwargs, acquirer_name="garanti")
)
if tx.state != "done":
raise ValidationError(_("Transaction not completed"))
except:
return _(
"An error occurred while processing your payment. Please contact us."
)

# Redirect the user to the status page
return request.render(
"payment_garanti.garanti_payment_result",
qcontext={
"tx_id": tx,
"order_id": fields.first(tx.sale_order_ids[0]),
},
)
28 changes: 28 additions & 0 deletions payment_garanti/data/payment_acquirer_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">

<record id="payment_acquirer_garanti" model="payment.acquirer">
<field name="name">Garanti</field>
<field name="image" type="base64" file="payment_garanti/static/description/icon.png"/>
<field name="provider">garanti</field>
<field name="company_id" ref="base.main_company"/>
<field name="view_template_id" ref="payment_garanti.garanti_form"/>
<field name="registration_view_template_id" ref="payment_garanti.garanti_s2s_form"/>
<field name="environment">test</field>
<field name="payment_flow">s2s</field>
<field name="pre_msg"><![CDATA[
<p><br></p>]]></field>

<field name="payment_icon_ids"
eval="[(6, 0, [
ref('payment.payment_icon_cc_mastercard'),
ref('payment.payment_icon_cc_visa'),
])]"/>
<field name="garanti_merchant_id">dummy</field>
<field name="garanti_terminal_id">dummy</field>
<field name="garanti_prov_user">dummy</field>
<field name="garanti_prov_password">dummy</field>
<field name="garanti_store_key">dummy</field>
</record>

</odoo>
Loading

0 comments on commit e1dc8dd

Please sign in to comment.