Merge pull request #2745 from expsa/ENS-3085
[MIG] payment_hyperpay: v14
This commit is contained in:
commit
66e3a828a2
|
|
@ -1,3 +0,0 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (paper_world)" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/payment_hyperpay.iml" filepath="$PROJECT_DIR$/.idea/payment_hyperpay.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
|
@ -14,16 +14,16 @@
|
|||
# If not, see <https://store.webkul.com/license.html/>
|
||||
#################################################################################
|
||||
{
|
||||
"name" : "Hyperpay Payment Acquirer",
|
||||
"summary" : """Website Hyper Pay Payment Acquirer""",
|
||||
"category" : "Website",
|
||||
"version" : "1.0.0",
|
||||
"sequence" : 1,
|
||||
"author" : "Webkul Software Pvt. Ltd.",
|
||||
"license" : "Other proprietary",
|
||||
"maintainer" : "Anuj Kumar Chhetri",
|
||||
"website" : "https://store.webkul.com/odoo-hyperpay-payment-acquirer.html",
|
||||
"description" : """Odoo Hyperpay Payment Gateway
|
||||
"name": "Hyperpay Payment Acquirer",
|
||||
"summary": """Website Hyper Pay Payment Acquirer""",
|
||||
"category": "Website",
|
||||
"version": "1.0.0",
|
||||
"sequence": 1,
|
||||
"author": "Webkul Software Pvt. Ltd.",
|
||||
"license": "Other proprietary",
|
||||
"maintainer": "Anuj Kumar Chhetri",
|
||||
"website": "https://store.webkul.com/odoo-hyperpay-payment-acquirer.html",
|
||||
"description": """Odoo Hyperpay Payment Gateway
|
||||
Payment Gateway
|
||||
Hyperpay
|
||||
hyper pay
|
||||
|
|
@ -38,23 +38,20 @@
|
|||
Customer payment
|
||||
Integrate hyperpay payment acquirer in Odoo
|
||||
Integrate hyperpay payment gateway in Odoo""",
|
||||
"live_test_url" : "http://odoodemo.webkul.com/?module=payment_hyperpay",
|
||||
"depends" : ['account',
|
||||
'payment',
|
||||
'website_sale',
|
||||
],
|
||||
"data" : [
|
||||
'views/payment_views.xml',
|
||||
'views/payment_hyperpay_templates.xml',
|
||||
'data/payment_acquirer_data.xml',
|
||||
],
|
||||
'assets' : {
|
||||
'web.assets_frontend': ['payment_hyperpay/static/src/css/loader.css']
|
||||
},
|
||||
"demo" : [],
|
||||
"images" : ['static/description/banner.gif'],
|
||||
"application" : True,
|
||||
"installable" : True,
|
||||
"price" : 99.0,
|
||||
"currency" : "USD",
|
||||
"live_test_url": "http://odoodemo.webkul.com/?module=payment_hyperpay",
|
||||
"depends": ['account',
|
||||
'payment',
|
||||
'website_sale'],
|
||||
"data": [
|
||||
'views/payment_views.xml',
|
||||
'views/payment_hyperpay_templates.xml',
|
||||
'data/payment_acquirer_data.xml',
|
||||
'views/website_assets.xml',
|
||||
],
|
||||
"demo": [],
|
||||
"images": ['static/description/banner.gif'],
|
||||
"application": True,
|
||||
"installable": True,
|
||||
"price": 99.0,
|
||||
"currency": "USD",
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,16 +6,9 @@
|
|||
#################################################################################
|
||||
|
||||
import requests
|
||||
import werkzeug
|
||||
from werkzeug import urls
|
||||
import json
|
||||
from odoo import http
|
||||
import urllib
|
||||
import random
|
||||
# from odoo.addons.portal.controllers.portal import _build_url_w_params
|
||||
|
||||
#from odoo.addons.payment.controllers.portal import PaymentProcessing
|
||||
from odoo.addons.website_sale.controllers.main import WebsiteSale
|
||||
from odoo.http import request
|
||||
from odoo.addons.payment_hyperpay.data.payment_icon import payment_icon
|
||||
|
||||
|
|
@ -34,12 +27,10 @@ def _get_checkout_id(**params):
|
|||
domain = live_domain
|
||||
else:
|
||||
domain = test_domain
|
||||
# params['testMode'] = 'EXTERNAL'
|
||||
url_string = domain + "/v1/checkouts"
|
||||
|
||||
# url = _build_url_w_params(url_string, params)
|
||||
headers = {
|
||||
"Authorization" : auth,
|
||||
"Authorization": auth,
|
||||
}
|
||||
try:
|
||||
r = requests.post(url=url_string, data=params, headers=headers)
|
||||
|
|
@ -55,83 +46,79 @@ class HyperPayController(http.Controller):
|
|||
@http.route('/payment/hyperpay/checkout/create', type='json', auth='public', csrf=False, website=True)
|
||||
def create_hyperpay_checkout(self, **post):
|
||||
_logger.info('--post---%r', post)
|
||||
tx = request.env['payment.transaction'].sudo().search([('id','=',int(post.get('txId', 0)))])
|
||||
tx = request.env['payment.transaction'].sudo().search([('id', '=', int(post.get('txId', 0)))])
|
||||
final_response = {}
|
||||
if tx:
|
||||
base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
||||
acq = tx.provider_id
|
||||
acq = tx.acquirer_id
|
||||
partner_id = tx.partner_id
|
||||
order_no = tx.reference.split('-', 1)
|
||||
order_id = tx.sale_order_ids[0] if tx.sale_order_ids else None
|
||||
partner_name = partner_id.name or 'Guest'
|
||||
partner_mobile = partner_id.mobile or ''
|
||||
if order_no:
|
||||
order_id = request.env['sale.order'].sudo().search([('name', '=', order_no[0])], limit=1)
|
||||
if order_id:
|
||||
partner_mobile = order_id.order_mobile_number
|
||||
partner_name = order_id.order_name
|
||||
if order_id:
|
||||
partner_mobile = order_id.order_mobile_number
|
||||
partner_name = order_id.order_name
|
||||
kwargs = {
|
||||
"auth": "Bearer " + acq.hyperpay_authorization,
|
||||
"entityId": acq.hyperpay_merchant_id,
|
||||
"amount": '%.2f'%tx.amount,
|
||||
"currency": tx.currency_id and tx.sudo().currency_id.name or '',
|
||||
"paymentType": "DB",
|
||||
"env": acq.state,
|
||||
"customParameters[SHOPPER_tx_id]": tx.id,
|
||||
"merchantTransactionId": tx.reference,
|
||||
"billing.street1": partner_id.street or 'Riyadh',
|
||||
"billing.street2": partner_id.street2 or '',
|
||||
"billing.city": partner_id.city or 'Riyadh',
|
||||
"billing.state": partner_id.state_id.name or 'Riyadh',
|
||||
"billing.postcode": partner_id.zip or '',
|
||||
"billing.country": partner_id.country_id.code or 'SA',
|
||||
"customer.givenName": partner_name,
|
||||
"customer.surname": '',
|
||||
"customer.email": '{seq}@ensan.sa'.format(seq=random.randint(0,10000)),
|
||||
"customer.mobile": partner_mobile,
|
||||
"customer.phone": partner_id and partner_id.phone or partner_id.mobile or '',
|
||||
}
|
||||
"auth": "Bearer " + acq.hyperpay_authorization,
|
||||
"entityId": acq.hyperpay_merchant_id,
|
||||
"amount": '%.2f' % tx.amount,
|
||||
"currency": tx.currency_id and tx.sudo().currency_id.name or '',
|
||||
"paymentType": "DB",
|
||||
"env": acq.state,
|
||||
"customParameters[SHOPPER_tx_id]": tx.id,
|
||||
"merchantTransactionId": tx.reference,
|
||||
"billing.street1": partner_id.street or 'Riyadh',
|
||||
"billing.street2": partner_id.street2 or '',
|
||||
"billing.city": partner_id.city or 'Riyadh',
|
||||
"billing.state": partner_id.state_id.name or 'Riyadh',
|
||||
"billing.postcode": partner_id.zip or '',
|
||||
"billing.country": partner_id.country_id.code or 'SA',
|
||||
"customer.givenName": partner_name,
|
||||
"customer.surname": '',
|
||||
"customer.email": '{seq}@ensan.sa'.format(seq=random.randint(0, 10000)),
|
||||
"customer.mobile": partner_mobile,
|
||||
"customer.phone": partner_id and partner_id.phone or partner_id.mobile or '',
|
||||
}
|
||||
resp = _get_checkout_id(**kwargs)
|
||||
tx.hyperpay_checkout_id = resp.get('id')
|
||||
domain = live_domain if acq.state == 'enabled' else test_domain
|
||||
#payment_acq = request.env['payment.acquirer'].sudo()
|
||||
#hyperpay =payment_acq.search([('name','=','HyperPay')])
|
||||
|
||||
payment_icons = acq.payment_icon_ids.mapped('name')
|
||||
data_brands = "VISA"
|
||||
if(len(payment_icon)>1):
|
||||
if (len(payment_icon) > 1):
|
||||
brands = [payment_icon[i.upper()] for i in payment_icons if i.upper() in payment_icon.keys()]
|
||||
data_brands = brands and " ".join(brands) or data_brands
|
||||
|
||||
final_response = {
|
||||
"checkoutId": resp.get('id',''),
|
||||
'domain': domain,
|
||||
'base_url': base_url,
|
||||
'data_brands':data_brands,
|
||||
'acq':acq.id
|
||||
}
|
||||
"checkoutId": resp.get('id', ''),
|
||||
'domain': domain,
|
||||
'base_url': base_url,
|
||||
'data_brands': data_brands,
|
||||
'acq': acq.id
|
||||
}
|
||||
return final_response
|
||||
|
||||
|
||||
@http.route('/payment/hyperpay/result', type='http', auth='public', csrf=False,website=True ,save_session=True)
|
||||
@http.route('/payment/hyperpay/result', type='http', auth='public', csrf=False, website=True, save_session=True)
|
||||
def hyperpay_shopper_result(self, **post):
|
||||
acq = request.env['payment.provider'].sudo().search([('id', '=', post.get('acq'))])
|
||||
acq = request.env['payment.acquirer'].sudo().search([('id', '=', post.get('acq'))])
|
||||
if acq.state == 'enabled':
|
||||
url = live_domain
|
||||
else:
|
||||
url = test_domain
|
||||
url += '/' + post.get('resourcePath')+"?entityId=%s"%(acq.hyperpay_merchant_id)
|
||||
url += '/' + post.get('resourcePath') + "?entityId=%s" % (acq.hyperpay_merchant_id)
|
||||
headers = {
|
||||
"Authorization" : "Bearer " + acq.hyperpay_authorization,
|
||||
"Authorization": "Bearer " + acq.hyperpay_authorization,
|
||||
}
|
||||
resp = requests.get(url=url, headers=headers).json()
|
||||
|
||||
_logger.info("-----/payment/hyperpay/result-----response------------%r----", resp)
|
||||
|
||||
payment = request.env['payment.transaction'].sudo()
|
||||
tx_id = payment.search([('hyperpay_checkout_id', '=', post.get('id',''))])
|
||||
tx = resp.get('customParameters',{}).get('SHOPPER_tx_id') or tx_id and tx_id.id or ''
|
||||
tx_id = payment.search([('hyperpay_checkout_id', '=', post.get('id', ''))])
|
||||
tx = resp.get('customParameters', {}).get('SHOPPER_tx_id') or tx_id and tx_id.id or ''
|
||||
resp.update({'tx_id': tx})
|
||||
#if tx:
|
||||
# PaymentProcessing.add_payment_transaction(payment.browse(int(tx)))
|
||||
|
||||
res = tx_id._handle_notification_data('hyperpay',resp)
|
||||
return werkzeug.utils.redirect(f'/payment/status')
|
||||
res = request.env['payment.transaction'].sudo().form_feedback(resp, "hyperpay")
|
||||
ids = tx_id.sale_order_ids.sudo().ids
|
||||
request.session['sale_last_order_id'] = ids[0] if len(ids) else None
|
||||
return request.redirect('/payment/process')
|
||||
|
|
|
|||
|
|
@ -1,136 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#################################################################################
|
||||
#
|
||||
# Copyright (c) 2015-Present Webkul Software Pvt. Ltd. (<https://webkul.com/>)
|
||||
#
|
||||
#################################################################################
|
||||
|
||||
import requests
|
||||
import werkzeug
|
||||
from werkzeug import urls
|
||||
import json
|
||||
from odoo import http
|
||||
import urllib
|
||||
# from odoo.addons.portal.controllers.portal import _build_url_w_params
|
||||
|
||||
#from odoo.addons.payment.controllers.portal import PaymentProcessing
|
||||
from odoo.addons.website_sale.controllers.main import WebsiteSale
|
||||
from odoo.http import request
|
||||
from odoo.addons.payment_hyperpay.data.payment_icon import payment_icon
|
||||
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
# test_domain = "https://test.oppwa.com"
|
||||
# live_domain = "https://oppwa.com"
|
||||
test_domain = "https://eu-test.oppwa.com"
|
||||
live_domain = "https://eu-prod.oppwa.com"
|
||||
|
||||
def _get_checkout_id(**params):
|
||||
auth = params.pop('auth', '')
|
||||
env = params.pop('env')
|
||||
if env == 'enabled':
|
||||
domain = live_domain
|
||||
else:
|
||||
domain = test_domain
|
||||
# params['testMode'] = 'EXTERNAL'
|
||||
url_string = domain + "/v1/checkouts"
|
||||
|
||||
# url = _build_url_w_params(url_string, params)
|
||||
headers = {
|
||||
"Authorization" : auth,
|
||||
}
|
||||
try:
|
||||
r = requests.post(url=url_string, data=params, headers=headers)
|
||||
r = r.json()
|
||||
if 'parameterErrors' in r.get('result'):
|
||||
raise Exception
|
||||
return r
|
||||
except Exception as e:
|
||||
return {}
|
||||
|
||||
class HyperPayController(http.Controller):
|
||||
|
||||
@http.route('/payment/hyperpay/checkout/create', type='json', auth='public', csrf=False, website=True)
|
||||
def create_hyperpay_checkout(self, **post):
|
||||
_logger.info('--post---%r', post)
|
||||
tx = request.env['payment.transaction'].sudo().search([('id','=',int(post.get('txId', 0)))])
|
||||
final_response = {}
|
||||
if tx:
|
||||
base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
||||
acq = tx.provider_id
|
||||
partner_id = tx.partner_id
|
||||
order_no = tx.reference.split('-', 1)
|
||||
partner_name = partner_id.name or 'Guest'
|
||||
partner_mobile = partner_id.mobile or ''
|
||||
if order_no:
|
||||
order_id = request.env['sale.order'].sudo().search([('name', '=', order_no[0])], limit=1)
|
||||
if order_id:
|
||||
partner_mobile = order_id.order_mobile_number
|
||||
partner_name = order_id.order_name
|
||||
kwargs = {
|
||||
"auth": "Bearer " + acq.hyperpay_authorization,
|
||||
"entityId": acq.hyperpay_merchant_id,
|
||||
"amount": '%.2f'%tx.amount,
|
||||
"currency": tx.currency_id and tx.sudo().currency_id.name or '',
|
||||
"paymentType": "DB",
|
||||
"env": acq.state,
|
||||
"customParameters[SHOPPER_tx_id]": tx.id,
|
||||
"merchantTransactionId": tx.reference,
|
||||
"billing.street1": partner_id.street or 'Riyadh',
|
||||
"billing.street2": partner_id.street2 or '',
|
||||
"billing.city": partner_id.city or 'Riyadh',
|
||||
"billing.state": partner_id.state_id.name or 'Riyadh',
|
||||
"billing.postcode": partner_id.zip or '',
|
||||
"billing.country": partner_id.country_id.code or 'SA',
|
||||
"customer.givenName": partner_name,
|
||||
"customer.surname": '',
|
||||
"customer.email": partner_id and partner_id.email or '',
|
||||
"customer.mobile": partner_mobile,
|
||||
"customer.phone": partner_id and partner_id.phone or partner_id.mobile or '',
|
||||
}
|
||||
resp = _get_checkout_id(**kwargs)
|
||||
tx.hyperpay_checkout_id = resp.get('id')
|
||||
domain = live_domain if acq.state == 'enabled' else test_domain
|
||||
#payment_acq = request.env['payment.acquirer'].sudo()
|
||||
#hyperpay =payment_acq.search([('name','=','HyperPay')])
|
||||
payment_icons = acq.payment_icon_ids.mapped('name')
|
||||
data_brands = "VISA"
|
||||
if(len(payment_icon)>1):
|
||||
brands = [payment_icon[i.upper()] for i in payment_icons if i.upper() in payment_icon.keys()]
|
||||
data_brands = brands and " ".join(brands) or data_brands
|
||||
|
||||
final_response = {
|
||||
"checkoutId": resp.get('id',''),
|
||||
'domain': domain,
|
||||
'base_url': base_url,
|
||||
'data_brands':data_brands,
|
||||
'acq':acq.id
|
||||
}
|
||||
return final_response
|
||||
|
||||
|
||||
@http.route('/payment/hyperpay/result', type='http', auth='public', csrf=False,website=True ,save_session=True)
|
||||
def hyperpay_shopper_result(self, **post):
|
||||
acq = request.env['payment.provider'].sudo().search([('id', '=', post.get('acq'))])
|
||||
if acq.state == 'enabled':
|
||||
url = live_domain
|
||||
else:
|
||||
url = test_domain
|
||||
url += '/' + post.get('resourcePath')+"?entityId=%s"%(acq.hyperpay_merchant_id)
|
||||
headers = {
|
||||
"Authorization" : "Bearer " + acq.hyperpay_authorization,
|
||||
}
|
||||
resp = requests.get(url=url, headers=headers).json()
|
||||
|
||||
_logger.info("-----/payment/hyperpay/result-----response------------%r----", resp)
|
||||
|
||||
payment = request.env['payment.transaction'].sudo()
|
||||
tx_id = payment.search([('hyperpay_checkout_id', '=', post.get('id',''))])
|
||||
tx = resp.get('customParameters',{}).get('SHOPPER_tx_id') or tx_id and tx_id.id or ''
|
||||
resp.update({'tx_id': tx})
|
||||
#if tx:
|
||||
# PaymentProcessing.add_payment_transaction(payment.browse(int(tx)))
|
||||
|
||||
res = tx_id._handle_notification_data('hyperpay',resp)
|
||||
return werkzeug.utils.redirect(f'/payment/status')
|
||||
|
|
@ -1,13 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
<record id="payment_acquirer_hyperpay" model="payment.provider">
|
||||
<record id="payment_acquirer_hyperpay" model="payment.acquirer">
|
||||
<field name="name">HyperPay</field>
|
||||
<field name="code">hyperpay</field>
|
||||
<field name="redirect_form_view_id" ref="hyperpay_form"/>
|
||||
<field name="provider">hyperpay</field>
|
||||
<field name="view_template_id" ref="hyperpay_form"/>
|
||||
<field name="image_128" type="base64" file="payment_hyperpay/static/src/img/hyperpay-logo.jpg"/>
|
||||
<field name="company_id" ref="base.main_company"/>
|
||||
|
||||
<field name="state">test</field>
|
||||
<field name="hyperpay_authorization">OGE4Mjk0MTc0ZDA1OTViYjAxNGQwNWQ4MjllNzAxZDF8OVRuSlBjMm45aA==</field>
|
||||
<field name="hyperpay_merchant_id">8a8294174d0595bb014d05d82e5b01d2</field>
|
||||
|
|
@ -18,11 +16,9 @@
|
|||
<div>Expiry Date : any date after today</div>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
<record id="payment_method_hyperpay" model="account.payment.method">
|
||||
<field name="name">HyperPay</field>
|
||||
<field name="code">hyperpay</field>
|
||||
<field name="payment_type">inbound</field>
|
||||
<field name="payment_icon_ids" eval='[(6, 0, [
|
||||
ref("payment.payment_icon_cc_mastercard"),
|
||||
ref("payment.payment_icon_cc_visa")])]'/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
|
|
|
|||
|
|
@ -5,4 +5,3 @@
|
|||
#
|
||||
#################################################################################
|
||||
from . import payment
|
||||
from . import acount_payment_method
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
from odoo import api, models
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
class AccountPaymentMethod(models.Model):
|
||||
_inherit = 'account.payment.method'
|
||||
|
||||
@api.model
|
||||
def _get_payment_method_information(self):
|
||||
res = super()._get_payment_method_information()
|
||||
_logger.info("this is res %r",res)
|
||||
res['hyperpay'] = {'mode': 'unique', 'domain': [('type', '=', 'bank')]}
|
||||
return res
|
||||
|
|
@ -10,29 +10,20 @@ import logging
|
|||
import dateutil.parser
|
||||
import pytz
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.addons.payment.models.payment_provider import ValidationError
|
||||
import pprint
|
||||
from odoo.fields import Datetime
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AcquirerHyperPay(models.Model):
|
||||
_inherit = 'payment.provider'
|
||||
_inherit = 'payment.acquirer'
|
||||
|
||||
code = fields.Selection(selection_add=[('hyperpay', 'HyperPay')],ondelete={'hyperpay': 'set default'})
|
||||
provider = fields.Selection(selection_add=[('hyperpay', 'HyperPay')], ondelete={'hyperpay': 'set default'})
|
||||
hyperpay_authorization = fields.Char('Authorization', required_if_provider='hyperpay', groups='base.group_user', help='Authorization header with Bearer authentication scheme')
|
||||
hyperpay_merchant_id = fields.Char(
|
||||
'Merchant Id', groups='base.group_user',
|
||||
help='The Merchant ID is required to authorize the request')
|
||||
|
||||
#New method added to core
|
||||
def _get_default_payment_method_id(self,code):
|
||||
provider_method_id = self._get_provider_payment_method(code)
|
||||
if provider_method_id:
|
||||
return provider_method_id.id
|
||||
return self.env.ref('account.account_payment_method_manual_in').id
|
||||
|
||||
def hyperpay_form_generate_values(self, values):
|
||||
hyperpay_tx_values = dict(values)
|
||||
if values.get('reference','/') != "/":
|
||||
|
|
@ -47,76 +38,51 @@ class HyperPayPaymentTransaction(models.Model):
|
|||
|
||||
hyperpay_checkout_id = fields.Char('Checkout Id', groups='base.group_user', help='Unique checkout id for every hyper transasction')
|
||||
|
||||
|
||||
def _get_specific_rendering_values(self, processing_values):
|
||||
""" Override of payment to return Alipay-specific rendering values.
|
||||
Note: self.ensure_one() from `_get_processing_values`
|
||||
:param dict processing_values: The generic and specific processing values of the transaction
|
||||
:return: The dict of acquirer-specific processing values
|
||||
:rtype: dict
|
||||
"""
|
||||
res = super()._get_specific_rendering_values(processing_values)
|
||||
if self.provider_code != 'hyperpay':
|
||||
return res
|
||||
|
||||
_logger.info('--specific------%r',(processing_values,self.reference))
|
||||
hyperpay_tx_values={}
|
||||
tx = self.env['payment.transaction'].sudo().search([('reference', '=', self.reference)])
|
||||
_logger.info('--specific------%r',(processing_values,self.reference,tx.id))
|
||||
hyperpay_tx_values.update({
|
||||
"txId": tx.id,
|
||||
'reference':self.reference
|
||||
})
|
||||
return hyperpay_tx_values
|
||||
|
||||
|
||||
@api.model
|
||||
def _get_tx_from_notification_data(self,provider, data):
|
||||
reference = data.get('ndc')
|
||||
tx_id = data.get('tx_id')
|
||||
tx = tx_id and self.sudo().browse(int(tx_id))
|
||||
if not tx or len(tx) > 1:
|
||||
error_msg = _('received data for reference %s') % (pprint.pformat(reference))
|
||||
if not tx:
|
||||
error_msg += _('; no order found')
|
||||
else:
|
||||
error_msg += _('; multiple order found')
|
||||
def _hyperpay_form_get_tx_from_data(self, data):
|
||||
reference, txn_id = data.get('ndc'), data.get('tx_id')
|
||||
if not reference or not txn_id:
|
||||
error_msg = _('HyperPay: received data with missing reference (%s) or txn_id (%s)') % (reference, txn_id)
|
||||
_logger.info(error_msg)
|
||||
raise ValidationError(error_msg)
|
||||
return tx
|
||||
|
||||
txs = self.env['payment.transaction'].search([('id', '=', int(txn_id))])
|
||||
if not txs or len(txs) > 1:
|
||||
error_msg = 'HyperPay: received data for reference %s' % (reference)
|
||||
if not txs:
|
||||
error_msg += '; no order found'
|
||||
else:
|
||||
error_msg += '; multiple order found'
|
||||
_logger.info(error_msg)
|
||||
raise ValidationError(error_msg)
|
||||
return txs[0]
|
||||
|
||||
def _process_notification_data(self, data):
|
||||
|
||||
res = super()._process_notification_data(data)
|
||||
if self.provider_code != 'hyperpay':
|
||||
return res
|
||||
|
||||
_logger.info('Validated transfer payment for tx %s: set as pending' % (self.reference))
|
||||
def _hyperpay_form_validate(self, data):
|
||||
_logger.info('Validated HyperPay payment for tx %s: set as pending' % (self.reference))
|
||||
result = data.get('result')
|
||||
result_code = result.get('code')
|
||||
res ={}
|
||||
res = {
|
||||
'acquirer_reference': data.get('id'),
|
||||
'state_message': result.get('description', '')
|
||||
}
|
||||
success_pattern = [
|
||||
'^(000\.000\.|000\.100\.1|000\.[36])',
|
||||
'^(000\.400\.0[^3]|000\.400\.100)'
|
||||
'^(000\.000\.|000\.100\.1|000\.[36])',
|
||||
'^(000\.400\.0[^3]|000\.400\.100)'
|
||||
]
|
||||
pending_pattern =[
|
||||
'^(000\.200)',
|
||||
'^(800\.400\.5|100\.400\.500)'
|
||||
pending_pattern = [
|
||||
'^(000\.200)',
|
||||
'^(800\.400\.5|100\.400\.500)'
|
||||
]
|
||||
_logger.info('------feedback-%r',result)
|
||||
if re.match(success_pattern[0], result_code) or re.match(success_pattern[1], result_code):
|
||||
date_validate = dateutil.parser.parse(data.get('timestamp')).astimezone(pytz.utc).replace(tzinfo=None)
|
||||
res.update(provider_reference=data.get('id'), last_state_change=date_validate, state_message= result.get('description',''))
|
||||
self._set_done()
|
||||
res.update(provider_reference=data.get('id'), date=date_validate)
|
||||
self._set_transaction_done()
|
||||
elif re.match(pending_pattern[0], result_code) or re.match(pending_pattern[1], result_code):
|
||||
res.update(state_message= result.get('description',''))
|
||||
self._set_pending()
|
||||
self._set_transaction_pending()
|
||||
elif re.match('/^(000\.100\.2)/', result_code):
|
||||
res.update(state_message= result.get('description',''))
|
||||
self._set_error(result.get('description',''))
|
||||
self._set_transaction_error()
|
||||
else:
|
||||
res.update(state_message= result.get('description',''))
|
||||
self._set_canceled()
|
||||
_logger.info('------feedback-%r',(res,self.write(res),self))
|
||||
error = 'Received unrecognized status for HyperPay payment %s: %s, set as error' % (self.reference, result_code)
|
||||
_logger.info(error)
|
||||
self._set_transaction_cancel()
|
||||
return self.write(res)
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
var wpwlOptions = {
|
||||
onReady: function(){
|
||||
var shopOrigin = $('input[name="shopOrigin"]');
|
||||
var origin = parent.window.location.origin;
|
||||
parent_iframe = $('#hyperpay_iframe', window.parent.document);
|
||||
parent_iframe.css({"width":"100%", "height":"21em", "border":"none", "display":""});
|
||||
$('.hyperpay_loader', window.parent.document).remove();
|
||||
$('#hyperpay_close', window.parent.document).on('click', function(){
|
||||
parent.window.location.reload(true);
|
||||
});
|
||||
if (shopOrigin.length != 0 && shopOrigin.val() == 'null'){
|
||||
shopOrigin.val(origin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +1,28 @@
|
|||
odoo.define('payment_hyperpay.payment_hyperpay', function (require) {
|
||||
"use strict";
|
||||
odoo.define("payment_hyperpay.payment_hyperpay", function (require) {
|
||||
"use strict";
|
||||
|
||||
var core = require('web.core');
|
||||
var Dialog = require('web.Dialog');
|
||||
var publicWidget = require('web.public.widget');
|
||||
var ajax = require('web.ajax');
|
||||
const {assets} = require('@web/core/assets');
|
||||
var core = require("web.core");
|
||||
var publicWidget = require("web.public.widget");
|
||||
var ajax = require("web.ajax");
|
||||
|
||||
var qweb = core.qweb;
|
||||
var _t = core._t;
|
||||
var _t = core._t;
|
||||
|
||||
if ($.blockUI) {
|
||||
$.blockUI.defaults.css.border = '0';
|
||||
$.blockUI.defaults.css["background-color"] = '';
|
||||
$.blockUI.defaults.overlayCSS["opacity"] = '0.5';
|
||||
$.blockUI.defaults.overlayCSS["z-index"] = '1050';
|
||||
if ($.blockUI) {
|
||||
$.blockUI.defaults.css.border = "0";
|
||||
$.blockUI.defaults.css["background-color"] = "";
|
||||
$.blockUI.defaults.overlayCSS["opacity"] = "0.5";
|
||||
$.blockUI.defaults.overlayCSS["z-index"] = "1050";
|
||||
}
|
||||
|
||||
// Reference
|
||||
// https://dev.to/pulljosh/how-to-load-html-css-and-js-code-into-an-iframe-2blc
|
||||
const getGeneratedPageURL = ({ html, css, js}) => {
|
||||
const getBlobURL = (code, type) => {
|
||||
const blob = new Blob([code], { type })
|
||||
return URL.createObjectURL(blob)
|
||||
}
|
||||
const getGeneratedPageURL = ({ html, css, js }) => {
|
||||
const getBlobURL = (code, type) => {
|
||||
const blob = new Blob([code], { type });
|
||||
return URL.createObjectURL(blob);
|
||||
};
|
||||
|
||||
const source = `
|
||||
const source = `
|
||||
<html>
|
||||
<head>
|
||||
${css}
|
||||
|
|
@ -82,79 +79,79 @@ odoo.define('payment_hyperpay.payment_hyperpay', function (require) {
|
|||
}
|
||||
}
|
||||
</script>
|
||||
${html || ''}
|
||||
${html || ""}
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
`;
|
||||
|
||||
return getBlobURL(source, 'text/html')
|
||||
}
|
||||
return getBlobURL(source, "text/html");
|
||||
};
|
||||
|
||||
var HyperpayPaymentForm = publicWidget.Widget.extend({
|
||||
init: function() {
|
||||
this.tx_id = $('.clasic_hyperpay_tx').val();
|
||||
var HyperpayPaymentForm = publicWidget.Widget.extend({
|
||||
init: function () {
|
||||
this.tx_id = $(".clasic_hyperpay_tx").val();
|
||||
this._initBlockUI(_t("Loading..."));
|
||||
this.start();
|
||||
},
|
||||
start: function() {
|
||||
start: function () {
|
||||
var self = this;
|
||||
self._createHyperpayCheckoutId();
|
||||
},
|
||||
_createHyperpayCheckoutId: function() {
|
||||
_createHyperpayCheckoutId: function () {
|
||||
var self = this;
|
||||
ajax.jsonRpc('/payment/hyperpay/checkout/create', 'call', {
|
||||
'txId': self.tx_id
|
||||
})
|
||||
.then(function (result) {
|
||||
ajax.jsonRpc("/payment/hyperpay/checkout/create", "call", {
|
||||
txId: self.tx_id,
|
||||
}).then(function (result) {
|
||||
if (result) {
|
||||
self._renderHyperpayModal(result.checkoutId, result.domain, result.base_url,result.data_brands,result.acq);
|
||||
self._renderHyperpayModal(result.checkoutId, result.domain, result.base_url, result.data_brands, result.acq);
|
||||
} else {
|
||||
console.log('Error Occured');
|
||||
console.log("Error Occured");
|
||||
}
|
||||
});
|
||||
},
|
||||
_renderHyperpayModal: function(checkoutId, domain, base_url,data_brands,acq) {
|
||||
var self = this;
|
||||
try{
|
||||
var $modal_html = $($('.payment_hyper_modal').get()[0]);
|
||||
$modal_html.appendTo($('body')).modal({keyboard: false, backdrop: 'static'});
|
||||
var style_css = '<link rel="stylesheet" href="'+base_url+'/payment_hyperpay/static/src/css/hyperpay_style.css" />'
|
||||
var script = '<script async src="'+domain+'/v1/paymentWidgets.js?checkoutId='+checkoutId+'"></script>'
|
||||
var js_script = '<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>'
|
||||
var shopperResultUrlTag = '<form action="'+base_url+'/payment/hyperpay/result?acq='+acq+'" class="paymentWidgets" data-brands="'+data_brands+'"></form>'
|
||||
console.log(shopperResultUrlTag);
|
||||
var theIframe = document.createElement("iframe");
|
||||
theIframe.id = "hyperpay_iframe";
|
||||
theIframe.style = "display:none";
|
||||
var html = script + shopperResultUrlTag;
|
||||
|
||||
const url = getGeneratedPageURL({
|
||||
html: html,
|
||||
css: style_css,
|
||||
js: js_script
|
||||
})
|
||||
theIframe.src = url;
|
||||
$('#hyperpay-modal-body')[0].appendChild(theIframe);
|
||||
$modal_html.modal('show');
|
||||
}
|
||||
catch(err){
|
||||
console.log('component error:', err);
|
||||
}
|
||||
_renderHyperpayModal: function (checkoutId, domain, base_url, data_brands, acq) {
|
||||
var self = this;
|
||||
try {
|
||||
var $modal_html = $($(".payment_hyper_modal").get()[0]);
|
||||
$modal_html.appendTo($("body")).modal({ keyboard: false, backdrop: "static" });
|
||||
var style_css = '<link rel="stylesheet" href="' + base_url + '/payment_hyperpay/static/src/css/hyperpay_style.css" />';
|
||||
var script = '<script async src="' + domain + "/v1/paymentWidgets.js?checkoutId=" + checkoutId + '"></script>';
|
||||
var js_script = '<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>';
|
||||
var shopperResultUrlTag =
|
||||
'<form action="' +
|
||||
base_url +
|
||||
"/payment/hyperpay/result?acq=" +
|
||||
acq +
|
||||
'" class="paymentWidgets" data-brands="' +
|
||||
data_brands +
|
||||
'"></form>';
|
||||
console.log(shopperResultUrlTag);
|
||||
var theIframe = document.createElement("iframe");
|
||||
theIframe.id = "hyperpay_iframe";
|
||||
theIframe.style = "display:none";
|
||||
var html = script + shopperResultUrlTag;
|
||||
|
||||
const url = getGeneratedPageURL({
|
||||
html: html,
|
||||
css: style_css,
|
||||
js: js_script,
|
||||
});
|
||||
theIframe.src = url;
|
||||
$("#hyperpay-modal-body")[0].appendChild(theIframe);
|
||||
$modal_html.modal("show");
|
||||
} catch (err) {
|
||||
console.log("component error:", err);
|
||||
}
|
||||
},
|
||||
_initBlockUI: function(message) {
|
||||
_initBlockUI: function (message) {
|
||||
if ($.blockUI) {
|
||||
$.blockUI({
|
||||
'message': '<h2 class="text-white"><img src="/web/static/src/img/spin.png" class="fa-pulse"/>' +
|
||||
' <br />' + message +
|
||||
'</h2>'
|
||||
message: '<h2 class="text-white"><img src="/web/static/src/img/spin.png" class="fa-pulse"/>' + " <br />" + message + "</h2>",
|
||||
});
|
||||
}
|
||||
$("#o_payment_form_pay").attr('disabled', 'disabled');
|
||||
$("#o_payment_form_pay").attr("disabled", "disabled");
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
new HyperpayPaymentForm();
|
||||
|
||||
new HyperpayPaymentForm();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates id="hyperpay" xml:space="preserve">
|
||||
<t t-name="payment_hyperpay.modal">
|
||||
<div class="modal" tabindex="-1" role="dialog" id="payment_hyperpay_modal">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title">Hyperpay Payment</h4>
|
||||
<button id="hyperpay_close" type="button" class="close" data-dismiss="modal" aria-label="Close">&times;</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div id="hyperpay-modal-body">
|
||||
<div class="hyperpay_loader" style="margin:auto;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
|
|
@ -4,15 +4,15 @@
|
|||
|
||||
<record id="acquirer_form_hyperpay" model="ir.ui.view">
|
||||
<field name="name">provider.form.hyperpay</field>
|
||||
<field name="model">payment.provider</field>
|
||||
<field name="inherit_id" ref="payment.payment_provider_form"/>
|
||||
<field name="model">payment.acquirer</field>
|
||||
<field name="inherit_id" ref="payment.acquirer_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<group name='provider_credentials' position='inside'>
|
||||
<group attrs="{'invisible': [('code', '!=', 'hyperpay')]}">
|
||||
<xpath expr='//group[@name="acquirer"]' position='inside'>
|
||||
<group attrs="{'invisible': [('provider', '!=', 'hyperpay')]}">
|
||||
<field name="hyperpay_merchant_id"/>
|
||||
<field name="hyperpay_authorization"/>
|
||||
</group>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
<template id="payment_hyperpay" inherit_id="website.assets_frontend" name="payment_hyperpay">
|
||||
<xpath expr="." position="inside">
|
||||
<!--<script type="text/javascript" src='/payment_hyperpay/static/src/js/payment_form.js'></script>-->
|
||||
<link rel="stylesheet" href="/payment_hyperpay/static/src/css/loader.css" />
|
||||
</xpath>
|
||||
</template>
|
||||
|
|
|
|||
Loading…
Reference in New Issue