changes
This commit is contained in:
@@ -41,16 +41,37 @@ def build_api_headers(access_token, request_id=None):
|
||||
:return: The request headers dict.
|
||||
:rtype: dict
|
||||
"""
|
||||
if not request_id:
|
||||
request_id = generate_request_id()
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Api-Version': const.API_VERSION,
|
||||
'api-version': const.API_VERSION,
|
||||
'Accept': 'application/json',
|
||||
'Authorization': f'Bearer {access_token}',
|
||||
'Poynt-Request-Id': request_id,
|
||||
}
|
||||
if request_id:
|
||||
headers['POYNT-REQUEST-ID'] = request_id
|
||||
return headers
|
||||
|
||||
|
||||
def clean_application_id(raw_app_id):
|
||||
"""Extract the urn:aid:... portion from a raw application ID string.
|
||||
|
||||
Poynt developer portal sometimes displays the app UUID and URN together
|
||||
(e.g. 'a73a2957-...=urn:aid:fb0ba879-...'). The JWT needs only the URN.
|
||||
|
||||
:param str raw_app_id: The raw application ID string.
|
||||
:return: The cleaned application ID (urn:aid:...).
|
||||
:rtype: str
|
||||
"""
|
||||
if not raw_app_id:
|
||||
return raw_app_id
|
||||
raw_app_id = raw_app_id.strip()
|
||||
if 'urn:aid:' in raw_app_id:
|
||||
idx = raw_app_id.index('urn:aid:')
|
||||
return raw_app_id[idx:]
|
||||
return raw_app_id
|
||||
|
||||
|
||||
def create_self_signed_jwt(application_id, private_key_pem):
|
||||
"""Create a self-signed JWT for Poynt OAuth2 token request.
|
||||
|
||||
@@ -81,10 +102,12 @@ def create_self_signed_jwt(application_id, private_key_pem):
|
||||
|
||||
private_key = load_pem_private_key(key_bytes, password=None, backend=default_backend())
|
||||
|
||||
app_id = clean_application_id(application_id)
|
||||
|
||||
now = int(time.time())
|
||||
payload = {
|
||||
'iss': application_id,
|
||||
'sub': application_id,
|
||||
'iss': app_id,
|
||||
'sub': app_id,
|
||||
'aud': 'https://services.poynt.net',
|
||||
'iat': now,
|
||||
'exp': now + 300,
|
||||
@@ -162,12 +185,15 @@ def get_poynt_status(status_str):
|
||||
return 'error'
|
||||
|
||||
|
||||
def build_order_payload(reference, amount, currency, items=None, notes=''):
|
||||
def build_order_payload(reference, amount, currency, business_id='',
|
||||
store_id='', items=None, notes=''):
|
||||
"""Build a Poynt order creation payload.
|
||||
|
||||
:param str reference: The Odoo transaction reference.
|
||||
:param float amount: The order total in major currency units.
|
||||
:param recordset currency: The currency record.
|
||||
:param str business_id: The Poynt business UUID.
|
||||
:param str store_id: The Poynt store UUID.
|
||||
:param list items: Optional list of order item dicts.
|
||||
:param str notes: Optional order notes.
|
||||
:return: The Poynt-formatted order payload.
|
||||
@@ -185,6 +211,15 @@ def build_order_payload(reference, amount, currency, items=None, notes=''):
|
||||
'unitOfMeasure': 'EACH',
|
||||
}]
|
||||
|
||||
context = {
|
||||
'source': 'WEB',
|
||||
'sourceApp': 'odoo.fusion_poynt',
|
||||
}
|
||||
if business_id:
|
||||
context['businessId'] = business_id
|
||||
if store_id:
|
||||
context['storeId'] = store_id
|
||||
|
||||
return {
|
||||
'items': items,
|
||||
'amounts': {
|
||||
@@ -195,10 +230,7 @@ def build_order_payload(reference, amount, currency, items=None, notes=''):
|
||||
'netTotal': minor_amount,
|
||||
'currency': currency.name,
|
||||
},
|
||||
'context': {
|
||||
'source': 'WEB',
|
||||
'transactionInstruction': 'ONLINE_AUTH_REQUIRED',
|
||||
},
|
||||
'context': context,
|
||||
'statuses': {
|
||||
'status': 'OPENED',
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user