Commit 36591420 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_payzen: Include script to redirect to Manual Payment from a Website.

parent a6bae06d
from zExceptions import Unauthorized
portal = context.getPortalObject()
person = portal.ERP5Site_getAuthenticatedMemberPersonValue()
if getattr(context, "PaymentTransaction_getVADSUrlDict", None) is None:
raise ValueError("PaymentTransaction_getVADSUrlDict is missing on this site")
if person is None:
raise Unauthorized("Error")
def wrapWithShadow(payment_transaction, person_relative_url):
vads_url_dict = payment_transaction.PaymentTransaction_getVADSUrlDict()
_ , transaction_id = payment_transaction.PaymentTransaction_getPayzenId()
vads_url_already_registered = vads_url_dict.pop('vads_url_already_registered')
if transaction_id is not None:
return context.REQUEST.RESPONSE.redirect(vads_url_already_registered)
system_event = payment_transaction.PaymentTransaction_createPayzenEvent(
title='User navigation script for %s' % payment_transaction.getTitle(),
destination_section=person_relative_url,
)
system_event.generateManualPaymentPage(
**vads_url_dict
)
return system_event.contentValues(
portal_type="Payzen Event Message")[0].getTextContent()
return person.Person_restrictMethodAsShadowUser(
shadow_document=person,
callable_object=wrapWithShadow,
argument_list=[context, person.getRelativeUrl()])
<?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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>PaymentTransaction_redirectToManualPayzenPayment</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -620,6 +620,98 @@ class TestSlapOSPayzenAccountingTransaction_getPaymentState( ...@@ -620,6 +620,98 @@ class TestSlapOSPayzenAccountingTransaction_getPaymentState(
line.setGroupingReference("TEST%s" % self.new_id) line.setGroupingReference("TEST%s" % self.new_id)
self.assertEquals("Paid", invoice.AccountingTransaction_getPaymentState()) self.assertEquals("Paid", invoice.AccountingTransaction_getPaymentState())
class TestSlapOSPayzenPaymentTransaction_redirectToManualPayzenPayment(
SlapOSTestCaseMixinWithAbort):
def test_PaymentTransaction_redirectToManualPayzenPayment(self):
payment = self.createPaymentTransaction()
self.assertRaises(ValueError, payment.PaymentTransaction_redirectToManualPayzenPayment)
def _simulatePaymentTransaction_getVADSUrlDict(self):
script_name = 'PaymentTransaction_getVADSUrlDict'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""payment_transaction_url = context.getRelativeUrl()
return dict(vads_url_already_registered="%s/already_registered" % (payment_transaction_url),
vads_url_cancel="%s/cancel" % (payment_transaction_url),
vads_url_error="%s/error" % (payment_transaction_url),
vads_url_referral="%s/referral" % (payment_transaction_url),
vads_url_refused="%s/refused" % (payment_transaction_url),
vads_url_success="%s/success" % (payment_transaction_url),
vads_url_return="%s/return" % (payment_transaction_url),
)""")
def _dropPaymentTransaction_getVADSUrlDict(self):
script_name = 'PaymentTransaction_getVADSUrlDict'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
def test_PaymentTransaction_redirectToManualPayzenPayment_unauthorzied(self):
payment = self.createPaymentTransaction()
self._simulatePaymentTransaction_getVADSUrlDict()
try:
self.assertRaises(Unauthorized, payment.PaymentTransaction_redirectToManualPayzenPayment)
finally:
self._dropPaymentTransaction_getVADSUrlDict()
def test_PaymentTransaction_redirectToManualPayzenPayment_redirect(self):
person = self.makePerson()
invoice = self.createPayzenSaleInvoiceTransaction(
destination_section=person.getRelativeUrl())
self.tic()
payment = invoice.SaleInvoiceTransaction_getPayzenPaymentRelatedValue()
payment.setResourceValue(self.portal.currency_module.EUR)
self.tic()
self.login(person.getUserId())
self._simulatePaymentTransaction_getVADSUrlDict()
try:
text_content = payment.PaymentTransaction_redirectToManualPayzenPayment()
finally:
self._dropPaymentTransaction_getVADSUrlDict()
payment_transaction_url = payment.getRelativeUrl()
for item in ["vads_site_id",
payment_transaction_url,
"vads_url_cancel",
"%s/cancel" % (payment_transaction_url),
"vads_url_error",
"%s/error" % (payment_transaction_url),
"vads_url_referral",
"%s/referral" % (payment_transaction_url),
"vads_url_refused",
"%s/refused" % (payment_transaction_url),
"vads_url_success",
"%s/success" % (payment_transaction_url),
"vads_url_return",
"%s/return" % (payment_transaction_url)]:
self.assertTrue(item in text_content,
"%s not in %s" % (item, text_content))
def test_PaymentTransaction_redirectToManualPayzenPayment_already_registered(self):
person = self.makePerson()
invoice = self.createPayzenSaleInvoiceTransaction(
destination_section=person.getRelativeUrl())
self.tic()
payment = invoice.SaleInvoiceTransaction_getPayzenPaymentRelatedValue()
payment.setResourceValue(self.portal.currency_module.EUR)
payment.PaymentTransaction_generatePayzenId()
self.tic()
self.login(person.getUserId())
self._simulatePaymentTransaction_getVADSUrlDict()
try:
redirect = payment.PaymentTransaction_redirectToManualPayzenPayment()
finally:
self._dropPaymentTransaction_getVADSUrlDict()
self.assertEquals("%s/already_registered" % payment.getRelativeUrl(),
redirect)
class TestSlapOSPayzenSaleInvoiceTransaction_getPayzenPaymentRelatedValue( class TestSlapOSPayzenSaleInvoiceTransaction_getPayzenPaymentRelatedValue(
SlapOSTestCaseMixinWithAbort): SlapOSTestCaseMixinWithAbort):
......
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