Commit 37a63546 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Rafael Monnerat

slapos_payzen: Start Moving SlapOS Payzen to REST API

parent eb35deda
from DateTime import DateTime
state = context.getSimulationState()
if (state != 'started') or (context.getPaymentMode() != 'payzen'):
return
else:
_, transaction_id = context.PaymentTransaction_getPayzenId()
#if (state != 'started') or (context.getPaymentMode() != 'payzen'):
# return
#else:
_, transaction_id = context.PaymentTransaction_getPayzenId()
if transaction_id is not None:
if transaction_id is not None:
# so the payment is registered in payzen
context.PaymentTransaction_createPayzenEvent().updateStatus()
......@@ -13,75 +13,70 @@ transaction = payzen_event.getDestinationValue()
if transaction is None:
raise ValueError("Unable to find related transaction")
assert signature in (True, False)
if signature is False:
# signature is wrong, bye bye
payzen_event.confirm(comment='Signature does not match')
return
isTransitionPossible = context.getPortalObject().portal_workflow.isTransitionPossible
error_code = data_kw['errorCode']
if error_code == '2':
status = data_kw['status']
answer = data_kw['answer']
if status != "SUCCESS":
error_code = answer["error_code"]
if error_code == "PSP_010":
# Transaction Not Found
transaction_date, _ = transaction.PaymentTransaction_getPayzenId()
# Mark on payment transaction history log that transaction was not processed yet
payzen_event.confirm()
payzen_event.acknowledge(comment='Transaction not found on payzen side.')
if int(DateTime()) - int(transaction_date) > 86400:
if isTransitionPossible(transaction, 'cancel'):
transaction.cancel(comment='Aborting unknown payzen payment.')
else:
#if int(DateTime()) - int(transaction_date) > 86400:
# if isTransitionPossible(transaction, 'cancel'):
# pass
# transaction.cancel(comment='Aborting unknown payzen payment.')
#else:
# Comment the last part until all transaction are using the new REST Api and order_id
storeWorkflowComment(transaction,
'Error code 2 (Not found) did not changed the document state.')
'Error code PSP_010 (Not found) did not changed the document state.')
return
else:
# Unknown errorCode
payzen_event.confirm(comment='Unknown errorCode %r' % error_code)
return
elif error_code == '0':
transaction_code_mapping = {
'0': 'Initial (being treated)',
'1': 'To be validated ',
'2': 'To be forced - Contact issuer',
'3': 'To be validated and authorized',
'4': 'Waiting for submission',
'5': 'Waiting for authorization',
'6': 'Submitted',
'7': 'Expired',
'8': 'Refused',
'9': 'Cancelled',
'10': 'Waiting',
'11': 'Being submitted',
'12': 'Being authorized',
'13': 'Failed',
}
mark_transaction_id_list = ['0', '1', '3', '5', '10', '11', '12']
continue_transaction_id_list = ['4', '6']
cancel_transaction_id_list = ['8']
transaction_status = data_kw['transactionStatus']
transaction_status_description = transaction_code_mapping.get(transaction_status, None)
if transaction_status_description is None:
payzen_event.confirm(comment='Unknown transactionStatus %r' % transaction_status)
transaction_list = answer["transactions"]
if len(transaction_list) != 1:
# Unexpected Number of Transactions
payzen_event.confirm(comment='Unexpected Number of Transaction for this order')
return
if transaction_status in mark_transaction_id_list:
transaction_kw = transaction_list[0]
# See Full Status list at https://payzen.io/en-EN/rest/V4.0/api/kb/status_reference.html
mark_transaction_id_list = [
'AUTHORISED_TO_VALIDATE',
'WAITING_AUTHORISATION',
'WAITING_AUTHORISATION_TO_VALIDATE',
]
continue_transaction_id_list = ['AUTHORISED', 'CAPTURED', 'PARTIALLY_AUTHORISED']
cancel_transaction_id_list = ['REFUSED']
transaction_status = transaction_kw['detailedStatus']
if transaction_status in mark_transaction_id_list:
# Mark on payment transaction history log that transaction was not processed yet
storeWorkflowComment(transaction, 'Transaction status %s (%s) did not changed the document state' % (transaction_status, transaction_status_description))
storeWorkflowComment(transaction, 'Transaction status %s did not changed the document state' % (transaction_status))
payzen_event.confirm()
payzen_event.acknowledge(comment='Automatic acknowledge as result of correct communication')
if isTransitionPossible(transaction, 'confirm'):
transaction.confirm(comment='Confirmed as really saw in PayZen.')
elif transaction_status in continue_transaction_id_list:
elif transaction_status in continue_transaction_id_list:
# Check authAmount and authDevise and if match, stop transaction
auth_amount = int(data_kw['authAmount'])
auth_devise = data_kw['authDevise']
auth_amount = int(transaction_kw['transactionDetails']['cardDetails']['authorizationResponse']['amount'])
auth_devise = transaction_kw['transactionDetails']['cardDetails']['authorizationResponse']['currency']
transaction_amount = int((round(transaction.PaymentTransaction_getTotalPayablePrice(), 2) * -100))
if transaction_amount != auth_amount:
payzen_event.confirm(comment='Received amount (%r) does not match stored on transaction (%r)'% (auth_amount, transaction_amount))
return
transaction_devise = transaction.getResourceValue().Currency_getIntegrationMapping()
transaction_devise = transaction.getResourceReference()
if transaction_devise != auth_devise:
payzen_event.confirm(comment='Received devise (%r) does not match stored on transaction (%r)'% (auth_devise, transaction_devise))
return
......@@ -100,17 +95,13 @@ elif error_code == '0':
else:
payzen_event.confirm(comment='Expected to put transaction in stopped state, but achieved only %s state' % transaction.getSimulationState())
elif transaction_status in cancel_transaction_id_list:
elif transaction_status in cancel_transaction_id_list:
payzen_event.confirm()
payzen_event.acknowledge(comment='Refused payzen payment.')
if isTransitionPossible(transaction, 'cancel'):
transaction.cancel(comment='Aborting refused payzen payment.')
return
else:
payzen_event.confirm(comment='Transaction status %r (%r) is not supported' \
% (transaction_status, transaction_status_description))
return
else:
# Unknown errorCode
payzen_event.confirm(comment='Unknown errorCode %r' % error_code)
payzen_event.confirm(comment='Transaction status %r is not supported' \
% (transaction_status))
return
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>data_kw, signature, REQUEST=None</string> </value>
<value> <string>data_kw, REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -29,6 +29,7 @@ payzen_dict = {
'vads_amount': str(int(round((payment_transaction.PaymentTransaction_getTotalPayablePrice() * -100), 0))),
'vads_trans_date': now.toZone('UTC').asdatetime().strftime('%Y%m%d%H%M%S'),
'vads_trans_id': transaction_id,
'vads_order_id': transaction_id,
'vads_language': 'en',
'vads_url_cancel': vads_url_cancel,
'vads_url_error': vads_url_error,
......
......@@ -6,20 +6,20 @@ if transaction_id is None:
raise ValueError('Transaction not registered in payzen integration tool')
payment_service = payzen_event.getSourceValue(portal_type="Payzen Service")
data_kw, signature, sent_text, received_text = payment_service.soap_getInfo(
data_kw, sent_text, received_text = payment_service.rest_getInfo(
transaction_date.toZone('UTC').asdatetime(),
transaction_id)
# SENT
sent = payzen_event.newContent(
title='Sent SOAP',
title='Sent Data',
portal_type='Payzen Event Message',
text_content=sent_text)
# RECEIVED
payzen_event.newContent(
title='Received SOAP',
title='Received Data',
portal_type='Payzen Event Message',
text_content=received_text,
predecessor_value=sent)
payzen_event.PayzenEvent_processUpdate(data_kw, signature)
payzen_event.PayzenEvent_processUpdate(data_kw)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment