Commit 03c81da1 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_subscription_request: Implement request susbscription with token

parent 1e0bf417
<?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>invitation_token=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Person_applyContractInvitation</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -47,8 +47,9 @@ if confirmation_required and not person_is_new: ...@@ -47,8 +47,9 @@ if confirmation_required and not person_is_new:
if target_language is None: if target_language is None:
target_language = portal.Localizer.get_selected_language() target_language = portal.Localizer.get_selected_language()
contract = None
if token: if token:
person.Person_applyContractInvitation(invitation_token) contract = person.Person_applyContractInvitation(invitation_token)
subscription_request = context.subscription_request_module.newContent( subscription_request = context.subscription_request_module.newContent(
portal_type="Subscription Request", portal_type="Subscription Request",
...@@ -59,30 +60,40 @@ subscription_request = context.subscription_request_module.newContent( ...@@ -59,30 +60,40 @@ subscription_request = context.subscription_request_module.newContent(
subscription_request.setDefaultEmailText(email) subscription_request.setDefaultEmailText(email)
def wrapWithShadow(subscription_request, amount, subscription_reference, subscription_request_id): def wrapWithShadow(subscription_request, amount, subscription_reference,
subscription_request_id, contract=contract):
subscription_request.activate(tag="subscription_condition_%s" % subscription_request_id subscription_request.activate(tag="subscription_condition_%s" % subscription_request_id
).SubscriptionRequest_applyCondition(subscription_reference, target_language) ).SubscriptionRequest_applyCondition(subscription_reference, target_language)
return subscription_request.SubscriptionRequest_requestPaymentTransaction( return subscription_request.SubscriptionRequest_requestPaymentTransaction(
amount=amount, amount=amount,
tag="subscription_%s" % subscription_request_id, tag="subscription_%s" % subscription_request_id,
target_language=target_language target_language=target_language,
contract=contract
) )
payment = person.Person_restrictMethodAsShadowUser( payment = person.Person_restrictMethodAsShadowUser(
shadow_document=person, shadow_document=person,
callable_object=wrapWithShadow, callable_object=wrapWithShadow,
argument_list=[subscription_request, user_input_dict["amount"], subscription_reference, subscription_request.getId()]) argument_list=[subscription_request, user_input_dict["amount"],
subscription_reference, subscription_request.getId(),
contract])
if batch_mode: if batch_mode:
return {'subscription' : subscription_request.getRelativeUrl(), 'payment': payment.getRelativeUrl() } return {'subscription' : subscription_request.getRelativeUrl(),
'payment': payment.getRelativeUrl() }
if target_language == "zh": # Wechat payment if target_language == "zh": # Wechat payment
def wrapRedirectWithShadow(payment_transaction, web_site): def wrapRedirectWithShadow(payment_transaction, web_site):
return payment_transaction.PaymentTransaction_redirectToManualWechatPayment(web_site) if payment_transaction.PaymentTransaction_getTotalPayablePrice() > 0:
return payment_transaction.PaymentTransaction_redirectToManualWechatPayment(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):
return payment_transaction.PaymentTransaction_redirectToManualPayzenPayment(web_site) if payment_transaction.PaymentTransaction_getTotalPayablePrice() > 0:
return payment_transaction.PaymentTransaction_redirectToManualPayzenPayment(web_site)
return payment_transaction.PaymentTransaction_redirectToManualFreePayment(web_site)
return person.Person_restrictMethodAsShadowUser( return person.Person_restrictMethodAsShadowUser(
shadow_document=person, shadow_document=person,
callable_object=wrapRedirectWithShadow, callable_object=wrapRedirectWithShadow,
......
...@@ -23,6 +23,8 @@ if current_invoice is None: ...@@ -23,6 +23,8 @@ if current_invoice is None:
stop_date=DateTime() stop_date=DateTime()
) )
if context.SubscriptionRequest_testSkippedReservationFree(contract):
amount = 0
for line in current_payment.contentValues(): for line in current_payment.contentValues():
if line.getSource() in ["account_module/bank", "account_module/receivable"]: if line.getSource() in ["account_module/bank", "account_module/receivable"]:
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>amount, tag, target_language, REQUEST=None</string> </value> <value> <string>amount, tag, target_language, contract=None, REQUEST=None</string> </value>
</item> </item>
<item> <item>
<key> <string>_proxy_roles</string> </key> <key> <string>_proxy_roles</string> </key>
......
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
# It is mandatory use pass a contract to skip reservation
# as annonymous can request via website knowning the user's
# email
if contract is None:
return
if context.SubscriptionRequest_getTransactionalUser() is not None:
if contract is not None and contract.getMaximumInvoiceDelay() > 0:
return True
else:
person = context.getDestinationSectionValue()
if person.Entity_statSlapOSOutstandingAmount() > 0:
return
if contract is not None and contract.getMaximumInvoiceDelay() > 0:
return True
<?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>contract=None, REQUEST=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>SubscriptionRequest_testSkippedReservationFree</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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