Commit 295aff9b authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_panel: Factorize and deduplicate the code for payment mode selection

  Remove non required code around the topic.
parent 4794734d
...@@ -90,7 +90,8 @@ for index, line in enumerate(invoice_list): ...@@ -90,7 +90,8 @@ for index, line in enumerate(invoice_list):
activate_kw=activate_kw, activate_kw=activate_kw,
) )
assert len(payment_transaction.checkConsistency()) == 0 if len(payment_transaction.checkConsistency()) != 0:
raise AssertionError(payment_transaction.checkConsistency()[0])
payment_transaction.start() payment_transaction.start()
......
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
from DateTime import DateTime from DateTime import DateTime
from Products.ERP5Type.Message import translateString from Products.ERP5Type.Message import translateString
...@@ -11,7 +15,6 @@ source_section = context ...@@ -11,7 +15,6 @@ source_section = context
now = DateTime() now = DateTime()
module = portal.portal_trash module = portal.portal_trash
tmp_sale_order = module.newContent( tmp_sale_order = module.newContent(
portal_type='Sale Order', portal_type='Sale Order',
temp_object=True, temp_object=True,
...@@ -36,7 +39,6 @@ if (tmp_sale_order.getSourceSection(None) == tmp_sale_order.getDestinationSectio ...@@ -36,7 +39,6 @@ if (tmp_sale_order.getSourceSection(None) == tmp_sale_order.getDestinationSectio
(tmp_sale_order.getSourceSection(None) is None): (tmp_sale_order.getSourceSection(None) is None):
raise AssertionError('The trade condition does not generate accounting: %s' % tmp_sale_order.getSpecialise()) raise AssertionError('The trade condition does not generate accounting: %s' % tmp_sale_order.getSpecialise())
####################################################### #######################################################
payment_transaction = portal.accounting_module.newContent( payment_transaction = portal.accounting_module.newContent(
title="reservation payment", title="reservation payment",
...@@ -53,7 +55,7 @@ payment_transaction = portal.accounting_module.newContent( ...@@ -53,7 +55,7 @@ payment_transaction = portal.accounting_module.newContent(
destination_section=tmp_sale_order.getDestinationSection(), destination_section=tmp_sale_order.getDestinationSection(),
destination_decision=tmp_sale_order.getDestinationDecision(), destination_decision=tmp_sale_order.getDestinationDecision(),
destination_project=tmp_sale_order.getDestinationProject(), destination_project=tmp_sale_order.getDestinationProject(),
payment_mode=payment_mode,
ledger_value=portal.portal_categories.ledger.automated, ledger_value=portal.portal_categories.ledger.automated,
resource=tmp_sale_order.getPriceCurrency(), resource=tmp_sale_order.getPriceCurrency(),
created_by_builder=1, # XXX this prevent init script from creating lines. created_by_builder=1, # XXX this prevent init script from creating lines.
...@@ -84,9 +86,6 @@ payment_transaction.newContent( ...@@ -84,9 +86,6 @@ payment_transaction.newContent(
if len(payment_transaction.checkConsistency()) != 0: if len(payment_transaction.checkConsistency()) != 0:
raise AssertionError(payment_transaction.checkConsistency()[0]) raise AssertionError(payment_transaction.checkConsistency()[0])
#tag = '%s_update' % context.getDestinationReference() payment_transaction.start(comment=translateString("Deposit payment."))
comment = translateString("Deposit payment.")
payment_transaction.start(comment=comment)
return payment_transaction return payment_transaction
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>price, currency_relative_url, batch=0</string> </value> <value> <string>price, currency_relative_url, payment_mode=None, REQUEST=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -34,7 +34,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -34,7 +34,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
self.assertEqual(subscription_request.getSimulationState(), "submitted") self.assertEqual(subscription_request.getSimulationState(), "submitted")
with PinnedDateTime(self, DateTime('2021/04/04')): with PinnedDateTime(self, DateTime('2021/04/04')):
payment_transaction = owner_person.Person_addDepositPayment(99*10, currency.getRelativeUrl(), 1) payment_transaction = owner_person.Person_addDepositPayment(99*10, currency.getRelativeUrl())
# payzen interface will only stop the payment # payzen interface will only stop the payment
payment_transaction.stop() payment_transaction.stop()
self.tic() self.tic()
...@@ -209,7 +209,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -209,7 +209,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
# Add deposit # Add deposit
with PinnedDateTime(self, creation_date + 2): with PinnedDateTime(self, creation_date + 2):
for person in person_list: for person in person_list:
payment_transaction = person.Person_addDepositPayment(99*100, currency.getRelativeUrl(), 1) payment_transaction = person.Person_addDepositPayment(99*100, currency.getRelativeUrl())
# payzen interface will only stop the payment # payzen interface will only stop the payment
payment_transaction.stop() payment_transaction.stop()
...@@ -311,7 +311,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -311,7 +311,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
################################################## ##################################################
# Add deposit (0.1 to prevent discount generation) # Add deposit (0.1 to prevent discount generation)
with PinnedDateTime(self, creation_date + 0.1): with PinnedDateTime(self, creation_date + 0.1):
payment_transaction = owner_person.Person_addDepositPayment(99*100, currency.getRelativeUrl(), 1) payment_transaction = owner_person.Person_addDepositPayment(99*100, currency.getRelativeUrl())
# payzen interface will only stop the payment # payzen interface will only stop the payment
payment_transaction.stop() payment_transaction.stop()
......
...@@ -682,7 +682,7 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin): ...@@ -682,7 +682,7 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
payment_transaction = person.Person_restrictMethodAsShadowUser( payment_transaction = person.Person_restrictMethodAsShadowUser(
shadow_document=person, shadow_document=person,
callable_object=wrapWithShadow, callable_object=wrapWithShadow,
argument_list=[person, deposit_amount, currency.getRelativeUrl(), 1]) argument_list=[person, deposit_amount, currency.getRelativeUrl()])
self.tic() self.tic()
self.logout() self.logout()
self.login() self.login()
......
...@@ -56,7 +56,7 @@ class TestSlapOSCRMScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -56,7 +56,7 @@ class TestSlapOSCRMScenario(TestSlapOSVirtualMasterScenarioMixin):
################################################## ##################################################
# Add deposit # Add deposit
with PinnedDateTime(self, creation_date): with PinnedDateTime(self, creation_date):
payment_transaction = owner_person.Person_addDepositPayment(99*100, currency.getRelativeUrl(), 1) payment_transaction = owner_person.Person_addDepositPayment(99*100, currency.getRelativeUrl())
# payzen interface will only stop the payment # payzen interface will only stop the payment
payment_transaction.stop() payment_transaction.stop()
...@@ -176,4 +176,4 @@ class TestSlapOSCRMScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -176,4 +176,4 @@ class TestSlapOSCRMScenario(TestSlapOSVirtualMasterScenarioMixin):
with PinnedDateTime(self, creation_date + 5): with PinnedDateTime(self, creation_date + 5):
self.checkERP5StateBeforeExit() self.checkERP5StateBeforeExit()
\ No newline at end of file
...@@ -485,7 +485,7 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -485,7 +485,7 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
payment_transaction = owner_person.Person_restrictMethodAsShadowUser( payment_transaction = owner_person.Person_restrictMethodAsShadowUser(
shadow_document=owner_person, shadow_document=owner_person,
callable_object=wrapWithShadow, callable_object=wrapWithShadow,
argument_list=[owner_person, total_price, currency.getRelativeUrl(), 1]) argument_list=[owner_person, total_price, currency.getRelativeUrl()])
self.tic() self.tic()
self.logout() self.logout()
self.login() self.login()
...@@ -561,7 +561,7 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -561,7 +561,7 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
self.login() self.login()
project = self.portal.restrictedTraverse(project_relative_url) project = self.portal.restrictedTraverse(project_relative_url)
payment_transaction = customer_section_organisation.Person_addDepositPayment(99*10, currency.getRelativeUrl(), 1) payment_transaction = customer_section_organisation.Person_addDepositPayment(99*10, currency.getRelativeUrl())
# payzen interface will only stop the payment # payzen interface will only stop the payment
payment_transaction.stop() payment_transaction.stop()
self.tic() self.tic()
...@@ -869,7 +869,7 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -869,7 +869,7 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
payment_transaction = project_owner_person.Person_restrictMethodAsShadowUser( payment_transaction = project_owner_person.Person_restrictMethodAsShadowUser(
shadow_document=project_owner_person, shadow_document=project_owner_person,
callable_object=wrapWithShadow, callable_object=wrapWithShadow,
argument_list=[project_owner_person, deposit_amount, currency.getRelativeUrl(), 1]) argument_list=[project_owner_person, deposit_amount, currency.getRelativeUrl()])
self.tic() self.tic()
self.logout() self.logout()
self.login() self.login()
......
...@@ -20,7 +20,7 @@ for currency_value, secure_service_relative_url in [ ...@@ -20,7 +20,7 @@ for currency_value, secure_service_relative_url in [
(portal.currency_module.EUR, portal.Base_getPayzenServiceRelativeUrl()), (portal.currency_module.EUR, portal.Base_getPayzenServiceRelativeUrl()),
# (portal.currency_module.CNY, portal.Base_getWechatServiceRelativeUrl()) # (portal.currency_module.CNY, portal.Base_getWechatServiceRelativeUrl())
]: ]:
currency_uid = currency_value.getCurrencyUid() currency_uid = currency_value.getUid()
if secure_service_relative_url is not None: if secure_service_relative_url is not None:
# Existing invoices # Existing invoices
outstanding_amount_list = entity.Entity_getOutstandingAmountList( outstanding_amount_list = entity.Entity_getOutstandingAmountList(
......
""" XXX This script expects some re-implementation to
rely on panel configuration for handle payment.
"""
portal = context.getPortalObject()
payment_mode = None
for accepted_currency_uid, accepted_payment_mode, is_activated in [
(portal.currency_module.EUR.getUid(), 'payzen', portal.Base_getPayzenServiceRelativeUrl()),
# (portal.currency_module.CNY, 'wechat', portal.Base_getWechatServiceRelativeUrl())
]:
if is_activated and (currency_uid == accepted_currency_uid):
payment_mode = accepted_payment_mode
return payment_mode
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>currency_uid</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getPaymentModeForCurrency</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject() portal = context.getPortalObject()
web_site = context.getWebSiteValue() currency_value = None
if currency_reference:
if currency_reference is not None:
currency_value = portal.portal_catalog.getResultValue( currency_value = portal.portal_catalog.getResultValue(
portal_type="Currency", portal_type="Currency",
reference=currency_reference, reference=currency_reference,
validation_state="validated") validation_state="validated")
if currency_value is None: if currency_value is None:
raise ValueError("Unknown Currency: %s" % currency_reference) raise ValueError("Unknown Currency: %s" % currency_reference)
currency_uid = currency_value.getUid() payment_mode = context.Base_getPaymentModeForCurrency(currency_value.getUid())
assert payment_mode is not None
assert web_site is not None
deposit_price = context.Entity_getOutstandingDepositAmount(currency_uid) deposit_price = context.Entity_getOutstandingDepositAmount(currency_value.getUid())
if 0 >= deposit_price: if 0 >= deposit_price:
raise ValueError("Nothing to pay") raise ValueError("Nothing to pay")
payment_mode = None def wrapWithShadow(entity, total_amount, currency_value, payment_mode):
resource_uid = currency_uid
for accepted_resource_uid, accepted_payment_mode, is_activated in [
(portal.currency_module.EUR.getUid(), 'payzen', portal.Base_getPayzenServiceRelativeUrl()),
# (portal.currency_module.CNY, 'wechat', portal.Base_getWechatServiceRelativeUrl())
]:
if is_activated and (resource_uid == accepted_resource_uid):
payment_mode = accepted_payment_mode
assert payment_mode is not None
def wrapWithShadow(entity, total_amount, currency_value):
return entity.Person_addDepositPayment( return entity.Person_addDepositPayment(
total_amount, total_amount,
currency_value.getRelativeUrl(), currency_value.getRelativeUrl(),
batch=1 payment_mode=payment_mode
) )
payment_transaction = context.Person_restrictMethodAsShadowUser( payment_transaction = context.Person_restrictMethodAsShadowUser(
shadow_document=context, shadow_document=context,
callable_object=wrapWithShadow, callable_object=wrapWithShadow,
argument_list=[context, deposit_price, currency_value]) argument_list=[context, deposit_price, currency_value, payment_mode])
if (payment_mode == "wechat"): web_site = context.getWebSiteValue()
return payment_transaction.PaymentTransaction_redirectToManualWechatPayment(web_site=web_site) assert web_site is not None
elif (payment_mode == "payzen"): return payment_transaction.PaymentTransaction_redirectToManualPayment(web_site=web_site)
return payment_transaction.PaymentTransaction_redirectToManualPayzenPayment(web_site=web_site)
else:
raise NotImplementedError('not implemented')
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>currency_reference=None</string> </value> <value> <string>currency_reference</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
""" Return a dict with vads_urls required for payzen.""" """ Return a dict with vads_urls required for payzen."""
if web_site is None:
web_site = context.getWebSiteValue()
if web_site is None:
raise ValueError("This script must be called from a web site")
base = "%(payment_transaction_url)s/PaymentTransaction_triggerPaymentCheckAlarmAndRedirectToPanel?result=%(result)s" base = "%(payment_transaction_url)s/PaymentTransaction_triggerPaymentCheckAlarmAndRedirectToPanel?result=%(result)s"
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>web_site</string> </value> <value> <string></string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
if (context.getPaymentMode() == "wechat"):
return context.PaymentTransaction_redirectToManualWechatPayment(web_site=web_site)
elif (context.getPaymentMode() == "payzen"):
return context.PaymentTransaction_redirectToManualPayzenPayment()
else:
raise NotImplementedError('not implemented')
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>web_site=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>PaymentTransaction_redirectToManualPayment</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject() portal = context.getPortalObject()
from DateTime import DateTime
date = DateTime()
entity = portal.portal_membership.getAuthenticatedMember().getUserValue() entity = portal.portal_membership.getAuthenticatedMember().getUserValue()
outstanding_amount = context outstanding_amount = context
...@@ -11,17 +9,10 @@ assert web_site is not None ...@@ -11,17 +9,10 @@ assert web_site is not None
assert outstanding_amount.getLedgerUid() == portal.portal_categories.ledger.automated.getUid() assert outstanding_amount.getLedgerUid() == portal.portal_categories.ledger.automated.getUid()
assert outstanding_amount.getDestinationSectionUid() == entity.getUid() assert outstanding_amount.getDestinationSectionUid() == entity.getUid()
payment_mode = None payment_mode = outstanding_amount.Base_getPaymentModeForCurrency(outstanding_amount.getPriceCurrencyUid())
resource_uid = outstanding_amount.getPriceCurrencyUid()
for accepted_resource_uid, accepted_payment_mode, is_activated in [
(portal.currency_module.EUR.getUid(), 'payzen', portal.Base_getPayzenServiceRelativeUrl()),
]:
if is_activated and (resource_uid == accepted_resource_uid):
payment_mode = accepted_payment_mode
assert payment_mode is not None assert payment_mode is not None
def wrapWithShadow(entity, outstanding_amount): def wrapWithShadow(entity, outstanding_amount, payment_mode):
return entity.Entity_createPaymentTransaction( return entity.Entity_createPaymentTransaction(
entity.Entity_getOutstandingAmountList( entity.Entity_getOutstandingAmountList(
section_uid=outstanding_amount.getSourceSectionUid(), section_uid=outstanding_amount.getSourceSectionUid(),
...@@ -29,22 +20,12 @@ def wrapWithShadow(entity, outstanding_amount): ...@@ -29,22 +20,12 @@ def wrapWithShadow(entity, outstanding_amount):
ledger_uid=outstanding_amount.getLedgerUid(), ledger_uid=outstanding_amount.getLedgerUid(),
group_by_node=False group_by_node=False
), ),
start_date=date,
payment_mode=payment_mode payment_mode=payment_mode
) )
entity = outstanding_amount.getDestinationSectionValue(portal_type="Person")
payment_transaction = entity.Person_restrictMethodAsShadowUser( payment_transaction = entity.Person_restrictMethodAsShadowUser(
shadow_document=entity, shadow_document=entity,
callable_object=wrapWithShadow, callable_object=wrapWithShadow,
argument_list=[entity, outstanding_amount]) argument_list=[entity, outstanding_amount, payment_mode])
web_site = context.getWebSiteValue()
if (payment_mode == "wechat"): return payment_transaction.PaymentTransaction_redirectToManualPayment(web_site=web_site)
return payment_transaction.PaymentTransaction_redirectToManualWechatPayment(web_site=web_site)
elif (payment_mode == "payzen"):
return payment_transaction.PaymentTransaction_redirectToManualPayzenPayment(web_site=web_site)
else:
raise NotImplementedError('not implemented')
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