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