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. 14
      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
-------
* Developer:
* Developers:
(v16) Swaroop N P @ Cybrosys
Subina P @ Cybrosys
Contacts

2
myfatoorah_payment_gateway/__manifest__.py

@ -19,7 +19,6 @@
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
{
'name': 'MyFatoorah Payment Gateway',
'category': 'Accounting/Payment Acquirers',
@ -37,7 +36,6 @@
'views/payment_myfatoorah_templates.xml',
'views/myfatoorah_payment_template.xml',
'data/payment_provider_data.xml',
],
'post_init_hook': 'post_init_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)
def myfatoorah_payment_response(self, **data):
"""Function to get the payment response"""
payment_data = ast.literal_eval(data["data"])
vals = {
'customer': payment_data["CustomerName"],
@ -44,7 +45,7 @@ class PaymentMyFatoorahController(http.Controller):
'mobile': payment_data["CustomerMobile"],
'invoice_amount': payment_data["InvoiceValue"],
'address': payment_data["CustomerAddress"]["Address"],
'payment_url': payment_data["PaymentURL"],
'payment_url': payment_data["InvoiceURL"],
}
return request.render(
"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="image_128" type="base64"
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="redirect_form_view_id" ref="redirect_form"/>
</record>

2
myfatoorah_payment_gateway/models/payment_provider.py

@ -19,7 +19,7 @@
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from odoo import fields, models, api, _
from odoo import fields, models, api
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 logging
from odoo import _, api, fields, models
from odoo import _, models
from odoo.exceptions import ValidationError
import requests
import json
@ -36,42 +36,34 @@ class PaymentTransaction(models.Model):
res = super()._get_specific_rendering_values(processing_values)
if self.provider_code != 'myfatoorah':
return res
return self.execute_payment()
return self.send_payment()
def execute_payment(self):
"""Fetching data and Executing Payment"""
def send_payment(self):
base_api_url = self.env['payment.provider'].search(
[('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', '=',
'myfatoorah')]).myfatoorah_token
odoo_base_url = self.env['ir.config_parameter'].get_param(
'web.base.url')
sale_order = self.env['payment.transaction'].search(
[('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
phone_number = self.partner_phone
if not phone_number:
raise ValueError("Please provide the phone number.")
if phone_number:
else:
phone_number = phone_number.replace(str(MobileCountryCode), '')
if phone_number.startswith('+'):
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 = {
"PaymentMethodId": 6,
sendpay_data = {
"NotificationOption": "ALL",
"CustomerName": self.partner_name,
"DisplayCurrencyIso": currency,
"MobileCountryCode": MobileCountryCode,
@ -85,28 +77,27 @@ class PaymentTransaction(models.Model):
"CustomerAddress": {
"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 = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': f'Bearer {api_key}',
}
payload = json.dumps(payment_details)
print(payload,'payload')
payload = json.dumps(sendpay_data)
response = requests.request("POST", api_url, headers=headers,
data=payload)
print(response,'response...')
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_details['PaymentURL'] = payment_url
validation_errors = response_data.get('ValidationErrors')
if validation_errors:
error_message = validation_errors[0].get('Error')
raise ValidationError(f"{error_message}")
if response_data.get('Data')['InvoiceURL']:
payment_url = response_data.get('Data')['InvoiceURL']
sendpay_data['InvoiceURL'] = payment_url
return {
'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):

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.
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
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>
<!-- END OF OVERVIEW SECTION -->
@ -398,7 +399,7 @@
</div>
<!-- END OF END OF OUR SERVICES -->
<!-- END OF OUR SERVICES -->
<!-- OUR INDUSTRIES -->
@ -525,7 +526,7 @@
</div>
</div>
<!-- END OF END OF OUR INDUSTRIES -->
<!-- END OF OUR INDUSTRIES -->
<!-- SUPPORT -->
<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;

14
myfatoorah_payment_gateway/views/myfatoorah_payment_template.xml

@ -36,16 +36,6 @@
</td>
</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>
<label for="mobile">
Mobile
@ -56,8 +46,6 @@
t-att-value="mobile"
readonly="1"/>
</td>
</tr>
<tr>
<td>
<label for="invoice_amount">
Invoice Amount
@ -68,6 +56,8 @@
t-att-value="invoice_amount"
readonly="1"/>
</td>
</tr>
<tr>
<td>
<label for="address">
Address

2
myfatoorah_payment_gateway/views/payment_myfatoorah_templates.xml

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

Loading…
Cancel
Save