Commit f512ad84 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_payzen; Scripts moved to slapos_account in order to make it compatible...

slapos_payzen; Scripts moved to slapos_account in order to make it compatible with multiple payment types
parent 4a02fcbc
simulation_state = context.getSimulationState()
if simulation_state in ("cancelled", "deleted", "draft"):
result = "Cancelled"
elif simulation_state in ("planned", "confirmed", "ordered", "started"):
result = "Ongoing"
else:
portal = context.getPortalObject()
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
reversal = portal.portal_catalog.getResultValue(
portal_type="Sale Invoice Transaction",
simulation_state="stopped",
default_causality_uid=context.getUid()
)
if reversal is not None and (context.getTotalPrice() + reversal.getTotalPrice()) == 0:
result = "Cancelled"
elif paid:
result = "Paid"
elif context.getTotalPrice() == 0:
result = "Free!"
else:
# Check if there is an ongoing payzen payment
payment = context.SaleInvoiceTransaction_getPayzenPaymentRelatedValue()
if payment is None:
result = "Unpaid"
else:
# Check if mapping exists
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
payzen_id = person.Person_restrictMethodAsShadowUser(
shadow_document=person,
callable_object=payment.PaymentTransaction_getPayzenId,
argument_list=[])[0]
if payzen_id is None:
result = "Pay now"
else:
result = "Waiting for payment confirmation"
return result
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>AccountingTransaction_getPaymentState</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
return 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(),
)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SaleInvoiceTransaction_getPayzenPaymentRelatedValue</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -605,7 +605,7 @@ class TestSlapOSPayzenAccountingTransaction_getPaymentState(
invoice = self.createPayzenSaleInvoiceTransaction(
destination_section=person.getRelativeUrl())
self.tic()
payment = invoice.SaleInvoiceTransaction_getPayzenPaymentRelatedValue()
payment = invoice.SaleInvoiceTransaction_getSlapOSPaymentRelatedValue()
payment.PaymentTransaction_generatePayzenId()
self.login(person.getUserId())
self.assertEqual("Waiting for payment confirmation",
......@@ -667,7 +667,7 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans
invoice = self.createPayzenSaleInvoiceTransaction(
destination_section=person.getRelativeUrl())
self.tic()
payment = invoice.SaleInvoiceTransaction_getPayzenPaymentRelatedValue()
payment = invoice.SaleInvoiceTransaction_getSlapOSPaymentRelatedValue()
payment.setResourceValue(self.portal.currency_module.EUR)
self.tic()
self.login(person.getUserId())
......@@ -701,7 +701,7 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans
invoice = self.createPayzenSaleInvoiceTransaction(
destination_section=person.getRelativeUrl())
self.tic()
payment = invoice.SaleInvoiceTransaction_getPayzenPaymentRelatedValue()
payment = invoice.SaleInvoiceTransaction_getSlapOSPaymentRelatedValue()
payment.setResourceValue(self.portal.currency_module.EUR)
payment.PaymentTransaction_generatePayzenId()
self.tic()
......@@ -715,13 +715,13 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans
self.assertEqual("%s/already_registered" % payment.getRelativeUrl(),
redirect)
class TestSlapOSPayzenSaleInvoiceTransaction_getPayzenPaymentRelatedValue(
class TestSlapOSPayzenSaleInvoiceTransaction_getSlapOSPaymentRelatedValue(
SlapOSTestCaseMixinWithAbort):
def test_SaleInvoiceTransaction_getPayzenPaymentRelatedValue(self):
def test_SaleInvoiceTransaction_getSlapOSPaymentRelatedValue(self):
invoice = self.createPayzenSaleInvoiceTransaction()
self.tic()
payment = invoice.SaleInvoiceTransaction_getPayzenPaymentRelatedValue()
payment = invoice.SaleInvoiceTransaction_getSlapOSPaymentRelatedValue()
self.assertNotEqual(None, payment)
self.assertEqual(payment.getSimulationState(), "started")
self.assertEqual(payment.getCausalityValue(), invoice)
......@@ -731,7 +731,7 @@ class TestSlapOSPayzenSaleInvoiceTransaction_getPayzenPaymentRelatedValue(
payment.setStartDate(DateTime())
payment.stop()
payment.immediateReindexObject()
payment = invoice.SaleInvoiceTransaction_getPayzenPaymentRelatedValue()
payment = invoice.SaleInvoiceTransaction_getSlapOSPaymentRelatedValue()
self.assertEqual(None, payment)
class TestSlapOSPayzenSaleInvoiceTransaction_createReversalPayzenTransaction(
......
......@@ -117,6 +117,7 @@
</item>
</dictionary>
</list>
<none/>
</tuple>
</pickle>
</record>
......
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