Commit 3ba8a47f authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_accounting&sub_request: Redirect to "Contact us to pay" if secure payment isnt configured

   This allow the sites to work w/o payzen or wechat preconfigured.
parent 3f523e98
""" Return a dict with vads_urls required for payzen."""
if web_site is None:
web_site = context.getWebSiteValue()
if context.PaymentTransaction_getTotalPayablePrice() == 0:
# This script cannot be used if Payment has a value to pay
raise ValueError("Payment Transaction has a non zero total")
base_url = web_site.absolute_url()
payment_transaction_url = context.getRelativeUrl()
base = web_site.getLayoutProperty("configuration_payment_url_template",
"%(url)s/#/%(payment_transaction_url)s?page=slap_payment_result&result=%(result)s")
base_substitution_dict = {
"url" : base_url,
"payment_transaction_url": payment_transaction_url,
"result": "contact_us"
}
redirect_url = base % base_substitution_dict
return context.REQUEST.RESPONSE.redirect(redirect_url)
<?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>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>PaymentTransaction_redirectToManualContactUsPayment</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -13,9 +13,19 @@ payment = entity.Person_restrictMethodAsShadowUser( ...@@ -13,9 +13,19 @@ payment = entity.Person_restrictMethodAsShadowUser(
if web_site is None: if web_site is None:
web_site = context.getWebSiteValue() web_site = context.getWebSiteValue()
total_price = entity.Person_restrictMethodAsShadowUser(
shadow_document=entity,
callable_object=payment.PaymentTransaction_getTotalPayablePrice,
argument_list=[])
if total_price >= 0:
return payment.PaymentTransaction_redirectToManualFreePayment(web_site=web_site)
if payment_mode == "wechat": if payment_mode == "wechat":
return payment.PaymentTransaction_redirectToManualWechatPayment(web_site=web_site) if payment.Base_getWechatServiceRelativeUrl():
return payment.PaymentTransaction_redirectToManualWechatPayment(web_site=web_site)
elif payment_mode == "payzen": elif payment_mode == "payzen":
return payment.PaymentTransaction_redirectToManualPayzenPayment(web_site=web_site) if payment.Base_getPayzenServiceRelativeUrl():
return payment.PaymentTransaction_redirectToManualPayzenPayment(web_site=web_site)
raise ValueError("%s isn't an acceptable payment mode" % payment_mode) return payment.PaymentTransaction_redirectToManualContactUsPayment(web_site=web_site)
...@@ -167,6 +167,8 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template): ...@@ -167,6 +167,8 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template):
'slapos_accounting/SaleInvoiceTransaction_isTotalPriceEqualAccounting', 'slapos_accounting/SaleInvoiceTransaction_isTotalPriceEqualAccounting',
'slapos_accounting/SaleInvoiceTransaction_isTotalPriceMatchingSalePackingList', 'slapos_accounting/SaleInvoiceTransaction_isTotalPriceMatchingSalePackingList',
'slapos_accounting/SaleInvoiceTransaction_isTradeModelCorrect', 'slapos_accounting/SaleInvoiceTransaction_isTradeModelCorrect',
'slapos_accounting/PaymentTransaction_redirectToManualFreePayment',
'slapos_accounting/PaymentTransaction_redirectToManualContactUsPayment',
'slapos_accounting/SalePackingList_jumpToRelatedAggregatedSalePackingList', 'slapos_accounting/SalePackingList_jumpToRelatedAggregatedSalePackingList',
'slapos_accounting/SalePackingList_jumpToRelatedGroupedSalePackingList', 'slapos_accounting/SalePackingList_jumpToRelatedGroupedSalePackingList',
'slapos_accounting/SalePackingList_postSlapOSAggregatedDeliveryBuilder', 'slapos_accounting/SalePackingList_postSlapOSAggregatedDeliveryBuilder',
...@@ -232,7 +234,6 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template): ...@@ -232,7 +234,6 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template):
'slapos_hal_json_style/Organisation_getAssociatedPersonList', 'slapos_hal_json_style/Organisation_getAssociatedPersonList',
'slapos_hal_json_style/Organisation_hasItem', 'slapos_hal_json_style/Organisation_hasItem',
'slapos_hal_json_style/PasswordTool_changeUserPassword', 'slapos_hal_json_style/PasswordTool_changeUserPassword',
'slapos_hal_json_style/PaymentTransaction_redirectToManualFreePayment',
'slapos_hal_json_style/Person_getAssignmentDestinationList', 'slapos_hal_json_style/Person_getAssignmentDestinationList',
'slapos_hal_json_style/Person_getCloudContractRelated', 'slapos_hal_json_style/Person_getCloudContractRelated',
'slapos_hal_json_style/Person_requestComputeNode', 'slapos_hal_json_style/Person_requestComputeNode',
......
...@@ -20,8 +20,6 @@ if email in ["", None]: ...@@ -20,8 +20,6 @@ if email in ["", None]:
) )
return context.REQUEST.RESPONSE.redirect(redirect_url) return context.REQUEST.RESPONSE.redirect(redirect_url)
if token: if token:
error = "" error = ""
try: try:
...@@ -105,14 +103,18 @@ if target_language == "zh": # Wechat payment ...@@ -105,14 +103,18 @@ if target_language == "zh": # Wechat payment
def wrapRedirectWithShadow(payment_transaction, web_site): def wrapRedirectWithShadow(payment_transaction, web_site):
# getTotalPayble returns a negative value # getTotalPayble returns a negative value
if payment_transaction.PaymentTransaction_getTotalPayablePrice() < 0: if payment_transaction.PaymentTransaction_getTotalPayablePrice() < 0:
return payment_transaction.PaymentTransaction_redirectToManualWechatPayment(web_site) if payment_transaction.Base_getWechatServiceRelativeUrl():
return payment_transaction.PaymentTransaction_redirectToManualWechatPayment(web_site)
return payment_transaction.PaymentTransaction_redirectToManualContactUsPayment(web_site)
return payment_transaction.PaymentTransaction_redirectToManualFreePayment(web_site) return payment_transaction.PaymentTransaction_redirectToManualFreePayment(web_site)
else: # Payzen payment else: # Payzen payment
def wrapRedirectWithShadow(payment_transaction, web_site): def wrapRedirectWithShadow(payment_transaction, web_site):
# getTotalPayble returns a negative value # getTotalPayble returns a negative value
if payment_transaction.PaymentTransaction_getTotalPayablePrice() < 0: if payment_transaction.PaymentTransaction_getTotalPayablePrice() < 0:
return payment_transaction.PaymentTransaction_redirectToManualPayzenPayment(web_site) if payment_transaction.Base_getPayzenServiceRelativeUrl():
return payment_transaction.PaymentTransaction_redirectToManualPayzenPayment(web_site)
return payment_transaction.PaymentTransaction_redirectToManualContactUsPayment(web_site)
return payment_transaction.PaymentTransaction_redirectToManualFreePayment(web_site) return payment_transaction.PaymentTransaction_redirectToManualFreePayment(web_site)
return person.Person_restrictMethodAsShadowUser( return person.Person_restrictMethodAsShadowUser(
......
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