Browse Source

Jun 01 [UPDT] : Bug Fixed 'myfatoorah_payment_gateway'

pull/257/head
AjmalCybro 2 years ago
parent
commit
d1f41e8926
  1. 6
      myfatoorah_payment_gateway/README.rst
  2. 1
      myfatoorah_payment_gateway/__init__.py
  3. 8
      myfatoorah_payment_gateway/__manifest__.py
  4. 7
      myfatoorah_payment_gateway/controllers/main.py
  5. 40
      myfatoorah_payment_gateway/models/payment_transaction.py

6
myfatoorah_payment_gateway/README.rst

@ -1,6 +1,6 @@
MyFatoorah Payment Gateway MyFatroorah Payment Gateway
=========================== =====================================
* MyFatoorah Payment Gateway For Odoo 16 *MyFatroorah Payment Gateway For Odoo 16
Installation Installation
============ ============

1
myfatoorah_payment_gateway/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
############################################################################# #############################################################################
# #
# Cybrosys Technologies Pvt. Ltd. # Cybrosys Technologies Pvt. Ltd.

8
myfatoorah_payment_gateway/__manifest__.py

@ -23,19 +23,21 @@
{ {
'name': 'MyFatoorah Payment Gateway', 'name': 'MyFatoorah Payment Gateway',
'category': 'Accounting/Payment Acquirers', 'category': 'Accounting/Payment Acquirers',
'sequence': 50,
'version': '16.0.1.0.0', 'version': '16.0.1.0.0',
'description': """MyFatoorah Payment Gateway V16""", 'description': """MyFatoorah Payment Gateway""",
'Summary': """MyFatoorah Payment Gateway V16""", 'Summary': """Payment Provider : MyFatoorah """,
'author': "Cybrosys Techno Solutions", 'author': "Cybrosys Techno Solutions",
'company': 'Cybrosys Techno Solutions', 'company': 'Cybrosys Techno Solutions',
'maintainer': 'Cybrosys Techno Solutions', 'maintainer': 'Cybrosys Techno Solutions',
'website': "https://www.cybrosys.com", 'website': "https://www.cybrosys.com",
'depends': ['payment', 'account', 'website', 'website_sale'], 'depends': ['payment','account','website','website_sale'],
'data': [ 'data': [
'views/payment_template.xml', 'views/payment_template.xml',
'views/payment_myfatoorah_templates.xml', 'views/payment_myfatoorah_templates.xml',
'views/myfatoorah_payment_template.xml', 'views/myfatoorah_payment_template.xml',
'data/payment_provider_data.xml', 'data/payment_provider_data.xml',
], ],
'post_init_hook': 'post_init_hook', 'post_init_hook': 'post_init_hook',
'uninstall_hook': 'uninstall_hook', 'uninstall_hook': 'uninstall_hook',

7
myfatoorah_payment_gateway/controllers/main.py

@ -42,18 +42,18 @@ class PaymentMyFatoorahController(http.Controller):
vals = { vals = {
'customer': payment_data["CustomerName"], 'customer': payment_data["CustomerName"],
'currency': payment_data["DisplayCurrencyIso"], 'currency': payment_data["DisplayCurrencyIso"],
# 'country_code': payment_data["MobileCountryCode"],
'mobile': payment_data["CustomerMobile"], 'mobile': payment_data["CustomerMobile"],
'invoice_amount': payment_data["InvoiceValue"], 'invoice_amount': payment_data["InvoiceValue"],
'address': payment_data["CustomerAddress"]["Address"], 'address': payment_data["CustomerAddress"]["Address"],
'payment_url': payment_data["PaymentURL"], 'payment_url': payment_data["PaymentURL"],
} }
return request.render( return request.render(
"myfatoorah_payment_gateway.myfatoorah_payment_gateway_form", vals) "myfatoorah_payment_gateway.myfatoorah_payment_gateway_form", vals)
@http.route(_return_url, type='http', auth='public', @http.route(_return_url, type='http', auth='public',
methods=['GET']) methods=['GET'])
def myfatoorah__checkout(self, **data): def myfatoorah_checkout(self, **data):
_logger.info("Received MyFatoorah return data:\n%s", _logger.info("Received MyFatoorah return data:\n%s",
pprint.pformat(data)) pprint.pformat(data))
tx_sudo = request.env[ tx_sudo = request.env[
@ -64,6 +64,7 @@ class PaymentMyFatoorahController(http.Controller):
@http.route('/payment/myfatoorah/failed', type='http', auth='user', @http.route('/payment/myfatoorah/failed', type='http', auth='user',
website=True, ) website=True, )
def payment_failed(self, redirect=None): def payment_failed(self, redirect=None, **data):
# self.myfatoorah_checkout(data = data)
return request.render( return request.render(
"myfatoorah_payment_gateway.myfatoorah_payment_gateway_failed_form") "myfatoorah_payment_gateway.myfatoorah_payment_gateway_failed_form")

40
myfatoorah_payment_gateway/models/payment_transaction.py

@ -18,20 +18,12 @@
# If not, see <http://www.gnu.org/licenses/>. # If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################# #############################################################################
# Import required libraries (make sure it is installed!)
import logging import logging
from werkzeug import urls
from odoo import _, api, fields, models from odoo import _, api, fields, models
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
from odoo.addons.payment import utils as payment_utils
from odoo.http import request
# Import required libraries (make sure it is installed!)
import requests import requests
import json import json
import sys
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -59,7 +51,6 @@ class PaymentTransaction(models.Model):
order_line = self.env['payment.transaction'].search( order_line = self.env['payment.transaction'].search(
[('id', '=', self.id)]).sale_order_ids.order_line [('id', '=', self.id)]).sale_order_ids.order_line
invoice_items = [ invoice_items = [
{ {
'ItemName': rec.product_id.name, 'ItemName': rec.product_id.name,
@ -69,12 +60,16 @@ class PaymentTransaction(models.Model):
for rec in order_line for rec in order_line
] ]
if len(self.partner_phone.replace('-', "").rsplit(' ', 1)[1]) > 11: if len(self.partner_phone.replace('-', "").rsplit(' ', 1)[1]) > 11:
raise ValidationError(_("Phone number must not be greater than 11 characters")) raise ValidationError(
_("Phone number must not be greater than 11 characters"))
payment_details = { payment_details = {
"PaymentMethodId": 4, "PaymentMethodId": 6,
"CustomerName": self.partner_name, "CustomerName": self.partner_name,
"DisplayCurrencyIso": self.currency_id.name, "DisplayCurrencyIso": self.currency_id.name,
"CustomerMobile": self.partner_phone.replace('-', "").rsplit(' ', 1)[1], # "MobileCountryCode": "964",
# "CustomerMobile": "78589587458",
"CustomerMobile":
self.partner_phone.replace('-', "").rsplit(' ', 1)[1],
"CustomerEmail": self.partner_email, "CustomerEmail": self.partner_email,
"InvoiceValue": (self.amount - sale_order.amount_tax), "InvoiceValue": (self.amount - sale_order.amount_tax),
"CallBackUrl": f"{odoo_base_url}/payment/myfatoorah/_return_url", "CallBackUrl": f"{odoo_base_url}/payment/myfatoorah/_return_url",
@ -97,9 +92,11 @@ class PaymentTransaction(models.Model):
response = requests.request("POST", api_url, headers=headers, response = requests.request("POST", api_url, headers=headers,
data=payload) data=payload)
response_data = response.json() response_data = response.json()
if not response_data.get('IsSuccess'):
raise ValidationError(f"{response_data.get('Message')}")
if response_data.get('Data')['PaymentURL']:
payment_url = response_data.get('Data')['PaymentURL'] payment_url = response_data.get('Data')['PaymentURL']
payment_details['PaymentURL'] = payment_url payment_details['PaymentURL'] = payment_url
return { return {
'api_url': f"{odoo_base_url}/payment/myfatoorah/response", 'api_url': f"{odoo_base_url}/payment/myfatoorah/response",
'data': payment_details, 'data': payment_details,
@ -122,28 +119,27 @@ class PaymentTransaction(models.Model):
'Accept': 'application/json', 'Accept': 'application/json',
'Authorization': f'Bearer {api_key}', 'Authorization': f'Bearer {api_key}',
} }
response = requests.request("POST", url, headers=headers, data=payload) response = requests.request("POST", url, headers=headers, data=payload)
response_data = response.json() response_data = response.json()
tx = super()._get_tx_from_notification_data(provider_code, tx = super()._get_tx_from_notification_data(provider_code,
notification_data) notification_data)
if provider_code != 'myfatoorah' or len(tx) == 1: if provider_code != 'myfatoorah' or len(tx) == 1:
return tx return tx
domain = [('provider_code', '=', 'myfatoorah')]
reference = ""
if response_data["Data"]["CustomerReference"]:
reference = response_data["Data"]["CustomerReference"] reference = response_data["Data"]["CustomerReference"]
tx = self.search( domain.append(reference)
[ if tx := self.search(domain):
('reference', '=', reference), return tx
('provider_code', '=', 'myfatoorah')]) else:
if not tx:
raise ValidationError( raise ValidationError(
"myfatoorah: " + _( "myfatoorah: " + _(
"No transaction found matching reference %s.", "No transaction found matching reference %s.",
reference) reference)
) )
return tx
def _handle_notification_data(self, provider_code, notification_data): def _handle_notification_data(self, provider_code, notification_data):
tx = self._get_tx_from_notification_data(provider_code, tx = self._get_tx_from_notification_data(provider_code,
notification_data) notification_data)
tx._process_notification_data(notification_data) tx._process_notification_data(notification_data)

Loading…
Cancel
Save