Browse Source

Dec 30 : [UPDT] Bug Fixed 'myfatoorah_payment_gateway'

pull/299/head
AjmalCybro 1 year ago
parent
commit
db471c1534
  1. 3
      myfatoorah_payment_gateway/README.rst
  2. 2
      myfatoorah_payment_gateway/__manifest__.py
  3. 3
      myfatoorah_payment_gateway/controllers/main.py
  4. 4
      myfatoorah_payment_gateway/data/payment_provider_data.xml
  5. 2
      myfatoorah_payment_gateway/models/payment_provider.py
  6. 51
      myfatoorah_payment_gateway/models/payment_transaction.py
  7. BIN
      myfatoorah_payment_gateway/static/description/assets/screenshots/screenshot4.png
  8. 7
      myfatoorah_payment_gateway/static/description/index.html
  9. 22
      myfatoorah_payment_gateway/static/src/js/modal.js
  10. 16
      myfatoorah_payment_gateway/views/myfatoorah_payment_template.xml
  11. 2
      myfatoorah_payment_gateway/views/payment_myfatoorah_templates.xml

3
myfatoorah_payment_gateway/README.rst

@ -18,8 +18,9 @@ Company
Credits Credits
------- -------
* Developer: * Developers:
(v16) Swaroop N P @ Cybrosys (v16) Swaroop N P @ Cybrosys
Subina P @ Cybrosys
Contacts Contacts

2
myfatoorah_payment_gateway/__manifest__.py

@ -19,7 +19,6 @@
# If not, see <http://www.gnu.org/licenses/>. # If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################# #############################################################################
{ {
'name': 'MyFatoorah Payment Gateway', 'name': 'MyFatoorah Payment Gateway',
'category': 'Accounting/Payment Acquirers', 'category': 'Accounting/Payment Acquirers',
@ -37,7 +36,6 @@
'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',

3
myfatoorah_payment_gateway/controllers/main.py

@ -37,6 +37,7 @@ class PaymentMyFatoorahController(http.Controller):
website=True, methods=['POST'], csrf=False, save_session=False) website=True, methods=['POST'], csrf=False, save_session=False)
def myfatoorah_payment_response(self, **data): def myfatoorah_payment_response(self, **data):
"""Function to get the payment response""" """Function to get the payment response"""
payment_data = ast.literal_eval(data["data"]) payment_data = ast.literal_eval(data["data"])
vals = { vals = {
'customer': payment_data["CustomerName"], 'customer': payment_data["CustomerName"],
@ -44,7 +45,7 @@ class PaymentMyFatoorahController(http.Controller):
'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["InvoiceURL"],
} }
return request.render( return request.render(
"myfatoorah_payment_gateway.myfatoorah_payment_gateway_form", vals) "myfatoorah_payment_gateway.myfatoorah_payment_gateway_form", vals)

4
myfatoorah_payment_gateway/data/payment_provider_data.xml

@ -4,6 +4,10 @@
<field name="code">myfatoorah</field> <field name="code">myfatoorah</field>
<field name="image_128" type="base64" <field name="image_128" type="base64"
file="myfatoorah_payment_gateway/static/description/icon.png"/> file="myfatoorah_payment_gateway/static/description/icon.png"/>
<field name="payment_icon_ids" eval="[(6, 0, [
ref('payment.payment_icon_cc_visa'),
ref('payment.payment_icon_cc_mastercard'),
])]"/>
<field name="company_id" ref="base.main_company"/> <field name="company_id" ref="base.main_company"/>
<field name="redirect_form_view_id" ref="redirect_form"/> <field name="redirect_form_view_id" ref="redirect_form"/>
</record> </record>

2
myfatoorah_payment_gateway/models/payment_provider.py

@ -19,7 +19,7 @@
# If not, see <http://www.gnu.org/licenses/>. # If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################# #############################################################################
from odoo import fields, models, api, _ from odoo import fields, models, api
class PaymentProvider(models.Model): class PaymentProvider(models.Model):

51
myfatoorah_payment_gateway/models/payment_transaction.py

@ -20,7 +20,7 @@
############################################################################# #############################################################################
# Import required libraries (make sure it is installed!) # Import required libraries (make sure it is installed!)
import logging import logging
from odoo import _, api, fields, models from odoo import _, models
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
import requests import requests
import json import json
@ -36,42 +36,34 @@ class PaymentTransaction(models.Model):
res = super()._get_specific_rendering_values(processing_values) res = super()._get_specific_rendering_values(processing_values)
if self.provider_code != 'myfatoorah': if self.provider_code != 'myfatoorah':
return res return res
return self.execute_payment() return self.send_payment()
def execute_payment(self): def send_payment(self):
"""Fetching data and Executing Payment"""
base_api_url = self.env['payment.provider'].search( base_api_url = self.env['payment.provider'].search(
[('code', '=', 'myfatoorah')])._myfatoorah_get_api_url() [('code', '=', 'myfatoorah')])._myfatoorah_get_api_url()
api_url = f"{base_api_url}v2/ExecutePayment" api_url = f"{base_api_url}v2/SendPayment"
api_key = self.env['payment.provider'].search([('code', '=', api_key = self.env['payment.provider'].search([('code', '=',
'myfatoorah')]).myfatoorah_token 'myfatoorah')]).myfatoorah_token
odoo_base_url = self.env['ir.config_parameter'].get_param( odoo_base_url = self.env['ir.config_parameter'].get_param(
'web.base.url') 'web.base.url')
sale_order = self.env['payment.transaction'].search( sale_order = self.env['payment.transaction'].search(
[('id', '=', self.id)]).sale_order_ids [('id', '=', self.id)]).sale_order_ids
order_line = self.env['payment.transaction'].search(
[('id', '=', self.id)]).sale_order_ids.order_line
invoice_items = [
{
'ItemName': rec.product_id.name,
'Quantity': int(rec.product_uom_qty),
'UnitPrice': rec.price_unit,
}
for rec in order_line
]
MobileCountryCode = self.partner_id.country_id.phone_code MobileCountryCode = self.partner_id.country_id.phone_code
phone_number = self.partner_phone phone_number = self.partner_phone
if not phone_number: if not phone_number:
raise ValueError("Please provide the phone number.") raise ValueError("Please provide the phone number.")
if phone_number: else:
phone_number = phone_number.replace(str(MobileCountryCode), '') phone_number = phone_number.replace(str(MobileCountryCode), '')
if phone_number.startswith('+'): if phone_number.startswith('+'):
phone_number = phone_number[1:] phone_number = phone_number[1:]
currency = self.partner_id.company_id.currency_id.name elif not phone_number:
raise ValueError(
"Please provide the phone number in proper format")
currency = self.env.company.currency_id.name
payment_details = { sendpay_data = {
"PaymentMethodId": 6, "NotificationOption": "ALL",
"CustomerName": self.partner_name, "CustomerName": self.partner_name,
"DisplayCurrencyIso": currency, "DisplayCurrencyIso": currency,
"MobileCountryCode": MobileCountryCode, "MobileCountryCode": MobileCountryCode,
@ -85,28 +77,27 @@ class PaymentTransaction(models.Model):
"CustomerAddress": { "CustomerAddress": {
"Address": f'{self.partner_address} ,{self.partner_city} {self.partner_zip} ,{self.partner_state_id.name} ,{self.partner_country_id.name}', "Address": f'{self.partner_address} ,{self.partner_city} {self.partner_zip} ,{self.partner_state_id.name} ,{self.partner_country_id.name}',
}, },
"InvoiceItems":
invoice_items
} }
headers = { headers = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Accept': 'application/json', 'Accept': 'application/json',
'Authorization': f'Bearer {api_key}', 'Authorization': f'Bearer {api_key}',
} }
payload = json.dumps(payment_details) payload = json.dumps(sendpay_data)
print(payload,'payload')
response = requests.request("POST", api_url, headers=headers, response = requests.request("POST", api_url, headers=headers,
data=payload) data=payload)
print(response,'response...')
response_data = response.json() response_data = response.json()
if not response_data.get('IsSuccess'): if not response_data.get('IsSuccess'):
raise ValidationError(f"{response_data.get('Message')}") validation_errors = response_data.get('ValidationErrors')
if response_data.get('Data')['PaymentURL']: if validation_errors:
payment_url = response_data.get('Data')['PaymentURL'] error_message = validation_errors[0].get('Error')
payment_details['PaymentURL'] = payment_url raise ValidationError(f"{error_message}")
if response_data.get('Data')['InvoiceURL']:
payment_url = response_data.get('Data')['InvoiceURL']
sendpay_data['InvoiceURL'] = 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': sendpay_data,
} }
def _get_tx_from_notification_data(self, provider_code, notification_data): def _get_tx_from_notification_data(self, provider_code, notification_data):

BIN
myfatoorah_payment_gateway/static/description/assets/screenshots/screenshot4.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 170 KiB

7
myfatoorah_payment_gateway/static/description/index.html

@ -100,7 +100,8 @@
<div class="col-sm-12 py-4">This module allows us to add and enable MyFatoorah payment acquirer on our website. <div class="col-sm-12 py-4">This module allows us to add and enable MyFatoorah payment acquirer on our website.
Please ensure that your system is configured to use HTTPS instead of localhost to maintain a secure connection Please ensure that your system is configured to use HTTPS instead of localhost to maintain a secure connection
and protect sensitive information during interactions with the module.In case you are utilizing localhost for and protect sensitive information during interactions with the module.In case you are utilizing localhost for
testing purposes, please use http://127.0.0.1/<portnumber> instead of 'localhost' to access the module. testing purposes, please use http://127.0.0.1/ instead of 'localhost' to access the module.
Also, ensure that the phone number format and currency match the standards of the supported countries.
</div> </div>
</div> </div>
<!-- END OF OVERVIEW SECTION --> <!-- END OF OVERVIEW SECTION -->
@ -398,7 +399,7 @@
</div> </div>
<!-- END OF END OF OUR SERVICES --> <!-- END OF OUR SERVICES -->
<!-- OUR INDUSTRIES --> <!-- OUR INDUSTRIES -->
@ -525,7 +526,7 @@
</div> </div>
</div> </div>
<!-- END OF END OF OUR INDUSTRIES --> <!-- END OF OUR INDUSTRIES -->
<!-- SUPPORT --> <!-- SUPPORT -->
<div class="d-flex align-items-center" style="border-bottom: 2px solid #714B67; padding: 15px 0px;"> <div class="d-flex align-items-center" style="border-bottom: 2px solid #714B67; padding: 15px 0px;">

22
myfatoorah_payment_gateway/static/src/js/modal.js

@ -0,0 +1,22 @@
//// Import the necessary dependencies
//import { useService } from '@odoo/owl';
//import { useRef } from '@odoo/owl';
//
//class YourComponent {
// setup() {
// this.orm = useService('orm');
// this.preview = useRef('preview_modal');
// this._super.apply(this, arguments);
//
// // Call a method to open the modal
// this.openModal();
// }
//
// openModal() {
// // Assuming you are using Bootstrap, trigger the modal by its ID
// const modal = new bootstrap.Modal(document.getElementById('preview_modal'));
// modal.show();
// }
//}
//
//export default YourComponent;

16
myfatoorah_payment_gateway/views/myfatoorah_payment_template.xml

@ -36,16 +36,6 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<!-- <td>-->
<!-- <label for="country_code">-->
<!-- Country Code-->
<!-- </label>-->
<!-- <input type="text"-->
<!-- class="form-control shadow-none"-->
<!-- name="country_code"-->
<!-- t-att-value="country_code"-->
<!-- readonly="1"/>-->
<!-- </td>-->
<td> <td>
<label for="mobile"> <label for="mobile">
Mobile Mobile
@ -56,9 +46,7 @@
t-att-value="mobile" t-att-value="mobile"
readonly="1"/> readonly="1"/>
</td> </td>
</tr> <td>
<tr>
<td>
<label for="invoice_amount"> <label for="invoice_amount">
Invoice Amount Invoice Amount
</label> </label>
@ -68,6 +56,8 @@
t-att-value="invoice_amount" t-att-value="invoice_amount"
readonly="1"/> readonly="1"/>
</td> </td>
</tr>
<tr>
<td> <td>
<label for="address"> <label for="address">
Address Address

2
myfatoorah_payment_gateway/views/payment_myfatoorah_templates.xml

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<odoo> <odoo>
<template id="redirect_form"> <template id="redirect_form">
<form t-att-action="api_url" method="post"> <form t-att-action="api_url" method="post">
<input type="hidden" name="csrf_token" <input type="hidden" name="csrf_token"
@ -19,5 +18,4 @@
<input type="hidden" name="ErrorUrl" t-att-value="ErrorUrl"/> <input type="hidden" name="ErrorUrl" t-att-value="ErrorUrl"/>
</form> </form>
</template> </template>
</odoo> </odoo>

Loading…
Cancel
Save