Commit 673cba0a authored by Alain Takoudjou's avatar Alain Takoudjou

slapos_payzen migrated to new bt format

parent 4121077a
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
context.setStartDate(start_date)
......@@ -48,14 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
if REQUEST is not None:\n
raise Unauthorized\n
context.setStartDate(start_date)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>start_date, REQUEST=None</string> </value>
......
context.getPortalObject().portal_orders.slapos_payment_transaction_builder.build(
activate_kw={'tag': tag}
)
context.activate(after_tag=tag).getId()
......@@ -48,14 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>context.getPortalObject().portal_orders.slapos_payment_transaction_builder.build(\n
activate_kw={\'tag\': tag}\n
)\n
context.activate(after_tag=tag).getId()\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>tag, fixit, params</string> </value>
......
portal = context.getPortalObject()
portal.portal_catalog.searchAndActivate(
portal_type="Payment Transaction",
simulation_state=["confirmed"],
causality_state=["draft"],
payment_mode_uid=portal.portal_categories.payment_mode.payzen.getUid(),
method_id='PaymentTransaction_startPayzenPayment',
packet_size=1, # just one to minimise errors
activate_kw={'tag': tag}
)
context.activate(after_tag=tag).getId()
......@@ -48,22 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n
\n
portal.portal_catalog.searchAndActivate(\n
portal_type="Payment Transaction", \n
simulation_state=["confirmed"],\n
causality_state=["draft"],\n
payment_mode_uid=portal.portal_categories.payment_mode.payzen.getUid(),\n
method_id=\'PaymentTransaction_startPayzenPayment\',\n
packet_size=1, # just one to minimise errors\n
activate_kw={\'tag\': tag}\n
)\n
context.activate(after_tag=tag).getId()\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>tag, fixit, params</string> </value>
......
portal = context.getPortalObject()
portal.portal_catalog.searchAndActivate(
portal_type="Payment Transaction",
simulation_state=["started"],
causality_state=["draft"],
payment_mode_uid=portal.portal_categories.payment_mode.payzen.getUid(),
method_id='PaymentTransaction_updateStatus',
packet_size=1, # just one to minimise errors
activate_kw={'tag': tag}
)
context.activate(after_tag=tag).getId()
......@@ -48,21 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n
portal.portal_catalog.searchAndActivate(\n
portal_type="Payment Transaction", \n
simulation_state=["started"],\n
causality_state=["draft"],\n
payment_mode_uid=portal.portal_categories.payment_mode.payzen.getUid(),\n
method_id=\'PaymentTransaction_updateStatus\',\n
packet_size=1, # just one to minimise errors\n
activate_kw={\'tag\': tag}\n
)\n
context.activate(after_tag=tag).getId()\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>tag, fixit, params</string> </value>
......
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
payment_service = portal.portal_secure_payments.find(
service_reference=portal.portal_preferences.getPreferredPayzenPaymentServiceReference())
return payment_service.getRelativeUrl()
......@@ -48,19 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
if REQUEST is not None:\n
raise Unauthorized\n
\n
portal = context.getPortalObject()\n
payment_service = portal.portal_secure_payments.find(\n
service_reference=portal.portal_preferences.getPreferredPayzenPaymentServiceReference())\n
\n
return payment_service.getRelativeUrl()\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None, **kw</string> </value>
......
portal = context.getPortalObject()
integration_site = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite())
relative_url = context.getRelativeUrl()
# Only EUR is supported for now
assert relative_url == 'currency_module/EUR'
return integration_site.getMappingFromCategory('resource/%s' % relative_url).split('/', 1)[-1]
......@@ -48,17 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n
integration_site = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite())\n
\n
relative_url = context.getRelativeUrl()\n
# Only EUR is supported for now\n
assert relative_url == \'currency_module/EUR\'\n
return integration_site.getMappingFromCategory(\'resource/%s\' % relative_url).split(\'/\', 1)[-1]\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
......
from Products.ERP5Type.Document import newTempSimulationMovement
portal = context.getPortalObject()
select_dict = {'causality_payment_transaction_related_uid': None}
select_kw = kwargs.copy()
select_kw.pop('portal_type', None)
select_kw.pop('delivery_relative_url_list', None)
select_kw.update(
portal_type='Sale Invoice Transaction',
simulation_state='stopped',
default_payment_mode_uid=portal.portal_categories.payment_mode.payzen.getUid(),
limit=10, # do only some in one shot
select_dict=select_dict,
left_join_list=select_dict.keys(),
causality_payment_transaction_related_uid=None,
)
default_source_uid=portal.restrictedTraverse('account_module/receivable').getUid()
movement_list = []
id = 1
for invoice in portal.portal_catalog(**select_kw):
invoice.getObject().serialize() # in order to avoid selection in same transaction
quantity = 0.
for movement in invoice.searchFolder(portal_type='Sale Invoice Transaction Line',
default_source_uid=default_source_uid):
quantity += movement.getQuantity()
temp_movement_kw = dict(
causality=invoice.getRelativeUrl(),
source_section=invoice.getSourceSection(),
destination_section=invoice.getDestinationSection(),
resource=invoice.getResource(),
price_currency=invoice.getResource(),
start_date=invoice.getStartDate(),
stop_date=invoice.getStopDate(),
specialise=invoice.getSpecialise(),
payment_mode=invoice.getPaymentMode(),
source_payment='organisation_module/slapos/bank_account', # the other place defnied: business process
)
temp_movement_rec = newTempSimulationMovement(
portal, str(id),
quantity=-1 * quantity,
source='account_module/receivable',
destination='account_module/payable',
**temp_movement_kw
)
id += 1
temp_movement_bank = newTempSimulationMovement(
portal, str(id),
quantity=1 * quantity,
source='account_module/bank',
destination='account_module/bank',
**temp_movement_kw
)
id += 1
movement_list.extend([temp_movement_rec, temp_movement_bank])
return movement_list
......@@ -48,68 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from Products.ERP5Type.Document import newTempSimulationMovement\n
\n
portal = context.getPortalObject()\n
select_dict = {\'causality_payment_transaction_related_uid\': None}\n
\n
select_kw = kwargs.copy()\n
select_kw.pop(\'portal_type\', None)\n
select_kw.pop(\'delivery_relative_url_list\', None)\n
select_kw.update(\n
portal_type=\'Sale Invoice Transaction\',\n
simulation_state=\'stopped\',\n
default_payment_mode_uid=portal.portal_categories.payment_mode.payzen.getUid(),\n
limit=10, # do only some in one shot\n
select_dict=select_dict,\n
left_join_list=select_dict.keys(),\n
causality_payment_transaction_related_uid=None,\n
)\n
\n
default_source_uid=portal.restrictedTraverse(\'account_module/receivable\').getUid()\n
movement_list = []\n
id = 1\n
for invoice in portal.portal_catalog(**select_kw):\n
invoice.getObject().serialize() # in order to avoid selection in same transaction\n
quantity = 0.\n
for movement in invoice.searchFolder(portal_type=\'Sale Invoice Transaction Line\',\n
default_source_uid=default_source_uid):\n
quantity += movement.getQuantity()\n
temp_movement_kw = dict(\n
causality=invoice.getRelativeUrl(),\n
source_section=invoice.getSourceSection(),\n
destination_section=invoice.getDestinationSection(),\n
resource=invoice.getResource(),\n
price_currency=invoice.getResource(),\n
start_date=invoice.getStartDate(),\n
stop_date=invoice.getStopDate(),\n
specialise=invoice.getSpecialise(),\n
payment_mode=invoice.getPaymentMode(),\n
source_payment=\'organisation_module/slapos/bank_account\', # the other place defnied: business process\n
)\n
temp_movement_rec = newTempSimulationMovement(\n
portal, str(id),\n
quantity=-1 * quantity,\n
source=\'account_module/receivable\',\n
destination=\'account_module/payable\',\n
**temp_movement_kw\n
)\n
id += 1\n
temp_movement_bank = newTempSimulationMovement(\n
portal, str(id),\n
quantity=1 * quantity,\n
source=\'account_module/bank\',\n
destination=\'account_module/bank\',\n
**temp_movement_kw\n
)\n
id += 1\n
movement_list.extend([temp_movement_rec, temp_movement_bank])\n
\n
return movement_list\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>*args, **kwargs</string> </value>
......
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
kw.update({
'portal_type': 'Payzen Event',
'source': portal.Base_getPayzenServiceRelativeUrl(),
'destination_value': context,
})
return portal.system_event_module.newContent(**kw)
......@@ -48,23 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
if REQUEST is not None:\n
raise Unauthorized\n
\n
portal = context.getPortalObject()\n
\n
kw.update({\n
\'portal_type\': \'Payzen Event\',\n
\'source\': portal.Base_getPayzenServiceRelativeUrl(),\n
\'destination_value\': context,\n
})\n
\n
return portal.system_event_module.newContent(**kw)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None, **kw</string> </value>
......
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
integration_site = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite())
transaction_date, transaction_id = context.PaymentTransaction_getPayzenId()
if transaction_id is not None:
# XXX raise?
return None, None
now = DateTime().toZone('UTC')
today = now.asdatetime().strftime('%Y%m%d')
transaction_id = str(portal.portal_ids.generateNewId(
id_group='%s_%s' % (integration_site.getRelativeUrl(), today),
id_generator='uid')).zfill(6)
mapping_id = '%s_%s' % (today, transaction_id)
# integration_site.Causality[mapping_id].setDestinationReference(context.getRelativeUrl())
# try:
# integration_site.getCategoryFromMapping('Causality/%s' % mapping_id, create_mapping_line=True, create_mapping=True)
# except ValueError:
# mapping = integration_site.Causality[mapping_id]
# mapping.setDestinationReference('%s' % context.getRelativeUrl())
# else:
# raise ValueError, "Payzen transaction_id already exists"
try:
mapping = integration_site.getCategoryFromMapping(
'Causality/%s' % context.getId().replace('-', '_'),
create_mapping_line=True,
create_mapping=True)
except ValueError:
pass
integration_site.Causality[context.getId().replace('-', '_')].setDestinationReference(mapping_id)
return context.PaymentTransaction_getPayzenId()
......@@ -48,49 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
if REQUEST is not None:\n
raise Unauthorized\n
\n
portal = context.getPortalObject()\n
integration_site = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite())\n
\n
transaction_date, transaction_id = context.PaymentTransaction_getPayzenId()\n
if transaction_id is not None:\n
# XXX raise?\n
return None, None\n
\n
now = DateTime().toZone(\'UTC\')\n
today = now.asdatetime().strftime(\'%Y%m%d\')\n
\n
transaction_id = str(portal.portal_ids.generateNewId(\n
id_group=\'%s_%s\' % (integration_site.getRelativeUrl(), today),\n
id_generator=\'uid\')).zfill(6)\n
\n
mapping_id = \'%s_%s\' % (today, transaction_id)\n
# integration_site.Causality[mapping_id].setDestinationReference(context.getRelativeUrl())\n
# try:\n
# integration_site.getCategoryFromMapping(\'Causality/%s\' % mapping_id, create_mapping_line=True, create_mapping=True)\n
# except ValueError:\n
# mapping = integration_site.Causality[mapping_id]\n
# mapping.setDestinationReference(\'%s\' % context.getRelativeUrl())\n
# else:\n
# raise ValueError, "Payzen transaction_id already exists"\n
\n
try:\n
mapping = integration_site.getCategoryFromMapping(\n
\'Causality/%s\' % context.getId().replace(\'-\', \'_\'),\n
create_mapping_line=True,\n
create_mapping=True)\n
except ValueError:\n
pass\n
integration_site.Causality[context.getId().replace(\'-\', \'_\')].setDestinationReference(mapping_id)\n
\n
return context.PaymentTransaction_getPayzenId()\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value>
......
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
integration_site = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite())
payzen_id = integration_site.getCategoryFromMapping('Causality/%s' % context.getId().replace('-', '_'))
if payzen_id != 'causality/%s' % context.getId().replace('-', '_'):
date, payzen_id = payzen_id.split('_', 1)
return DateTime(date).toZone('UTC'), payzen_id
else:
return None, None
......@@ -48,23 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
if REQUEST is not None:\n
raise Unauthorized\n
\n
portal = context.getPortalObject()\n
integration_site = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite())\n
\n
payzen_id = integration_site.getCategoryFromMapping(\'Causality/%s\' % context.getId().replace(\'-\', \'_\'))\n
if payzen_id != \'causality/%s\' % context.getId().replace(\'-\', \'_\'):\n
date, payzen_id = payzen_id.split(\'_\', 1)\n
return DateTime(date).toZone(\'UTC\'), payzen_id\n
else:\n
return None, None\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value>
......
from DateTime import DateTime
portal = context.getPortalObject()
state = context.getSimulationState()
transaction_amount = int(round((context.PaymentTransaction_getTotalPayablePrice() * -100), 2))
if (state != 'confirmed') or (context.getPaymentMode() != 'payzen') or (transaction_amount == 0):
return
else:
# Request manual payment
context.start(comment='Requested manual payment')
# raise NotImplementedError
# if context.PaymentTransaction_getPreviousPayzenId() is not None:
# # there is previous payment
# context.setStartDate(DateTime())
# context.updateCausalityState()
# portal.system_event_module.newContent(
# title='Transaction %s Payzen registration' % context.getTitle(),
# portal_type='Payzen Event',
# source_value=service,
# destination_value=context).registerPayzen()
# comment='Automatically duplicated in payzen.'
# else:
......@@ -48,33 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from DateTime import DateTime\n
portal = context.getPortalObject()\n
\n
state = context.getSimulationState()\n
transaction_amount = int(round((context.PaymentTransaction_getTotalPayablePrice() * -100), 2))\n
if (state != \'confirmed\') or (context.getPaymentMode() != \'payzen\') or (transaction_amount == 0):\n
return\n
else:\n
# Request manual payment\n
context.start(comment=\'Requested manual payment\')\n
\n
# raise NotImplementedError\n
# if context.PaymentTransaction_getPreviousPayzenId() is not None:\n
# # there is previous payment\n
# context.setStartDate(DateTime())\n
# context.updateCausalityState()\n
# portal.system_event_module.newContent(\n
# title=\'Transaction %s Payzen registration\' % context.getTitle(),\n
# portal_type=\'Payzen Event\',\n
# source_value=service,\n
# destination_value=context).registerPayzen()\n
# comment=\'Automatically duplicated in payzen.\'\n
# else:\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
......
from DateTime import DateTime
portal = context.getPortalObject()
state = context.getSimulationState()
if (state != 'started') or (context.getPaymentMode() != 'payzen'):
return
else:
transaction_date, transaction_id = context.PaymentTransaction_getPayzenId()
if transaction_id is not None:
# so the payment is registered in payzen
context.PaymentTransaction_createPayzenEvent().updateStatus()
......@@ -48,22 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from DateTime import DateTime\n
portal = context.getPortalObject()\n
\n
state = context.getSimulationState()\n
if (state != \'started\') or (context.getPaymentMode() != \'payzen\'):\n
return\n
else:\n
transaction_date, transaction_id = context.PaymentTransaction_getPayzenId()\n
\n
if transaction_id is not None:\n
# so the payment is registered in payzen\n
context.PaymentTransaction_createPayzenEvent().updateStatus()\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
......
......@@ -2,7 +2,7 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5Form" module="Products.ERP5Form.Form"/>
<global name="ERP5 Form" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
......
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
def storeWorkflowComment(ctx, comment):
portal = ctx.getPortalObject()
workflow_tool = portal.portal_workflow
workflow_tool.doActionFor(ctx, 'edit_action', comment=comment)
payzen_event = context
transaction = payzen_event.getDestinationValue()
portal = transaction.getPortalObject()
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':
transaction_date, payzen_id = 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:
storeWorkflowComment(transaction,
'Error code 2 (Not found) did not changed the document state.')
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', '4', '5', '10', '11', '12']
continue_transaction_id_list = ['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)
return
doActionFor = context.getPortalObject().portal_workflow.doActionFor
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))
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:
# Check authAmount and authDevise and if match, stop transaction
auth_amount = int(data_kw['authAmount'])
auth_devise = data_kw['authDevise']
transaction_amount = int(round((transaction.PaymentTransaction_getTotalPayablePrice() * -100), 2))
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()
if transaction_devise != auth_devise:
payzen_event.confirm(comment='Received devise (%r) does not match stored on transaction (%r)'% (auth_devise, transaction_devise))
return
comment = 'PayZen considered as paid.'
if isTransitionPossible(transaction, 'confirm'):
transaction.confirm(comment=comment)
if isTransitionPossible(transaction, 'start'):
transaction.start(comment=comment)
if isTransitionPossible(transaction, 'stop'):
transaction.stop(comment=comment)
if transaction.getSimulationState() == 'stopped':
payzen_event.confirm()
payzen_event.acknowledge(comment='Automatic acknowledge as result of correct communication')
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:
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)
......@@ -48,130 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
from zExceptions import Unauthorized\n
if REQUEST is not None:\n
raise Unauthorized\n
\n
def storeWorkflowComment(ctx, comment):\n
portal = ctx.getPortalObject()\n
workflow_tool = portal.portal_workflow\n
workflow_tool.doActionFor(ctx, \'edit_action\', comment=comment)\n
\n
payzen_event = context\n
transaction = payzen_event.getDestinationValue()\n
portal = transaction.getPortalObject()\n
\n
assert signature in (True, False)\n
if signature is False:\n
# signature is wrong, bye bye\n
payzen_event.confirm(comment=\'Signature does not match\')\n
return\n
\n
isTransitionPossible = context.getPortalObject().portal_workflow.isTransitionPossible\n
\n
error_code = data_kw[\'errorCode\']\n
if error_code == \'2\':\n
transaction_date, payzen_id = transaction.PaymentTransaction_getPayzenId()\n
# Mark on payment transaction history log that transaction was not processed yet\n
payzen_event.confirm()\n
payzen_event.acknowledge(comment=\'Transaction not found on payzen side.\')\n
if int(DateTime()) - int(transaction_date) > 86400:\n
if isTransitionPossible(transaction, \'cancel\'):\n
transaction.cancel(comment=\'Aborting unknown payzen payment.\')\n
else:\n
storeWorkflowComment(transaction, \n
\'Error code 2 (Not found) did not changed the document state.\')\n
return\n
\n
elif error_code == \'0\':\n
transaction_code_mapping = {\n
\'0\': \'Initial (being treated)\',\n
\'1\': \'To be validated \',\n
\'2\': \'To be forced - Contact issuer\',\n
\'3\': \'To be validated and authorized\',\n
\'4\': \'Waiting for submission\',\n
\'5\': \'Waiting for authorization\',\n
\'6\': \'Submitted\',\n
\'7\': \'Expired\',\n
\'8\': \'Refused\',\n
\'9\': \'Cancelled\',\n
\'10\': \'Waiting\',\n
\'11\': \'Being submitted\',\n
\'12\': \'Being authorized\',\n
\'13\': \'Failed\',\n
}\n
mark_transaction_id_list = [\'0\', \'1\', \'3\', \'4\', \'5\', \'10\', \'11\', \'12\']\n
continue_transaction_id_list = [\'6\']\n
cancel_transaction_id_list = [\'8\']\n
\n
transaction_status = data_kw[\'transactionStatus\']\n
\n
transaction_status_description = transaction_code_mapping.get(transaction_status, None)\n
if transaction_status_description is None:\n
payzen_event.confirm(comment=\'Unknown transactionStatus %r\' % transaction_status)\n
return\n
\n
doActionFor = context.getPortalObject().portal_workflow.doActionFor\n
\n
if transaction_status in mark_transaction_id_list:\n
# Mark on payment transaction history log that transaction was not processed yet\n
storeWorkflowComment(transaction, \'Transaction status %s (%s) did not changed the document state\' % (transaction_status, transaction_status_description))\n
payzen_event.confirm()\n
payzen_event.acknowledge(comment=\'Automatic acknowledge as result of correct communication\')\n
if isTransitionPossible(transaction, \'confirm\'):\n
transaction.confirm(comment=\'Confirmed as really saw in PayZen.\')\n
\n
elif transaction_status in continue_transaction_id_list:\n
# Check authAmount and authDevise and if match, stop transaction\n
auth_amount = int(data_kw[\'authAmount\'])\n
auth_devise = data_kw[\'authDevise\']\n
transaction_amount = int(round((transaction.PaymentTransaction_getTotalPayablePrice() * -100), 2))\n
\n
if transaction_amount != auth_amount:\n
payzen_event.confirm(comment=\'Received amount (%r) does not match stored on transaction (%r)\'% (auth_amount, transaction_amount))\n
return\n
\n
transaction_devise = transaction.getResourceValue().Currency_getIntegrationMapping()\n
if transaction_devise != auth_devise:\n
payzen_event.confirm(comment=\'Received devise (%r) does not match stored on transaction (%r)\'% (auth_devise, transaction_devise))\n
return\n
\n
comment = \'PayZen considered as paid.\'\n
if isTransitionPossible(transaction, \'confirm\'):\n
transaction.confirm(comment=comment)\n
if isTransitionPossible(transaction, \'start\'):\n
transaction.start(comment=comment)\n
if isTransitionPossible(transaction, \'stop\'):\n
transaction.stop(comment=comment)\n
\n
if transaction.getSimulationState() == \'stopped\':\n
payzen_event.confirm()\n
payzen_event.acknowledge(comment=\'Automatic acknowledge as result of correct communication\')\n
else:\n
payzen_event.confirm(comment=\'Expected to put transaction in stopped state, but achieved only %s state\' % transaction.getSimulationState())\n
\n
elif transaction_status in cancel_transaction_id_list:\n
payzen_event.confirm()\n
payzen_event.acknowledge(comment=\'Refused payzen payment.\')\n
if isTransitionPossible(transaction, \'cancel\'):\n
transaction.cancel(comment=\'Aborting refused payzen payment.\')\n
return\n
else:\n
payzen_event.confirm(comment=\'Transaction status %r (%r) is not supported\' \\\n
% (transaction_status, transaction_status_description))\n
return\n
\n
else:\n
# Unknown errorCode\n
payzen_event.confirm(comment=\'Unknown errorCode %r\' % error_code)\n
]]></string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>data_kw, signature, REQUEST=None</string> </value>
......
......@@ -2,7 +2,7 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5Form" module="Products.ERP5Form.Form"/>
<global name="ERP5 Form" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
......
""" Create a reversal transaction from current payzen transaction. """
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
# Check that we are in state that we are waiting for user manual payment
assert context.getPortalType() == 'Sale Invoice Transaction'
assert context.getPaymentMode() == 'payzen'
assert context.getSimulationState() == 'stopped'
assert context.getTotalPrice() != 0
assert context.getSpecialise() == "sale_trade_condition_module/slapos_aggregated_trade_condition"
paid = True
for line in context.getMovementList(portal.getPortalAccountingMovementTypeList()):
node_value = line.getSourceValue(portal_type='Account')
if node_value.getAccountType() == 'asset/receivable':
if not line.hasGroupingReference():
paid = False
break
assert not paid
payment = portal.portal_catalog.getResultValue(
portal_type="Payment Transaction",
simulation_state="started",
default_causality_uid=context.getUid(),
default_payment_mode_uid=portal.portal_categories.payment_mode.payzen.getUid(),
)
assert payment is not None
assert payment.getSimulationState() == 'started'
assert payment.getPaymentMode() == 'payzen'
assert payment.PaymentTransaction_getPayzenId()[1] is None
# Should be safe now to fix everything
context.edit(payment_mode=None)
payment.edit(payment_mode=None)
reversal_transaction = context.Base_createCloneDocument(batch_mode=1)
payment.cancel(
comment="Reversal sale invoice transaction created %s" % reversal_transaction.getRelativeUrl())
reversal_transaction.edit(
title="Reversal Transaction for %s" % context.getTitle(),
causality_value=context,
description="Reversal Transaction for %s" % context.getTitle(),
specialise_value=portal.sale_trade_condition_module.slapos_manual_accounting_trade_condition,
)
for line in reversal_transaction.getMovementList():
line.edit(quantity=(-line.getQuantity()))
reversal_transaction.confirm(comment="Automatic because of reversal creation")
reversal_transaction.stop(comment="Automatic because of reversal creation")
return reversal_transaction
......@@ -48,65 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>""" Create a reversal transaction from current payzen transaction. """\n
from zExceptions import Unauthorized\n
if REQUEST is not None:\n
raise Unauthorized\n
\n
portal = context.getPortalObject()\n
\n
# Check that we are in state that we are waiting for user manual payment\n
assert context.getPortalType() == \'Sale Invoice Transaction\'\n
assert context.getPaymentMode() == \'payzen\'\n
assert context.getSimulationState() == \'stopped\'\n
assert context.getTotalPrice() != 0\n
assert context.getSpecialise() == "sale_trade_condition_module/slapos_aggregated_trade_condition"\n
\n
paid = True\n
for line in context.getMovementList(portal.getPortalAccountingMovementTypeList()):\n
node_value = line.getSourceValue(portal_type=\'Account\')\n
if node_value.getAccountType() == \'asset/receivable\':\n
if not line.hasGroupingReference():\n
paid = False\n
break\n
assert not paid\n
\n
payment = portal.portal_catalog.getResultValue(\n
portal_type="Payment Transaction",\n
simulation_state="started",\n
default_causality_uid=context.getUid(),\n
default_payment_mode_uid=portal.portal_categories.payment_mode.payzen.getUid(),\n
)\n
assert payment is not None\n
assert payment.getSimulationState() == \'started\'\n
assert payment.getPaymentMode() == \'payzen\'\n
assert payment.PaymentTransaction_getPayzenId()[1] is None\n
\n
# Should be safe now to fix everything\n
context.edit(payment_mode=None)\n
payment.edit(payment_mode=None)\n
reversal_transaction = context.Base_createCloneDocument(batch_mode=1)\n
payment.cancel(\n
comment="Reversal sale invoice transaction created %s" % reversal_transaction.getRelativeUrl())\n
\n
reversal_transaction.edit(\n
title="Reversal Transaction for %s" % context.getTitle(),\n
causality_value=context,\n
description="Reversal Transaction for %s" % context.getTitle(),\n
specialise_value=portal.sale_trade_condition_module.slapos_manual_accounting_trade_condition,\n
)\n
\n
for line in reversal_transaction.getMovementList():\n
line.edit(quantity=(-line.getQuantity()))\n
\n
reversal_transaction.confirm(comment="Automatic because of reversal creation")\n
reversal_transaction.stop(comment="Automatic because of reversal creation")\n
\n
return reversal_transaction\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value>
......
......@@ -2,7 +2,7 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5Form" module="Products.ERP5Form.Form"/>
<global name="ERP5 Form" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
......
......@@ -32,30 +32,6 @@
</object>
</value>
</item>
<item>
<key> <string>_text</string> </key>
<value> <unicode encoding="cdata"><![CDATA[
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n
<head>\n
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n
<meta http-equiv="Content-Script-Type" content="text/javascript" />\n
<meta http-equiv="Content-Style-Type" content="text/css" />\n
<title tal:content="here/title"></title>\n
</head>\n
<body onload="document.payment.submit();">\n
<form method="POST" tal:attributes="action here/link_url_string" id="payment" name="payment">\n
<tal:block tal:repeat="value here/field_list">\n
<input type="hidden" tal:attributes="name python: value[0]; value python: value[1]">\n
</tal:block>\n
<input type="submit" tal:attributes="value here/pay">\n
</form>\n
</body>\n
</html>
]]></unicode> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<title tal:content="here/title"></title>
</head>
<body onload="document.payment.submit();">
<form method="POST" tal:attributes="action here/link_url_string" id="payment" name="payment">
<tal:block tal:repeat="value here/field_list">
<input type="hidden" tal:attributes="name python: value[0]; value python: value[1]">
</tal:block>
<input type="submit" tal:attributes="value here/pay">
</form>
</body>
</html>
\ No newline at end of file
from DateTime import DateTime
payzen_event = state_change['object']
payment_service = payzen_event.getSourceValue(portal_type="Payzen Service")
return payment_service.navigate(
page_template='payzen_payment',
pay='Click to pay',
payzen_dict=payzen_dict,
)
......@@ -48,19 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from DateTime import DateTime\n
payzen_event = state_change[\'object\']\n
\n
payment_service = payzen_event.getSourceValue(portal_type="Payzen Service")\n
return payment_service.navigate(\n
page_template=\'payzen_payment\',\n
pay=\'Click to pay\',\n
payzen_dict=payzen_dict,\n
)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change, payzen_dict</string> </value>
......
from DateTime import DateTime
payzen_event = state_change['object']
# Get required arguments
kwargs = state_change.kwargs
# Required args
# Raise TypeError if all parameters are not provided
try:
vads_url_cancel = kwargs['vads_url_cancel']
vads_url_error = kwargs['vads_url_error']
vads_url_referral = kwargs['vads_url_referral']
vads_url_refused = kwargs['vads_url_refused']
vads_url_success = kwargs['vads_url_success']
vads_url_return = kwargs['vads_url_return']
except KeyError:
raise TypeError, "PayzenEvent_generateNavigationPage takes exactly 6 arguments"
payment_transaction = payzen_event.getDestinationValue(portal_type="Payment Transaction")
now = DateTime()
payment_transaction.AccountingTransaction_updateStartDate(now)
transaction_date, transaction_id = payment_transaction.PaymentTransaction_generatePayzenId()
if transaction_id is None:
raise ValueError, "Transaction already registered"
today = now.toZone('UTC').asdatetime().strftime('%Y%m%d')
payzen_dict = {
'vads_currency': payment_transaction.getResourceValue().Currency_getIntegrationMapping(),
'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_language': 'en',
'vads_url_cancel': vads_url_cancel,
'vads_url_error': vads_url_error,
'vads_url_referral': vads_url_referral,
'vads_url_refused': vads_url_refused,
'vads_url_success': vads_url_success,
'vads_url_return': vads_url_return,
}
html_document = context.PayzenEvent_callPayzenServiceNavigation(state_change, payzen_dict)
payzen_event.newContent(
title='Shown Page',
portal_type='Payzen Event Message',
text_content=html_document,
)
payzen_event.confirm()
payzen_event.acknowledge(comment='Automatic acknowledge as result of correct communication')
......@@ -48,60 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from DateTime import DateTime\n
payzen_event = state_change[\'object\']\n
\n
# Get required arguments\n
kwargs = state_change.kwargs\n
\n
# Required args\n
# Raise TypeError if all parameters are not provided\n
try:\n
vads_url_cancel = kwargs[\'vads_url_cancel\']\n
vads_url_error = kwargs[\'vads_url_error\']\n
vads_url_referral = kwargs[\'vads_url_referral\']\n
vads_url_refused = kwargs[\'vads_url_refused\']\n
vads_url_success = kwargs[\'vads_url_success\']\n
vads_url_return = kwargs[\'vads_url_return\']\n
except KeyError:\n
raise TypeError, "PayzenEvent_generateNavigationPage takes exactly 6 arguments"\n
\n
payment_transaction = payzen_event.getDestinationValue(portal_type="Payment Transaction")\n
now = DateTime()\n
payment_transaction.AccountingTransaction_updateStartDate(now)\n
\n
transaction_date, transaction_id = payment_transaction.PaymentTransaction_generatePayzenId()\n
if transaction_id is None:\n
raise ValueError, "Transaction already registered"\n
\n
today = now.toZone(\'UTC\').asdatetime().strftime(\'%Y%m%d\')\n
payzen_dict = {\n
\'vads_currency\': payment_transaction.getResourceValue().Currency_getIntegrationMapping(),\n
\'vads_amount\': str(int(round((payment_transaction.PaymentTransaction_getTotalPayablePrice() * -100), 0))),\n
\'vads_trans_date\': now.toZone(\'UTC\').asdatetime().strftime(\'%Y%m%d%H%M%S\'),\n
\'vads_trans_id\': transaction_id,\n
\'vads_language\': \'en\',\n
\'vads_url_cancel\': vads_url_cancel,\n
\'vads_url_error\': vads_url_error,\n
\'vads_url_referral\': vads_url_referral,\n
\'vads_url_refused\': vads_url_refused,\n
\'vads_url_success\': vads_url_success,\n
\'vads_url_return\': vads_url_return,\n
}\n
\n
html_document = context.PayzenEvent_callPayzenServiceNavigation(state_change, payzen_dict)\n
payzen_event.newContent(\n
title=\'Shown Page\',\n
portal_type=\'Payzen Event Message\',\n
text_content=html_document,\n
)\n
\n
payzen_event.confirm()\n
payzen_event.acknowledge(comment=\'Automatic acknowledge as result of correct communication\')\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change</string> </value>
......
"""Registers current transaction in payment
In order to not transmit sensitive information the registration is done by looking the newest
payzen related transaction for destination_section and doing its duplicate"""
from DateTime import DateTime
payzen_event = state_change['object']
transaction = payzen_event.getDestinationValue()
portal = transaction.getPortalObject()
payment_service = payzen_event.getSourceValue(portal_type="Payzen Service")
previous_id = transaction.PaymentTransaction_getPreviousPayzenId()
if previous_id is None:
payzen_event.confirm(comment='No previous id found')
return
transaction_date, transaction_id = transaction.PaymentTransaction_generatePayzenId()
if transaction_id is None:
raise ValueError('Transaction already mapped in integration tool.')
# do causality mapping in integration_site between transaction.getRelativeUrl and today + transaction_id
payzen_dict = {}
payzen_dict.update(
devise=transaction.getResourceValue().Currency_getIntegrationMapping(),
amount=str(int(round((transaction.PaymentTransaction_getTotalPayablePrice() * -100), 0))),
presentationDate=transaction.getStartDate().toZone('UTC').asdatetime(),
newTransactionId=transaction_id,
transmissionDate=transaction_date.asdatetime(),
transactionId=previous_id
)
data_kw, signature, sent_text, received_text = payment_service.soap_duplicate(**payzen_dict)
sent = payzen_event.newContent(title='Sent SOAP', portal_type='Payzen Event Message', text_content=sent_text)
received = payzen_event.newContent(title='Received SOAP', text_content=received_text, predecessor_value=sent, portal_type='Payzen Event Message')
context.PayzenEvent_processUpdate(state_change, data_kw, signature)
......@@ -48,46 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>"""Registers current transaction in payment\n
\n
In order to not transmit sensitive information the registration is done by looking the newest\n
payzen related transaction for destination_section and doing its duplicate"""\n
\n
from DateTime import DateTime\n
payzen_event = state_change[\'object\']\n
transaction = payzen_event.getDestinationValue()\n
portal = transaction.getPortalObject()\n
payment_service = payzen_event.getSourceValue(portal_type="Payzen Service")\n
\n
previous_id = transaction.PaymentTransaction_getPreviousPayzenId()\n
if previous_id is None:\n
payzen_event.confirm(comment=\'No previous id found\')\n
return\n
\n
transaction_date, transaction_id = transaction.PaymentTransaction_generatePayzenId()\n
if transaction_id is None:\n
raise ValueError(\'Transaction already mapped in integration tool.\')\n
\n
# do causality mapping in integration_site between transaction.getRelativeUrl and today + transaction_id\n
payzen_dict = {}\n
payzen_dict.update(\n
devise=transaction.getResourceValue().Currency_getIntegrationMapping(),\n
amount=str(int(round((transaction.PaymentTransaction_getTotalPayablePrice() * -100), 0))),\n
presentationDate=transaction.getStartDate().toZone(\'UTC\').asdatetime(),\n
newTransactionId=transaction_id,\n
transmissionDate=transaction_date.asdatetime(),\n
transactionId=previous_id\n
)\n
\n
data_kw, signature, sent_text, received_text = payment_service.soap_duplicate(**payzen_dict)\n
\n
sent = payzen_event.newContent(title=\'Sent SOAP\', portal_type=\'Payzen Event Message\', text_content=sent_text)\n
received = payzen_event.newContent(title=\'Received SOAP\', text_content=received_text, predecessor_value=sent, portal_type=\'Payzen Event Message\')\n
context.PayzenEvent_processUpdate(state_change, data_kw, signature)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change</string> </value>
......
payzen_event = state_change['object']
payment_transaction = payzen_event.getDestinationValue(portal_type="Payment Transaction")
portal = payment_transaction.getPortalObject()
transaction_date, transaction_id = payment_transaction.PaymentTransaction_getPayzenId()
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(
transaction_date.toZone('UTC').asdatetime(),
transaction_id)
sent = payzen_event.newContent(
title='Sent SOAP',
portal_type='Payzen Event Message',
text_content=sent_text)
received = payzen_event.newContent(
title='Received SOAP',
portal_type='Payzen Event Message',
text_content=received_text,
predecessor_value=sent)
payzen_event.PayzenEvent_processUpdate(data_kw, signature)
......@@ -48,33 +48,6 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>payzen_event = state_change[\'object\']\n
payment_transaction = payzen_event.getDestinationValue(portal_type="Payment Transaction")\n
portal = payment_transaction.getPortalObject()\n
\n
transaction_date, transaction_id = payment_transaction.PaymentTransaction_getPayzenId()\n
if transaction_id is None:\n
raise ValueError(\'Transaction not registered in payzen integration tool\')\n
\n
payment_service = payzen_event.getSourceValue(portal_type="Payzen Service")\n
data_kw, signature, sent_text, received_text = payment_service.soap_getInfo(\n
transaction_date.toZone(\'UTC\').asdatetime(),\n
transaction_id)\n
\n
sent = payzen_event.newContent(\n
title=\'Sent SOAP\', \n
portal_type=\'Payzen Event Message\', \n
text_content=sent_text)\n
received = payzen_event.newContent(\n
title=\'Received SOAP\', \n
portal_type=\'Payzen Event Message\', \n
text_content=received_text, \n
predecessor_value=sent)\n
payzen_event.PayzenEvent_processUpdate(data_kw, signature)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change</string> </value>
......
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