This commit is contained in:
gsinghpal
2026-02-25 09:40:41 -05:00
parent 0e1aebe60b
commit e71bc503f9
69 changed files with 7537 additions and 82 deletions

View File

@@ -1,5 +1,6 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import json
import logging
from odoo import _, api, fields, models
@@ -129,22 +130,29 @@ class PoyntTerminal(models.Model):
if order_id:
payment_request['orderId'] = order_id
store_id = self.store_id_poynt or self.provider_id.poynt_store_id or ''
data_str = json.dumps({
'action': 'sale',
'purchaseAmount': minor_amount,
'tipAmount': 0,
'currency': currency.name,
'referenceId': reference,
'callbackUrl': self._get_terminal_callback_url(),
})
try:
result = self.provider_id._poynt_make_request(
'POST',
f'cloudMessages',
'cloudMessages',
business_scoped=False,
payload={
'businessId': self.provider_id.poynt_business_id,
'storeId': store_id,
'deviceId': self.device_id,
'ttl': 300,
'serialNum': self.serial_number or '',
'data': {
'action': 'sale',
'purchaseAmount': minor_amount,
'tipAmount': 0,
'currency': currency.name,
'referenceId': reference,
'callbackUrl': self._get_terminal_callback_url(),
},
'data': data_str,
},
)
_logger.info(
@@ -171,6 +179,9 @@ class PoyntTerminal(models.Model):
def action_check_terminal_payment_status(self, reference):
"""Poll for the status of a terminal payment.
Searches Poynt transactions by referenceId (set via cloud message)
and falls back to notes field.
:param str reference: The Odoo transaction reference.
:return: Dict with status and transaction data if completed.
:rtype: dict
@@ -182,15 +193,37 @@ class PoyntTerminal(models.Model):
'GET',
'transactions',
params={
'notes': reference,
'limit': 1,
'referenceId': reference,
'limit': 5,
},
)
transactions = txn_result.get('transactions', [])
if not transactions:
txn_result = self.provider_id._poynt_make_request(
'GET',
'transactions',
params={
'notes': reference,
'limit': 5,
},
)
transactions = txn_result.get('transactions', [])
if not transactions:
return {'status': 'pending', 'message': 'Waiting for terminal response...'}
for txn in transactions:
status = txn.get('status', 'UNKNOWN')
if status in ('CAPTURED', 'AUTHORIZED', 'SETTLED'):
return {
'status': status,
'transaction_id': txn.get('id', ''),
'funding_source': txn.get('fundingSource', {}),
'amounts': txn.get('amounts', {}),
}
txn = transactions[0]
return {
'status': txn.get('status', 'UNKNOWN'),