Ir al contenido
Menú
Se marcó esta pregunta
350 Vistas

Hi, I'm new to Odoo. I'm building a payment acquirer for a payment gateway in Odoo 15.

When I click Pay, the button just keeps loading and does not redirect to the payment gateway page as expected. 

The button is stuck on loading and doesn't redirect.

The XHR in the console, when I click Transaction, always shows this:

<function PaymentPortal.payment_transaction at 0x00000280C7F6F8B0>, /payment/transaction: Function declared as capable of handling request of type 'json' but called with a request of type 'http'

If I use the _get_specific_processing_values function, there's no error. The log looks like this:

2025-03-11 03:16:42,209 14908 INFO db_odoo odoo.addons.payment_duitku.models.duitku_transaction: payment request response: {'api_url': '(the link can be clicked)', 'expiryPeriod': 1440, 'merchantOrderId': 'INV/2025/00001', 'reference': 'XXXXXXX'}

But if I use _get_specific_rendering_values, the function never gets executed.

Is there any setting in the form/module that determines which one Odoo decides to run?


here my function  _get_specific_proccesing_values or _get_specific_rendering_values

def _get_specific_processing_values(self, processing_values):
print("running processing value")
""" Override of payment to return Duitku-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 provider-specific processing values
:rtype: dict
"""
res = super()._get_specific_processing_values(processing_values)
print("Processing Values--", processing_values)
if self.provider != 'duitku':
return res

base_url = self.acquirer_id.get_base_url()

duitku_tx_values = dict()

item_details, customer_detail, processing_values = self.duitku_prepare_payment_values(processing_values)
processing_values['itemDetails'] = item_details
processing_values['customerDetail'] = customer_detail
processing_values['amount'] = processing_values['amount']
processing_values['merchantOrderId'] = processing_values['reference']
processing_values['productDetails'] = '%s: %s' % (self.company_id.name, processing_values['reference'])
processing_values['customerVaName'] = processing_values['billing_partner_first_name']
processing_values['merchantUserInfo'] = processing_values['billing_partner_first_name']
processing_values['email'] = processing_values['billing_partner_email']
processing_values['callbackUrl'] = urls.url_join(base_url, DuitkuController._callback_url)
processing_values['returnUrl'] = urls.url_join(base_url, DuitkuController._return_url)
processing_values['expiryPeriod'] = self.acquirer_id.duitku_expiry
processing_values['phoneNumber'] = processing_values['billing_partner_phone']
processing_values['merchantCode'] = self.acquirer_id.duitku_merchant_code
processing_values['apiKey'] = self.acquirer_id.duitku_api_key

payload, headers = self._duitku_prepare_payment_request_payload(processing_values)
_logger.info("sending '/createInvoice' request for link creation:\n%s", pprint.pformat(payload))
payment_data = self.acquirer_id._duitku_make_request('/createInvoice', payload=payload, headers=headers)



# if the merchantOrderId already exists in Duitku and you try to pay again, the createInvoice return
# ("MerchantOrderId":"Bill already paid. (Parameter \u0027MerchantOrderId\u0027)")
# So her we check, if he response is string thne
if isinstance(payment_data, str):
self._set_error(payment_data)
raise ValidationError(
"Duitku: " + _("Create Invoice response %(ref)s.", ref=payment_data)
)

self.reference = payment_data.get('reference')

duitku_tx_values.update({
'api_url': payment_data.get('paymentUrl'),
# 'payment_url': payment_data['paymentUrl'],
'merchantOrderId': processing_values['merchantOrderId'],
'expiryPeriod': self.acquirer_id.duitku_expiry,
'reference': payment_data['reference']
})
# return duitku_tx_values
_logger.info("payment request response:\n%s", pprint.pformat(duitku_tx_values))
return duitku_tx_values


function make request in my model Payment Acquirer

def _duitku_make_request(self, endpoint, payload=None, headers=None, method='POST'):
print("running make request...")
""" Make a request at duitku endpoint.

Note: self.ensure_one()

:param str endpoint: The endpoint to be reached by the request
:param dict data: The payload of the request
:param dict headers: The headers of the request
:param str method: The HTTP method of the request
:return The JSON-formatted content of the response
:rtype: dict
:raise: ValidationError if an HTTP error occurs
"""
endpoint = endpoint.strip("/")
url = urls.url_join(self._duitku_get_api_url(), endpoint)
print("running function make request url is... ", url)
url = urls.url_join(self._duitku_get_api_url(), endpoint)
try:
req = requests.request(method, url, json=payload, headers=headers, timeout=60)
req.raise_for_status()
response = req.json()
if endpoint == 'transactionStatus':
if response['statusCode'] != '00':
raise ValidationError(_("Payment has not been successfully paid but a callback is triggered."
"Could be because someone is trying to cheat the system."))
if endpoint == 'createInvoice':
if req.status_code != 200:
_logger.info('There was an error when creating a transasction. The data sent was %s',
pprint.pformat(req))
_logger.info('Duitku create transaction response %s', pprint.pformat(response))
raise ValidationError(_("%s") % response)
except requests.exceptions.ConnectionError:
_logger.exception("unable to reach endpoint at %s", url)
raise ValidationError("Duitku: " + _("Could not establish the connection to the API."))
except requests.exceptions.HTTPError as error:
_logger.exception(
"invalid API request at %s with data %s: %s", url, payload, error.response.text
)
raise ValidationError("Duit: " + _("The communication with the API failed."))
return response


Thank you before!

Avatar
Descartar