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):
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()
......
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
from DateTime import DateTime
from Products.ERP5Type.Message import translateString
......@@ -11,7 +15,6 @@ source_section = context
now = DateTime()
module = portal.portal_trash
tmp_sale_order = module.newContent(
portal_type='Sale Order',
temp_object=True,
......@@ -36,7 +39,6 @@ if (tmp_sale_order.getSourceSection(None) == tmp_sale_order.getDestinationSectio
(tmp_sale_order.getSourceSection(None) is None):
raise AssertionError('The trade condition does not generate accounting: %s' % tmp_sale_order.getSpecialise())
#######################################################
payment_transaction = portal.accounting_module.newContent(
title="reservation payment",
......@@ -53,7 +55,7 @@ payment_transaction = portal.accounting_module.newContent(
destination_section=tmp_sale_order.getDestinationSection(),
destination_decision=tmp_sale_order.getDestinationDecision(),
destination_project=tmp_sale_order.getDestinationProject(),
payment_mode=payment_mode,
ledger_value=portal.portal_categories.ledger.automated,
resource=tmp_sale_order.getPriceCurrency(),
created_by_builder=1, # XXX this prevent init script from creating lines.
......@@ -84,9 +86,6 @@ payment_transaction.newContent(
if len(payment_transaction.checkConsistency()) != 0:
raise AssertionError(payment_transaction.checkConsistency()[0])
#tag = '%s_update' % context.getDestinationReference()
comment = translateString("Deposit payment.")
payment_transaction.start(comment=comment)
payment_transaction.start(comment=translateString("Deposit payment."))
return payment_transaction
......@@ -50,7 +50,7 @@
</item>
<item>
<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>
<key> <string>id</string> </key>
......
......@@ -34,7 +34,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
self.assertEqual(subscription_request.getSimulationState(), "submitted")
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
payment_transaction.stop()
self.tic()
......@@ -209,7 +209,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
# Add deposit
with PinnedDateTime(self, creation_date + 2):
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
payment_transaction.stop()
......@@ -311,7 +311,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
##################################################
# Add deposit (0.1 to prevent discount generation)
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
payment_transaction.stop()
......
......@@ -682,7 +682,7 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
payment_transaction = person.Person_restrictMethodAsShadowUser(
shadow_document=person,
callable_object=wrapWithShadow,
argument_list=[person, deposit_amount, currency.getRelativeUrl(), 1])
argument_list=[person, deposit_amount, currency.getRelativeUrl()])
self.tic()
self.logout()
self.login()
......
......@@ -56,7 +56,7 @@ class TestSlapOSCRMScenario(TestSlapOSVirtualMasterScenarioMixin):
##################################################
# Add deposit
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
payment_transaction.stop()
......
......@@ -485,7 +485,7 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
payment_transaction = owner_person.Person_restrictMethodAsShadowUser(
shadow_document=owner_person,
callable_object=wrapWithShadow,
argument_list=[owner_person, total_price, currency.getRelativeUrl(), 1])
argument_list=[owner_person, total_price, currency.getRelativeUrl()])
self.tic()
self.logout()
self.login()
......@@ -561,7 +561,7 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
self.login()
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
payment_transaction.stop()
self.tic()
......@@ -869,7 +869,7 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
payment_transaction = project_owner_person.Person_restrictMethodAsShadowUser(
shadow_document=project_owner_person,
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.logout()
self.login()
......
......@@ -20,7 +20,7 @@ for currency_value, secure_service_relative_url in [
(portal.currency_module.EUR, portal.Base_getPayzenServiceRelativeUrl()),
# (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:
# Existing invoices
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()
web_site = context.getWebSiteValue()
if currency_reference is not None:
currency_value = None
if currency_reference:
currency_value = portal.portal_catalog.getResultValue(
portal_type="Currency",
reference=currency_reference,
......@@ -11,41 +10,25 @@ if currency_reference is not None:
if currency_value is None:
raise ValueError("Unknown Currency: %s" % currency_reference)
currency_uid = currency_value.getUid()
assert web_site is not None
payment_mode = context.Base_getPaymentModeForCurrency(currency_value.getUid())
assert payment_mode is not None
deposit_price = context.Entity_getOutstandingDepositAmount(currency_uid)
deposit_price = context.Entity_getOutstandingDepositAmount(currency_value.getUid())
if 0 >= deposit_price:
raise ValueError("Nothing to pay")
payment_mode = None
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):
def wrapWithShadow(entity, total_amount, currency_value, payment_mode):
return entity.Person_addDepositPayment(
total_amount,
currency_value.getRelativeUrl(),
batch=1
payment_mode=payment_mode
)
payment_transaction = context.Person_restrictMethodAsShadowUser(
shadow_document=context,
callable_object=wrapWithShadow,
argument_list=[context, deposit_price, currency_value])
argument_list=[context, deposit_price, currency_value, payment_mode])
if (payment_mode == "wechat"):
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')
web_site = context.getWebSiteValue()
assert web_site is not None
return payment_transaction.PaymentTransaction_redirectToManualPayment(web_site=web_site)
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>currency_reference=None</string> </value>
<value> <string>currency_reference</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
""" 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"
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>web_site</string> </value>
<value> <string></string> </value>
</item>
<item>
<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()
from DateTime import DateTime
date = DateTime()
entity = portal.portal_membership.getAuthenticatedMember().getUserValue()
outstanding_amount = context
......@@ -11,17 +9,10 @@ assert web_site is not None
assert outstanding_amount.getLedgerUid() == portal.portal_categories.ledger.automated.getUid()
assert outstanding_amount.getDestinationSectionUid() == entity.getUid()
payment_mode = None
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
payment_mode = outstanding_amount.Base_getPaymentModeForCurrency(outstanding_amount.getPriceCurrencyUid())
assert payment_mode is not None
def wrapWithShadow(entity, outstanding_amount):
def wrapWithShadow(entity, outstanding_amount, payment_mode):
return entity.Entity_createPaymentTransaction(
entity.Entity_getOutstandingAmountList(
section_uid=outstanding_amount.getSourceSectionUid(),
......@@ -29,22 +20,12 @@ def wrapWithShadow(entity, outstanding_amount):
ledger_uid=outstanding_amount.getLedgerUid(),
group_by_node=False
),
start_date=date,
payment_mode=payment_mode
)
entity = outstanding_amount.getDestinationSectionValue(portal_type="Person")
payment_transaction = entity.Person_restrictMethodAsShadowUser(
shadow_document=entity,
callable_object=wrapWithShadow,
argument_list=[entity, outstanding_amount])
web_site = context.getWebSiteValue()
argument_list=[entity, outstanding_amount, payment_mode])
if (payment_mode == "wechat"):
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')
return payment_transaction.PaymentTransaction_redirectToManualPayment(web_site=web_site)
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