Commit b24cd627 authored by Boxiang Sun's avatar Boxiang Sun

WIP: slapos_subscription_request: Check the currency to determine the payment method

parent 08948d2a
...@@ -19,6 +19,6 @@ user_input_dict = { ...@@ -19,6 +19,6 @@ user_input_dict = {
"amount" : amount} "amount" : amount}
return context.SubscriptionRequestModule_requestSubscriptionProxy( return context.SubscriptionRequestModule_requestSubscriptionProxy(
default_email_text, subscription_reference, payment_mode, default_email_text, subscription_reference,
confirmation_required=bool(confirmation_required), confirmation_required=bool(confirmation_required),
user_input_dict=user_input_dict, batch_mode=0) user_input_dict=user_input_dict, batch_mode=0)
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>name=None, default_email_text=None, payment_mode=None, subscription_reference=None, amount=0, confirmation_required=True, REQUEST=None, **kw</string> </value> <value> <string>name=None, default_email_text=None, subscription_reference=None, amount=0, confirmation_required=True, REQUEST=None, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -7,9 +7,8 @@ if REQUEST is not None: ...@@ -7,9 +7,8 @@ if REQUEST is not None:
person, person_is_new = context.SubscriptionRequest_createUser(email, user_input_dict['name']) person, person_is_new = context.SubscriptionRequest_createUser(email, user_input_dict['name'])
web_site = context.getWebSiteValue() web_site = context.getWebSiteValue()
# Check if user is already exist, otherwise redirect to ask confirmation
# if payment mode not selected, ask user to confirm and select one. if confirmation_required and not person_is_new:
if not payment_mode:
base_url = web_site.absolute_url() base_url = web_site.absolute_url()
return context.REQUEST.RESPONSE.redirect( return context.REQUEST.RESPONSE.redirect(
...@@ -28,17 +27,16 @@ subscription_request = context.subscription_request_module.newContent( ...@@ -28,17 +27,16 @@ subscription_request = context.subscription_request_module.newContent(
subscription_request.setDefaultEmailText(email) subscription_request.setDefaultEmailText(email)
def wrapWithShadow(subscription_request, amount, subscription_reference, payment_mode): def wrapWithShadow(subscription_request, amount, subscription_reference):
subscription_request.activate(tag="subscription_condition_%s" % subscription_request.getId() subscription_request.activate(tag="subscription_condition_%s" % subscription_request.getId()
).SubscriptionRequest_applyCondition(subscription_reference) ).SubscriptionRequest_applyCondition(subscription_reference)
return subscription_request.SubscriptionRequest_requestPaymentTransaction(amount=amount, return subscription_request.SubscriptionRequest_requestPaymentTransaction(amount=amount,
tag="subscription_%s" % subscription_request.getId(), payment_mode=payment_mode) tag="subscription_%s" % subscription_request.getId())
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, payment_mode]) argument_list=[subscription_request, user_input_dict["amount"], subscription_reference])
if batch_mode: if batch_mode:
return {'subscription' : subscription_request.getRelativeUrl(), 'payment': payment.getRelativeUrl() } return {'subscription' : subscription_request.getRelativeUrl(), 'payment': payment.getRelativeUrl() }
...@@ -51,18 +49,32 @@ price = person.Person_restrictMethodAsShadowUser( ...@@ -51,18 +49,32 @@ price = person.Person_restrictMethodAsShadowUser(
callable_object=wrapGetPriceWithShadow, callable_object=wrapGetPriceWithShadow,
argument_list=[payment,]) argument_list=[payment,])
if payment_mode == "wechat": # currency = subscription_request.getSpecialiseValue().getPriceCurrency()
# XXX: Test
# currency = "currency_module/EUR"
currency = "currency_module/CNY"
if currency == "currency_module/CNY": # Wechat payment
'''
portal = context.getPortalObject() portal = context.getPortalObject()
code_url = portal.Base_getWechatCodeURL(subscription_request.getId(), price, user_input_dict["amount"]) code_url = portal.Base_getWechatCodeURL(subscription_request.getId(), price, user_input_dict["amount"])
web_site = context.getWebSiteValue() web_site = context.getWebSiteValue()
base_url = web_site.absolute_url() base_url = web_site.absolute_url()
return context.REQUEST.RESPONSE.redirect( return context.REQUEST.RESPONSE.redirect(
"%s/#wechat_payment?amount=%s&trade_no=%s&code_url=%s" % (base_url, user_input_dict["amount"], subscription_request.getId(), code_url)) "%s/#wechat_payment?amount=%s&trade_no=%s&code_url=%s" % (base_url, user_input_dict["amount"], subscription_request.getId(), code_url))
'''
def wrapRedirectWithShadow(payment_transaction, web_site):
return payment_transaction.PaymentTransaction_redirectToWechatPayment(web_site)
def wrapRedirectWithShadow(payment_transaction, web_site): return person.Person_restrictMethodAsShadowUser(
return payment_transaction.PaymentTransaction_redirectToManualPayzenPayment(web_site) shadow_document=person,
callable_object=wrapRedirectWithShadow,
argument_list=[payment, web_site])
else: # "currency_module/EUR", Payzen payment
def wrapRedirectWithShadow(payment_transaction, web_site):
return payment_transaction.PaymentTransaction_redirectToManualPayzenPayment(web_site)
return person.Person_restrictMethodAsShadowUser( return person.Person_restrictMethodAsShadowUser(
shadow_document=person, shadow_document=person,
callable_object=wrapRedirectWithShadow, callable_object=wrapRedirectWithShadow,
argument_list=[payment, web_site]) argument_list=[payment, web_site])
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>email, subscription_reference, payment_mode=None, confirmation_required=False, user_input_dict={}, batch_mode=True, REQUEST=None</string> </value> <value> <string>email, subscription_reference, confirmation_required=False, user_input_dict={}, batch_mode=True, REQUEST=None</string> </value>
</item> </item>
<item> <item>
<key> <string>_proxy_roles</string> </key> <key> <string>_proxy_roles</string> </key>
......
...@@ -11,7 +11,7 @@ if subscription_condition_reference is not None: ...@@ -11,7 +11,7 @@ if subscription_condition_reference is not None:
subscription_condition = context.portal_catalog.getResultValue( subscription_condition = context.portal_catalog.getResultValue(
portal_type="Subscription Condition", portal_type="Subscription Condition",
reference=subscription_condition_reference, reference=subscription_condition_reference,
validation_state="validated") validation_state="published") # XXX Wechat workaround, validated?
else: else:
subscription_condition = context.getSpecialiseValue() subscription_condition = context.getSpecialiseValue()
...@@ -36,7 +36,7 @@ context.edit( ...@@ -36,7 +36,7 @@ context.edit(
root_slave=subscription_condition.getRootSlave(), root_slave=subscription_condition.getRootSlave(),
specialise_value=subscription_condition, specialise_value=subscription_condition,
price=subscription_condition.getPrice(), price=subscription_condition.getPrice(),
price_currency=subscription_condition.getPriceCurrency() price_currency="currency_module/CNY", # For test!!! subscription_condition.getPriceCurrency()
) )
context.setSourceReference(subscription_condition.getSourceReference()) context.setSourceReference(subscription_condition.getSourceReference())
...@@ -7,7 +7,10 @@ portal = context.getPortalObject() ...@@ -7,7 +7,10 @@ portal = context.getPortalObject()
current_invoice = context.getCausalityValue() current_invoice = context.getCausalityValue()
if current_invoice is None: if current_invoice is None:
if payment_mode == "wechat": # currency = context.getSpecialiseValue().getPriceCurrency()
# currency = "currency_module/EUR"
currency = "currency_module/CNY"
if currency == "currency_module/CNY": # Wechat payment
invoice_template_path = "accounting_module/template_wechat_pre_payment_subscription_sale_invoice_transaction" invoice_template_path = "accounting_module/template_wechat_pre_payment_subscription_sale_invoice_transaction"
else: else:
invoice_template_path = "accounting_module/template_pre_payment_subscription_sale_invoice_transaction" invoice_template_path = "accounting_module/template_pre_payment_subscription_sale_invoice_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>amount, tag, payment, payment_mode=None, REQUEST=None</string> </value> <value> <string>amount, tag, payment, REQUEST=None</string> </value>
</item> </item>
<item> <item>
<key> <string>_proxy_roles</string> </key> <key> <string>_proxy_roles</string> </key>
......
...@@ -9,7 +9,10 @@ current_payment = None ...@@ -9,7 +9,10 @@ current_payment = None
if current_invoice is None: if current_invoice is None:
# Hardcoded value for reservation # Hardcoded value for reservation
if payment_mode == "wechat": # currency = context.getSpecialiseValue().getPriceCurrency()
# XXX: Test for now
currency = "currency_module/CNY"
if currency == "currency_module/CNY": # Wechat payment
payment_template = portal.restrictedTraverse("accounting_module/slapos_wechat_pre_payment_template") payment_template = portal.restrictedTraverse("accounting_module/slapos_wechat_pre_payment_template")
quantity = int(amount) * 188 quantity = int(amount) * 188
else: else:
...@@ -43,6 +46,6 @@ if current_invoice is None: ...@@ -43,6 +46,6 @@ if current_invoice is None:
context.reindexObject(activate_kw={'tag': tag}) context.reindexObject(activate_kw={'tag': tag})
context.activate(tag=tag).SubscriptionRequest_createRelatedSaleInvoiceTransaction( context.activate(tag=tag).SubscriptionRequest_createRelatedSaleInvoiceTransaction(
amount, tag, current_payment.getRelativeUrl(), payment_mode) amount, tag, current_payment.getRelativeUrl())
return current_payment return current_payment
...@@ -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, payment_mode=None, REQUEST=None</string> </value> <value> <string>amount, tag, REQUEST=None</string> </value>
</item> </item>
<item> <item>
<key> <string>_proxy_roles</string> </key> <key> <string>_proxy_roles</string> </key>
......
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