Commit 8774aa7a authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_wechat&payzen: Be fault tolerant if wechat secure payment

   Return None rather them raise, to allow the site to show an alternative page or inform that payments are disabled.
parent 606415d7
......@@ -3,7 +3,16 @@ if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
payment_service = portal.portal_secure_payments.find(
service_reference=portal.portal_preferences.getPreferredPayzenPaymentServiceReference())
service_reference = portal.portal_preferences.getPreferredPayzenPaymentServiceReference()
if not service_reference:
return
try:
payment_service = portal.portal_secure_payments.find(service_reference=service_reference)
except ValueError:
# If service is not found, return None
# this might allow the side handle disabled service configuration.
return
return payment_service.getRelativeUrl()
......@@ -170,6 +170,8 @@ class TestSlapOSPaymentTransaction_createPayzenEvent(SlapOSTestCaseMixinWithAbor
REQUEST={})
def test_createPayzenEvent_newPayment(self):
self.portal.portal_secure_payments.slapos_payzen_test.setReference("PSERV-Payzen-Test")
self.tic()
payment_transaction = self.createPaymentTransaction()
payzen_event = payment_transaction.PaymentTransaction_createPayzenEvent()
self.assertEqual(payzen_event.getPortalType(), "Payzen Event")
......@@ -178,6 +180,8 @@ class TestSlapOSPaymentTransaction_createPayzenEvent(SlapOSTestCaseMixinWithAbor
self.assertEqual(payzen_event.getDestination(), payment_transaction.getRelativeUrl())
def test_createPayzenEvent_kwParameter(self):
self.portal.portal_secure_payments.slapos_payzen_test.setReference("PSERV-Payzen-Test")
self.tic()
payment_transaction = self.createPaymentTransaction()
payzen_event = payment_transaction.PaymentTransaction_createPayzenEvent(
title='foo')
......@@ -666,9 +670,18 @@ class TestSlapOSPayzenBase_getPayzenServiceRelativeUrl(SlapOSTestCaseMixinWithAb
REQUEST={})
def test_getPayzenServiceRelativeUrl_default_result(self):
self.portal.portal_secure_payments.slapos_payzen_test.setReference("PSERV-Payzen-Test")
self.tic()
result = self.portal.Base_getPayzenServiceRelativeUrl()
self.assertEqual(result, 'portal_secure_payments/slapos_payzen_test')
def test_getPayzenServiceRelativeUrl_not_found(self):
self.portal.portal_secure_payments.slapos_payzen_test.setReference("disabled")
self.tic()
result = self.portal.Base_getPayzenServiceRelativeUrl()
self.assertEqual(result, None)
class TestSlapOSPayzenPaymentTransaction_redirectToManualPayzenPayment(
SlapOSTestCaseMixinWithAbort):
......@@ -712,6 +725,8 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans
self._dropPaymentTransaction_getVADSUrlDict()
def test_PaymentTransaction_redirectToManualPayzenPayment_redirect(self):
self.portal.portal_secure_payments.slapos_payzen_test.setReference("PSERV-Payzen-Test")
self.tic()
person = self.makePerson()
invoice = self.createStoppedSaleInvoiceTransaction(
destination_section=person.getRelativeUrl())
......
......@@ -3,7 +3,17 @@ if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
payment_service = portal.portal_secure_payments.find(
service_reference=portal.portal_preferences.getPreferredWechatPaymentServiceReference())
service_reference = portal.portal_preferences.getPreferredWechatPaymentServiceReference()
if not service_reference:
return
try:
payment_service = portal.portal_secure_payments.find(
service_reference=service_reference)
except ValueError:
# If service is not found, return None
# this might allow the side handle disabled service configuration.
return
return payment_service.getRelativeUrl()
......@@ -169,6 +169,7 @@ class TestSlapOSPaymentTransaction_createWechatEvent(SlapOSTestCaseMixinWithAbor
REQUEST={})
def test_createWechatEvent_newPayment(self):
self.portal.portal_secure_payments.slapos_wechat_test.setReference("PSERV-Wechat-Test")
payment_transaction = self.createPaymentTransaction()
wechat_event = payment_transaction.PaymentTransaction_createWechatEvent()
self.assertEqual(wechat_event.getPortalType(), "Wechat Event")
......@@ -177,6 +178,8 @@ class TestSlapOSPaymentTransaction_createWechatEvent(SlapOSTestCaseMixinWithAbor
self.assertEqual(wechat_event.getDestination(), payment_transaction.getRelativeUrl())
def test_createWechatEvent_kwParameter(self):
self.portal.portal_secure_payments.slapos_wechat_test.setReference("PSERV-Wechat-Test")
self.tic()
payment_transaction = self.createPaymentTransaction()
wechat_event = payment_transaction.PaymentTransaction_createWechatEvent(
title='foo')
......@@ -523,7 +526,6 @@ return addToDate(DateTime(), to_add={'day': -1, 'second': -1}).toZone('UTC'), 'f
payment.workflow_history['accounting_workflow'][-1]['comment'])
class TestSlapOSWechatBase_getWechatServiceRelativeUrl(SlapOSTestCaseMixinWithAbort):
def test_getWechatServiceRelativeUrl_REQUEST_disallowed(self):
self.assertRaises(
Unauthorized,
......@@ -531,9 +533,18 @@ class TestSlapOSWechatBase_getWechatServiceRelativeUrl(SlapOSTestCaseMixinWithAb
REQUEST={})
def test_getWechatServiceRelativeUrl_default_result(self):
self.portal.portal_secure_payments.slapos_wechat_test.setReference("PSERV-Wechat-Test")
self.tic()
result = self.portal.Base_getWechatServiceRelativeUrl()
self.assertEqual(result, 'portal_secure_payments/slapos_wechat_test')
def test_getWechatServiceRelativeUrl_not_found(self):
self.portal.portal_secure_payments.slapos_wechat_test.setReference("disabled")
self.tic()
result = self.portal.Base_getWechatServiceRelativeUrl()
self.assertEqual(result, None)
class TestSlapOSWechatPaymentTransaction_redirectToManualWechatPayment(
SlapOSTestCaseMixinWithAbort):
......@@ -577,6 +588,7 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans
self._dropPaymentTransaction_getVADSUrlDict()
def test_PaymentTransaction_redirectToManualWechatPayment_redirect(self):
self.portal.portal_secure_payments.slapos_wechat_test.setReference("PSERV-Wechat-Test")
person = self.makePerson()
invoice = self.createStoppedSaleInvoiceTransaction(
payment_mode="wechat",
......@@ -621,6 +633,7 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans
transaction.abort()
def test_PaymentTransaction_redirectToManualWechatPayment_redirect_with_website(self):
self.portal.portal_secure_payments.slapos_wechat_test.setReference("PSERV-Wechat-Test")
person = self.makePerson()
invoice = self.createStoppedSaleInvoiceTransaction(
payment_mode="wechat",
......
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