Commit ce45a47b authored by Romain Courteaud's avatar Romain Courteaud

Submit payment only if the amount is not null.

parent 0bf6ae0d
...@@ -54,7 +54,8 @@ ...@@ -54,7 +54,8 @@
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
\n \n
state = context.getSimulationState()\n state = context.getSimulationState()\n
if (state != \'confirmed\') or (context.getPaymentMode() != \'payzen\'):\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 return\n
else:\n else:\n
# Request manual payment\n # Request manual payment\n
......
...@@ -117,6 +117,34 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P ...@@ -117,6 +117,34 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P
'Visited by PaymentTransaction_startPayzenPayment', 'Visited by PaymentTransaction_startPayzenPayment',
transaction.workflow_history['edit_workflow'][-1]['comment']) transaction.workflow_history['edit_workflow'][-1]['comment'])
def _simulatePaymentTransaction_getTotalPayablePrice(self):
script_name = 'PaymentTransaction_getTotalPayablePrice'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""return 1""")
transaction.commit()
def _simulatePaymentTransaction_getZeroTotalPayablePrice(self):
script_name = 'PaymentTransaction_getTotalPayablePrice'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""return 0""")
transaction.commit()
def _dropPaymentTransaction_getTotalPayablePrice(self):
script_name = 'PaymentTransaction_getTotalPayablePrice'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_not_confirmed_payment(self): def test_not_confirmed_payment(self):
new_id = self.generateNewId() new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent( transaction = self.portal.accounting_module.newContent(
...@@ -127,7 +155,11 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P ...@@ -127,7 +155,11 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P
) )
simulation_state = transaction.getSimulationState() simulation_state = transaction.getSimulationState()
modification_date = transaction.getModificationDate() modification_date = transaction.getModificationDate()
transaction.PaymentTransaction_startPayzenPayment() self._simulatePaymentTransaction_getTotalPayablePrice()
try:
transaction.PaymentTransaction_startPayzenPayment()
finally:
self._dropPaymentTransaction_getTotalPayablePrice()
self.assertEquals(transaction.getSimulationState(), simulation_state) self.assertEquals(transaction.getSimulationState(), simulation_state)
self.assertEquals(transaction.getModificationDate(), modification_date) self.assertEquals(transaction.getModificationDate(), modification_date)
...@@ -141,7 +173,31 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P ...@@ -141,7 +173,31 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P
self.portal.portal_workflow._jumpToStateFor(transaction, 'confirmed') self.portal.portal_workflow._jumpToStateFor(transaction, 'confirmed')
simulation_state = transaction.getSimulationState() simulation_state = transaction.getSimulationState()
modification_date = transaction.getModificationDate() modification_date = transaction.getModificationDate()
transaction.PaymentTransaction_startPayzenPayment() self._simulatePaymentTransaction_getTotalPayablePrice()
try:
transaction.PaymentTransaction_startPayzenPayment()
finally:
self._dropPaymentTransaction_getTotalPayablePrice()
self.assertEquals(transaction.getSimulationState(), simulation_state)
self.assertEquals(transaction.getModificationDate(), modification_date)
def test_zero_amount_payment(self):
new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
payment_mode="payzen",
)
self.portal.portal_workflow._jumpToStateFor(transaction, 'confirmed')
simulation_state = transaction.getSimulationState()
modification_date = transaction.getModificationDate()
self._simulatePaymentTransaction_getZeroTotalPayablePrice()
try:
transaction.PaymentTransaction_startPayzenPayment()
finally:
self._dropPaymentTransaction_getTotalPayablePrice()
self.assertEquals(transaction.getSimulationState(), simulation_state) self.assertEquals(transaction.getSimulationState(), simulation_state)
self.assertEquals(transaction.getModificationDate(), modification_date) self.assertEquals(transaction.getModificationDate(), modification_date)
...@@ -174,10 +230,12 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P ...@@ -174,10 +230,12 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P
self.portal.portal_workflow._jumpToStateFor(transaction, 'confirmed') self.portal.portal_workflow._jumpToStateFor(transaction, 'confirmed')
self._simulatePaymentTransaction_sendManualPayzenPaymentUrl() self._simulatePaymentTransaction_sendManualPayzenPaymentUrl()
self._simulatePaymentTransaction_getTotalPayablePrice()
try: try:
transaction.PaymentTransaction_startPayzenPayment() transaction.PaymentTransaction_startPayzenPayment()
finally: finally:
self._dropPaymentTransaction_sendManualPayzenPaymentUrl() self._dropPaymentTransaction_sendManualPayzenPaymentUrl()
self._dropPaymentTransaction_getTotalPayablePrice()
self.assertEquals(transaction.getSimulationState(), 'started') self.assertEquals(transaction.getSimulationState(), 'started')
self.assertEqual( self.assertEqual(
'Visited by PaymentTransaction_sendManualPayzenPaymentUrl', 'Visited by PaymentTransaction_sendManualPayzenPaymentUrl',
......
100 101
\ No newline at end of file \ No newline at end of file
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